Monday, November 17, 2014

IP Nedir? Port Nedir? DNS Nedir? MAC Adresi Nedir?

Aklıma gelen bir analojiyle anlatayım.

MAC Adresi, arsanızın parsel numarasıdır. Sabittir. Değişmez (parsel bölme ve birleştirme gibi işlemleri saymazsak).

IP Adresi, arsanızda yer alan binanın adresidir. Zaman zaman değişebildiği görülmüştür.

IP Adresi 4 parçadan oluşur: 212.168.31.14 gibi. Kazım Mahallesi . Metin Caddesi . Dirayet Sokak . Güler Apartmanı demek gibi bir şey. Dirayet sokakta yer alan apartmanların IP adresleri 212.168.31 ile başlayacak hep.

DNS Sunucusu, kimin nerede oturduğunu bilen muhtardır. Ona Mehmet Gözüpek nerede? diye sorduğunuzda duyduğu ismin hangi adreste (IP Adresi) oturduğunu size söyler. Siz de o adrese gidersiniz.

Port, daire numarasıdır. Apartmanın içindeki hangi daireye girmeniz gerektiğini söyler.

Toparlayacak olursak, www.hede.com sitesine girmek istediğinizde DNS sunucusuna sorarsınız, adresi nedir diye. O da size 212.168.31.14 cevabını verir. Siz o adrese gidersiniz ve verilen port numarasından (web sitesiyse öntanımlı 80'dir) kapıyı çalar ve bilgi istediğinizi söylersiniz. O da size gerekli bilgileri verir.

MAC adresi bu aşamada sizi pek ilgilendirmez, onu internet hizmetini veren firma bilir sadece. Dışarıya kapalıdır.

Saturday, November 8, 2014

Sinüzite ne iyi gelir?

Uyarı: bu yazı bir doktor olmayan birisi tarafından yazılmıştır ve hiçbir tıbbi geçerliliği yoktur, sadece kişisel tecrübelerden ve araştırmalardan yola çıkılarak hazırlanmıştır. Uygulamanın sonuçlarından sorumluluk kabul edilmez. Doktorunuza danışmayı ihmal etmeyin.

Başınızı üşüttünüz ve sinüzit oldunuz, tebrikler. Sinüzit, sinüslerin mukus tabakasıyla dolması sonucu oluşan bir rahatsızlık. Bakteriyel bir doğası var.

Peki nasıl kurtulacağız bu Sinüzitten?


Tedavi olmadan kurtulmanın pek bir yolu yok gibi. Doktora gittiğinizde muhtemelen size sinüzitin şiddetine göre bir antibiyotik verecek. Bu sinüslerdeki bakterileri öldürecek ve sinüzitiniz zamanla çözülecek. Kimisi iyileşemeyecek kadar ağır sinüzit olup ameliyat olmak zorunda kalabiliyor.

Peki çok şiddetli değilse ya da genel spektrumlu antibiyotikten kaçınıyorsanız ne olacak? Sarımsak (ince ince doğrayıp çiğneyerek) ve Soğan yemek antibiyotik görevi görebiliyor. Ancak ilaç olan antibiyotiğin yerini alır mı, aynı etkiyi elde etmek için kaç diş yemeniz gerekir orası meçhul. Denen o ki günde 1-3 diş sarımsak kararında bir seçim.

Mukus Tahliyesi

Sinüslerdeki tıkanıklığı mukus tahliyesiyle gidermek gerekli. Burnunuzun açık olması bu açıdan çok önemli. Mukus tabakası kalınlaştıkça tahliyesi zorlaşıyor. Eğer burun da tıkalıysa bu da geniz akıntısına ve akıntı soluk borusuna kaçarsa öksürüğe sebep olabiliyor. Bu öksürüğü bronşitle karıştırmamak lazım. Akıntı ciğere doğru giderken soluk borunuzu gıdıkladığı için öksürüyorsunuz. Bu sayede ciğerleriniz korunmuş oluyor. Öksürük bir savunma mekanizması. Öksürük giderici ilaçlar da kullanmayın ki bu refleksinizi kaybetmeyin, ciğerleriniz dolmasın.

Eğer burnunuz tıkanıyorsa ve alerjik olduğunu biliyorsanız alerji hap/spreyleri burun etlerinizi indirmeye yarayabilir. Bu sayede tahliye kolaylaşır.

Eğer aynı anda grip tabanlı bir tıkanıklık varsa Pseudoefedrin'li bir ilaç da rahatlama sağlayacaktır.

Ancak bunlar doğrudan iyileştirme değil, dolaylı yoldan (tahliyeyi kolaylaştırarak) rahatlama sağlar.

Bu arada geniz akıntısını durdurucu ilaç kullanmamaya gayret edin ki tahliye durmasın, onun yerine mukusu inceltmek ve tahliyesine mümkünse burundan, değilse genizden imkan vermek en güzeli gibi.

Tedaviye ek olarak neler yapabiliriz?


Öncelikle daha fazla üşütmeyeceksiniz. Bol bol su içeceksiniz ki mukus incelsin.

Tuzlu suyu burnuza iyice çekip derinlere temas ettirebilirsiniz. Bu mukus tabakasını inceltecek ve akmasını sağlayacaktır. Böylelikle sinüslerde bir miktar temizlik sağlanmış olur. Dilerseniz kolaylık olması açısından Sinus Rinse gibi kitler de alabilirsiniz. Ayrıca yazın bol tuzlu bir denizde (Ege yetmez, Akdeniz) amuda kalkmak güzel bir temizlik sağlıyor.

Kaynar durumda 1 lt suya 2 kaşık papatya atıp 5 dk buğu yapmak da rahatlama getirecektir. 5 dk yap, 30 dk ara, 5 dk yap, 30 dk ara şeklinde yapılabilir. Max 3 defa.

Eğer evde buhar makinası varsa çalıştırabilirsiniz. Buhar iyi gelecektir. Yoksa bol sıcak buharlı bir duş almak da çok faydalı.

Çörekotu yağını her deliğe 1-2 damla damlatmak da mukus tabakasını eritme konusunda etkili. 2 damlayı geçmemenizi tavsiye ediyorlar, yakabilir.

Tavuksuyu çorba, sıcak çaylar vb mukus inceltici gıdalar tüketmenizde fayda var. Mukus yapıcı gıdalardan (süt ürünleri, karbonhidratlar) da uzak durmak gerek.

Bu söylediklerimi mümkün olduğunca erken saatlerde yapmanızda fayda var. Böylelikle tahliye işlemi siz yatıyorken değil ayaktayken gerçekleşir ve daha az öksürüğe sebep olur. Tahliye hızlanır.

Tuesday, May 13, 2014

MySQL Crashes on 512MB VPS

My VPS hosting Apache2+MySQL+Wordpress has problems with MySQL frequently. MySQL crashes and does not restart, leading to an inaccessible web site. What I initially found was the changing the Then I figured out that Apache was using 8 processes, consuming all the memory, leaving no memory for MySQL. So In apache2.conf, I changed StartServers from 5 to 2 and MaxClients from 150 to 5 to reduce the memory consumption. StartServers 2 MinSpareServers 5 MaxSpareServers 10 MaxClients 5 MaxRequestsPerChild 0

Monday, May 12, 2014

Samsung ML-2955ND on Ubuntu/Mint Linux

Default drivers does not seem to work. But when you choose 2850-pxlmono driver, it works! Both in local and in network mode. See: http://askubuntu.com/questions/228760/ubuntu-12-04-samsung-ml-2955dw-not-print

Saturday, March 22, 2014

AngularJS and Starrr plugin: updating score variable with directives

I'm using Starrr plugin (https://github.com/dobtco/starrr) with Angular.JS.

When the star rating changes, 'starrr:change' dom event is fired. I have to catch this event and update the score variable in my angular.js scope.  It was hard to find it but found it:
We define a directive in our angular app js file:
myApp.directive('rateable', function(){
        return function(scope, elt, attr){
            elt.bind('starrr:change', function(e, value){
                scope.score = value;
                scope.$apply();
            });
        }
});
In the HTML Code, we use the rateable directive as HTML tag attribute:
<div class="starrr" data-rating="1" id="hearts" rateable></div>
This way, whenever "starrr:change" event is fired from "#hearts", our score variable in the scope is updated. We have to call $apply to let Angular know some changes has been proposed.

Wednesday, March 12, 2014

Error: Failed to find request token in session at Strategy.OAuthStrategy.authenticate [passport-twitter on cluster]


I got the error in the title when I tried to deploy my code on Heroku or Dokku. Possible suspects were:

1) Twitter API KEY and SECRET
2) System Time

