Skip to content

Instantly share code, notes, and snippets.

@zhenyi2697
zhenyi2697 / localstorage_test.js
Created July 8, 2015 20:11
JavaScript: Test localStorage
'use strict'
// The helper
(function(self) {
//helper guts goes here :)
//data store for holding objects
var localStore = {};
@zhenyi2697
zhenyi2697 / django_i18n_cheat_sheet.md
Last active August 29, 2015 14:11
Django i18n cheat sheet

1. Create Message file

Run the following command from

  • The root directory of Django project

  • The root directory of Django app

    $ django-admin.py makemessages
    or
    $ django-admin.py makemessages -l fr # to update message file

java -Djava.library.path=/mnt/liting/jdk1.6.0_38/lib/ -jar minions.jar 9001 jedi004 9001 5
@zhenyi2697
zhenyi2697 / gist:8fd24da8f765bf81bb16
Created April 30, 2014 13:56
dpkg: warning: 'ldconfig' not found in PATH or not executable.
Modify /etc/sudoers
Defaults env_reset
Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
@zhenyi2697
zhenyi2697 / gist:8037328
Created December 19, 2013 10:36
Django: send email from template
from django.core.mail import EmailMultiAlternatives
from django.template.loader import render_to_string
from django.utils.html import strip_tags
subject, from_email, to = 'Order Confirmation', 'admin@yourdomain.com', 'someone@somewhere.com'
html_content = render_to_string('the_template.html', {'varname':'value'}) # ...
text_content = strip_tags(html_content) # this strips the html, so people will have the text as well.
# create the email, and attach the HTML version as well.

Steps to install PIL

$ sudo apt-get install python-imaging
$ sudo apt-get install libjpeg-dev libfreetype6 libfreetype6-dev zlib1g-dev

$ sudo ln -s /usr/lib/`uname -i`-linux-gnu/libfreetype.so /usr/lib/
$ sudo ln -s /usr/lib/`uname -i`-linux-gnu/libjpeg.so /usr/lib/
$ sudo ln -s /usr/lib/`uname -i`-linux-gnu/libz.so /usr/lib/

$ pip install PIL

@zhenyi2697
zhenyi2697 / test_output.py
Created October 30, 2013 09:12
Python: continuously read content from subprocess
#!/usr/bin/python
import subprocess
import time
cmd = 'python ./output.py'
proc = subprocess.Popen(
cmd,
shell=True,
@zhenyi2697
zhenyi2697 / gist:6761931
Created September 30, 2013 10:28
Google Data API: get image data
print 'AlbumID:', photo.albumid.text
print 'PhotoID:', photo.gphoto_id.text
if photo.exif.make and photo.exif.model:
camera = '%s %s' % (photo.exif.make.text, photo.exif.model.text)
else:
camera = 'unknown'
print 'Camera:', camera
print 'Content URL:', photo.content.src
print 'First Thumbnail:', photo.media.thumbnail[0].url
@zhenyi2697
zhenyi2697 / gist:6761384
Created September 30, 2013 09:29
Javascript: blueimp gallery load images
var carouselLinks = [],
linksContainer = $('#links'),
baseUrl;
// Add the demo images as links with thumbnails to the page:
$.each(result.photos.photo, function (index, photo) {
baseUrl = 'http://farm' + photo.farm + '.static.flickr.com/' +
photo.server + '/' + photo.id + '_' + photo.secret;
$('<a/>')
.append($('<img>').prop('src', baseUrl + '_s.jpg'))
.prop('href', baseUrl + '_b.jpg')
@zhenyi2697
zhenyi2697 / gist:6760653
Created September 30, 2013 07:59
Javascript: test browser user-agent
// test browser
var Sys = {};
var ua = navigator.userAgent.toLowerCase();
var s;
(s = ua.match(/msie ([\d.]+)/)) ? Sys.ie = s[1] :
(s = ua.match(/firefox\/([\d.]+)/)) ? Sys.firefox = s[1] :
(s = ua.match(/chrome\/([\d.]+)/)) ? Sys.chrome = s[1] :
(s = ua.match(/opera.([\d.]+)/)) ? Sys.opera = s[1] :
(s = ua.match(/version\/([\d.]+).*safari/)) ? Sys.safari = s[1] : 0;