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.
Friday, February 21, 2014
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:
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:
- Find your freemind dir (/usr/share/freemind)
- sudo mkdir /usr/share/freemind/plugins/latexmath
- Checkout/Download https://github.com/Alxa/LaTeXMath-Freemind-Plugin/
- Read: https://github.com/Alxa/LaTeXMath-Freemind-Plugin/blob/master/INSTALL
- sudo cp fm-plugin-latexmath/src/main/resources/LaTeXMath.xml /usr/share/freemind/plugins/
- sudo apt-get install maven2; cd fm-plugin-latexmath; mvn package
- See and copy jar file in target folder. sudo cp fm-plugin-latexmath-* /usr/share/freemind/plugins/latexmath/
- 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:
Tuesday, December 17, 2013
Can't update wordpress on Ubuntu
I had a wordpress installation on an Ubuntu 13 machine but was unable to update the wordpress. I thought it was due to rwx permission problems but it turned out it was not.
The wordpress folder should be of group "www-data" if you're using apache. Apache by-default runs with www-data group and user. So if your wordpress folder does not belong to this group, apache can not copy the newer version in this folder so it says "I could not update."
I found the solution by following the inverse of the instructions here ( stylishjm at the bottom ).
She said we could change the user and group of apache to our own username but that cause some other problems since it caused:
So instead of changing apache's username, I changed the group of wordpress folder:
Hope that helps.
The wordpress folder should be of group "www-data" if you're using apache. Apache by-default runs with www-data group and user. So if your wordpress folder does not belong to this group, apache can not copy the newer version in this folder so it says "I could not update."
I found the solution by following the inverse of the instructions here ( stylishjm at the bottom ).
She said we could change the user and group of apache to our own username but that cause some other problems since it caused:
... waiting /var/lock/apache2 already exists but is not a directory owned by "username"
So instead of changing apache's username, I changed the group of wordpress folder:
chgrp -R www-data wordpress
Hope that helps.
Sunday, December 8, 2013
Django Redis backend for sessions on Heroku
Session queries take significant time at each view request. To bypass PostgreSQL and obtain the session information, you can use Redis.
On Heroku, add RedisCloud addon to your app. Then install django-redis-sessions and add the following lines to your production settings file.
On Heroku, add RedisCloud addon to your app. Then install django-redis-sessions and add the following lines to your production settings file.
########## REDIS SESSION ###########
from os import environ
redis_url = environ.get("REDISCLOUD_URL")
credential_part, host_part = redis_url.split("//")[1].split("@")
rediscloud, rpassword = credential_part.split(":")
rhost, rport = host_part.split(":")
SESSION_REDIS_PASSWORD = rpassword
SESSION_REDIS_HOST = rhost
SESSION_REDIS_PORT = int(rport)
SESSION_ENGINE = 'redis_sessions.session'
SESSION_REDIS_DB = 0
SESSION_REDIS_PREFIX = 'session'
######## END REDIS SESSION #########
Thursday, October 10, 2013
Using PositiveSSL with nginx
Make sure you have nginx with SSL support:
sudo apt-get install nginx-full
Create a key:
sudo mkdir -p /etc/nginx/ssl
cd /etc/nginx/ssl
sudo openssl genrsa -des3 -out domain.key 2048
sudo openssl req -new -key domain.key -out domain.csr
Create certificate: a combined pem file
Put the zip file Namecheap has sent you via email on server, extract them.
cat www_mydomain_com.crt >> www_mydomain_com.pem
cat PositiveSSLCA2.crt >> www_mydomain_com.pem
cat AddTrustExternalCARoot.crt >> www_mydomain_com.pem
service nginx restart
Edit /etc/nginx/sites-available/default:
# Default server for non-domain requests
server {
return 404;
}
upstream django {
server localhost:8000 fail_timeout=10;
}
server {
listen 80;
server_name www.mydomain.com mydomain.com uk.mydomain.com;
return 301 https://$host$request_uri;
}
server {
listen 443;
server_name www.mydomain.com mydomain.com uk.mydomain.com;
root /home/user/projects/myproject;
ssl on;
ssl_certificate /etc/nginx/ssl/www_mydomain_com.pem;
ssl_certificate_key /etc/nginx/ssl/domain.key;
...
}
The first server lets wrong domain requests to get 404, not 500.
The second is the django server
The third is the HTTP to HTTPS redirection
The fourth is the ssl settings for the main project.
sudo apt-get install nginx-full
Create a key:
sudo mkdir -p /etc/nginx/ssl
cd /etc/nginx/ssl
sudo openssl genrsa -des3 -out domain.key 2048
sudo openssl req -new -key domain.key -out domain.csr
Create certificate: a combined pem file
Put the zip file Namecheap has sent you via email on server, extract them.
cat www_mydomain_com.crt >> www_mydomain_com.pem
cat PositiveSSLCA2.crt >> www_mydomain_com.pem
cat AddTrustExternalCARoot.crt >> www_mydomain_com.pem
service nginx restart
Edit /etc/nginx/sites-available/default:
# Default server for non-domain requests
server {
return 404;
}
upstream django {
server localhost:8000 fail_timeout=10;
}
server {
listen 80;
server_name www.mydomain.com mydomain.com uk.mydomain.com;
return 301 https://$host$request_uri;
}
server {
listen 443;
server_name www.mydomain.com mydomain.com uk.mydomain.com;
root /home/user/projects/myproject;
ssl on;
ssl_certificate /etc/nginx/ssl/www_mydomain_com.pem;
ssl_certificate_key /etc/nginx/ssl/domain.key;
...
}
The first server lets wrong domain requests to get 404, not 500.
The second is the django server
The third is the HTTP to HTTPS redirection
The fourth is the ssl settings for the main project.
Saturday, October 5, 2013
File transfer from Android to Linux
It's problematic to perform file transfers from Android via MTP protocol to Linux. I was desperate until today when I found the solution.
cd adt-bundle-linux-x86_64/sdk/platform-tool
and this will fetch all the files from external sd card:
./adb pull /sotrage/extSdCard/
cd adt-bundle-linux-x86_64/sdk/platform-tool
This will fetch all the files from internal memory:
./adb pull /storage/sdcard0/
./adb pull /sotrage/extSdCard/
Subscribe to:
Posts (Atom)