And they were correct. Then I found that if we run the module as cluster:

Authentication request was sent by passport-twitter to twitter and some data regarding this request kept in session object. Then the response came from twitter in form of (callback?oauth_token=...&oauth_verifier=...) but could not find session object since it was in another process. By the way, heroku can run 2 processes per web dyno.

So solution was :

not using cluster code and running the http server on a single process. 

Another solution: Use Redis for session storing:

RedisStore = require('connect-redis')(express.session);
var REDIS_URL = process.env.REDISCLOUD_URL || "redis://localhost";
app.use(express.session({ store: new RedisStore({'url': REDIS_URL}), secret: '2342342' })); // session secret

Monday, March 10, 2014

Upstart can't read environment variables

I was trying to configure a gunicorn server with upstart for easily starting/stopping my service. But it turned out to be problematic since upstart does not read environment variables.

How did I encounter this error? I was trying to parse signed_request from Facebook canvas via the following line:

fb_request = facebook.parse_signed_request(signed_request, APP_SECRET)

where

APP_SECRET = os.environ.get('FB_APP_SECRET', 'jhdklu3sh4o8y4o8fh34')

I realized that it couldn't read the environment variable and was using the default app secret so couldn't decrypt the signed request. My environment variables were in .bashrc of both regular user and root but it did not read. So I added them to the upstart script:

