Skip to content

Instantly share code, notes, and snippets.

@joequery
joequery / gist:3077833
Created July 9, 2012 17:43
Converting a simple website to Python Flask (backup gist!)

Flask is a Python web framework that's steadily increasing in popularity within the webdev world. After reading so many great things about Flask, I decided to try it out myself. I personally find testing out a new framework difficult, because you must find a project complex enough to reveal the framework's quirks, but not so daunting as to take the fun out of the project. Luckily, my PHP/Wordpress powered website filled this role quite nicely - the website simply consists of static content, a contact page, and a blog. If I could not convert such a simple site over to Flask, I would immediately know that Flask and I would not make a good team.

@joequery
joequery / gist:2870704
Created June 4, 2012 20:34
Stupidtable example
<html>
<head>
<title>Stupid jQuery table sort</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="stupidtable.js?dev"></script>
<script type="text/javascript">
$(function(){
$("table").stupidtable();
console.log($("table tbody tr td").eq(0))
$("table th").bind("click", function(){
@joequery
joequery / bruteforce.rb
Created May 11, 2012 15:41
How long to brute force a key of length n?
# How long to brute force keys
ks = 1000000000 # A billion keys per second
clusters = 10 # How many computers in the cluster attacking our key?
numChars = 38 # We have 38 characters available to use in the key
n = 100 # Length of the key string
combinations = numChars ** n # This ignores variable length too
# How many years it would take a single computer to brute force.
@joequery
joequery / gist:2486369
Created April 25, 2012 04:31
FFMpeg H264 encode_video function
# encode a video
# arg1: video origin
# arg2: destination
function encode_video(){
ffmpeg -y -i $1 -pass 1 -vcodec libx264 -b 756k -g 15 -bf 3 -refs 6 -b_strategy 1 -coder 1 -qmin 10 -qmax 51 -sc_threshold 40 -flags +loop -cmp +chroma -me_range 16 -me_method umh -subq 7 -i_qfactor 0.71 -qcomp 0.6 -qdiff 4 -directpred 3 -flags2 +dct8x8+wpred+bpyramid+mixed_refs -trellis 1 -partitions +parti8x8+parti4x4+partp8x8+partp4x4+partb8x8 -acodec libfaac -ab 64k $2
ffmpeg -y -i $1 -pass 2 -vcodec libx264 -b 756k -g 15 -bf 3 -refs 6 -b_strategy 1 -coder 1 -qmin 10 -qmax 51 -sc_threshold 40 -flags +loop -cmp +chroma -me_range 16 -me_method umh -subq 7 -i_qfactor 0.71 -qcomp 0.6 -qdiff 4 -directpred 3 -flags2 +dct8x8+wpred+bpyramid+mixed_refs -trellis 1 -partitions +parti8x8+parti4x4+partp8x8+partp4x4+partb8x8 -acodec libfaac -ab 64k $2
}
@joequery
joequery / gist:1807167
Created February 12, 2012 08:01
Install Nginx and PHP5-FPM
# Add a necessary repository.
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:brianmercer/php
sudo apt-get update
sudo apt-get install nginx
sudo apt-get install php5-cli php5-common php5-mysql php5-suhosin php5-gd php5-dev
sudo apt-get install php5-fpm php5-cgi php-pear php5-memcache php-apc
@joequery
joequery / gist:1695043
Created January 28, 2012 17:06
Ruby Assignment Returns
1.9.2-p290 :001 > def mytest
1.9.2-p290 :002?> return @someval = 10
1.9.2-p290 :003?> end
=> nil
1.9.2-p290 :004 > mytest
=> 10
1.9.2-p290 :005 > @someval
=> 10
1.9.2-p290 :006 > def mytest2
1.9.2-p290 :007?> return @someval ||= 30
@joequery
joequery / gist:1670769
Created January 24, 2012 15:45
Install git-dude on OSX

This is a small instruction guide for installing git-dude on OSX. Git dude is a convenient git repo monitoring service.

Ensure you have Homebrew installed.


Install growlnotify via brew install growlnotify.

If you are a Lion user and are getting No formula available, then you can just download growlnotify as a package

@joequery
joequery / gist:1640945
Created January 19, 2012 16:19
Nginx individual site config for multiple rails apps with Unicorn
##############################################################
# Upstream must have unique name and unique socket. #
# The socket must match what is in the app's unicorn.rb file #
##############################################################
upstream railsapp1_server {
server unix:/tmp/railsapp1.sock fail_timeout=0;
}
##############################
# Rewrite www to non-www #
@joequery
joequery / gist:1635318
Created January 18, 2012 20:23
Nginx config for use with multiple rails apps
worker_processes 1;
user nobody nogroup;
pid /tmp/nginx.pid;
error_log /tmp/nginx.error.log;
events {
worker_connections 1024;
accept_mutex off;
}
http {
default_type application/octet-stream;
@joequery
joequery / gist:1607063
Created January 13, 2012 15:49
Convient bash functions for managing nginx and Unicorn
# Kill and restart nginx
function restart_nginx(){
pids=$(pidof nginx)
if [[ -n $pids ]];
then
sudo kill -9 $pids
sudo service nginx restart
fi
}