script
     export HOME=/home/user/project
     cd $HOME
     export FB_APP_ID=859827u4fhk4vnf
     export FB_APP_SECRET=4ojfo92ufo2489fyuo482fy2
     . venv/bin/activate
     exec gunicorn myapp:app
end script


Wednesday, March 5, 2014

Installing Neo4J on Ubuntu

A simple dockerfile for this purpose. Not sure for the last lines. Fix me if I'm wrong.


FROM dockerfile/ubuntu

# Install Java
RUN apt-get install -y software-properties-common
RUN add-apt-repository -y ppa:webupd8team/java
RUN apt-get update
RUN echo debconf shared/accepted-oracle-license-v1-1 select true | debconf-set-selections
RUN echo debconf shared/accepted-oracle-license-v1-1 seen true | debconf-set-selections
RUN apt-get install -y oracle-java7-installer



RUN wget "http://download.neo4j.org/artifact?edition=community&version=1.9.6&distribution=tarball&dlid=notread"
RUN mv artifact\?edition\=community\&version\=1.9.6\&distribution\=tarball\&dlid\=notread neo.tar.gz
RUN tar xvfz neo.tar.gz


RUN mv neo4j-community-1.9.6 /opt/neo4j-community-1.9.6
RUN /opt/neo4j-community-1.9.6/bin/neo4j install



CMD service neo4j-service start



Tuesday, March 4, 2014

POST to Angular.JS by Facebook Canvas App

I was writing a Facebook Canvas App with Flask. Then I decided to move my frontend to AngularJS. I wanted to put the AngularJS static code to a static hosting provider to avoid higher costs. Nevertheless, I realized that I had forgotten that I can't handle POST requests by AngularJS since it doesn't have a dynamic server.

Facebook Canvas performs a POST request with signed_request parameter to your homepage and you should handle that parameter to see who the logged user is.

What I did was: create a Node.JS app with express.js framework. Convert homepage to view, add a hidden input field in the HTML code and handle POST parameter by Node.JS, filling that hidden input.

When I did this, facebook posted the signed_request parameter and I placed that code into the hidden field. Now AngularJS code can post that signed_request code to the backend API server to process it or use it client-side.

Friday, February 28, 2014

Linkedin's "People you may know" feature

In the last few months, I realized some people whom I really don't know are adding me as contacts in Linkedin. What I realized was that :

0) they had nothing to do with my industry, we had nothing in common.
1) most of these people had just joined Linkedin and had 0 contacts. 
2) either their name or surname started with "a", which is my first name's and
lastname's initial.

I guess Linkedin devised a "dummy" algorithm for the newcomers. They redirect them to random people with the same initials to integrate them to the system (make their graph more connected). Weird.

Friday, February 21, 2014

Embedding Skulpt Python Interpreter in Reveal.js slides

Lately, Slide libraries in HTML+JS+CSS became so popular. I liked reveal.js the most and wanted to prepare a presentation on Python. I wanted to perform demos throughout the presentation so I thought I could embed a Python interpreter (skulpt) on slides.

See sample HTML file: https://gist.github.com/aladagemre/9124007

Just place your html file inside reveal.js folder. Place skulpt js files in reveal.js/js folder.

There exists two slides with the interpreter embedded. Just copy and paste those sections for having more.


Saturday, February 1, 2014

Flask, Facebook Canvas App, localhost and SSL


If you're developing a facebook canvas app with Flask, then you're asked to provide URLs for your app. Initially I used myapp.herokuapp.com address for http and https. But I realized that for testing local changes, I'd like to use localhost.

When I give localhost, it says it's not SSL supported. Then I had to create SSL certificates and install pyopenssl to use them. See: http://kracekumar.com/post/54437887454/ssl-for-flask-local-development

But what I saw was that connection was untrusted and I could not Add an Exception. I learned that browsers do not trust localhost for SSL. So I had to create an alias for my herokuapp. Added the following line to /etc/hosts

127.0.0.1 myapp.herokuapp.com

And set the canvas url as myapp.herokuapp.com for http and https.

Now when the app starts, tries to load https://myapp.herokuapp.com. It loads https://127.0.0.1:443 which is listened by the Flask app:

if __name__ == "__main__":
    port = int(os.environ.get("PORT", 443))
    app.run('0.0.0.0', debug=True, port=port, ssl_context=('/home/user/projects/myapp/server.crt', '/home/user/projects/myapp/server.key'))

This way I could overcome the SSL localhost problem for facebook canvas apps.

UPDATE: If you don't want to run the app as root,  just forward port 443 to 3000 and listen 3000 port with the following command as root:

iptables -t nat -A OUTPUT -p tcp --dport 443 -j REDIRECT --to-port 3000

and to cancel it:

iptables -t nat -D OUTPUT -p tcp --dport 443 -j REDIRECT --to-port 3000

Note that forwarding 443, you won't be able to connect SSL web sites throughout your pc.

Maybe using vagrant could be more elegant.

Tuesday, January 7, 2014

Freemind Latex Plugin Installation

If you want to display latex formulas on your Freemind mindmap, here are the instructions:

  1. Find your freemind dir (/usr/share/freemind)
  2. sudo mkdir /usr/share/freemind/plugins/latexmath
  3. Checkout/Download https://github.com/Alxa/LaTeXMath-Freemind-Plugin/
  4. Read: https://github.com/Alxa/LaTeXMath-Freemind-Plugin/blob/master/INSTALL
  5. sudo cp fm-plugin-latexmath/src/main/resources/LaTeXMath.xml /usr/share/freemind/plugins/
  6. sudo apt-get install maven2; cd fm-plugin-latexmath; mvn package
  7. See and copy jar file in target folder. sudo cp fm-plugin-latexmath-* /usr/share/freemind/plugins/latexmath/
  8. sudo cp ~/.m2/repository/net/sf/alxa/jlatexmath/0.9.3-SNAPSHOT/*jar /usr/share/freemind/plugins/latexmath/jlatexmath.jar

Start freemind and you'll see Insert->Latex Equation option.


Note that this does not insert the equation into the branch, but inserts below it and it's a little large.Sample below: