Skip to content

Instantly share code, notes, and snippets.

View flavianmissi's full-sized avatar

Flavian Missi flavianmissi

View GitHub Profile
@flavianmissi
flavianmissi / simple_javascript_pagination.js
Created November 26, 2011 00:46
Simple JavaScript pagination
config = {
'items_per_page': 3,
'container_id': 'elements'
};
function Pagination(config, objects) {
this.config = config;
this.objects = objects;
this.current_page = 1;
this.offset = this.config.items_per_page;
@flavianmissi
flavianmissi / find_and_ack
Created December 12, 2011 20:44
Search for a pattern with the files resulting of a find command
find . -name "urls.py" -type f -exec ack -l "paginas" {} \;
@flavianmissi
flavianmissi / json_response_generic_view.py
Created December 13, 2011 17:57
Simple json response generic view
from django.views.generic import View
from django.utils import simplejson
class JSONResponseView(View):
def render_to_response(self, data, **httpresponse_kwargs):
"Retuns a json response based on the context"
json_data = simplejson.dumps(data)
return HttpResponse(json_data, content_type="application/json", **httpresponse_kwargs)
@flavianmissi
flavianmissi / restart_zombie_processes
Created January 11, 2012 12:12
Stop and restart zombie processes
kill -HUP `ps -A -ostat,ppid,pid,cmd | grep -e '^[Zz]' | awk '{print $2}'`
@flavianmissi
flavianmissi / ruby_array.rb
Created January 12, 2012 19:04
Ruby bizarre behavior
a = []
a[0] = 10
a[100000] = 10
puts a.inspect
@flavianmissi
flavianmissi / assert_queryset_equal_sample.py
Created May 1, 2012 13:55
Django's assertQuerysetEqual sample
user = User.objects.create(email="[email protected]")
qs = User.objects.all()
self.assertQuerysetEqual(qs, [repr(user)])
@flavianmissi
flavianmissi / pre-commit.sh
Created May 7, 2012 14:48
Git hook to run gofmt -w . before commiting
gofmt -w .
if [ "$(git diff --diff-filter M --name-only)" == "$(git diff --cached --name-only)" ];
then
echo "There's gofmt alterations to be commited."
exit 1
fi
@flavianmissi
flavianmissi / multiline-sed-replace.sh
Created May 24, 2012 21:10
Multiline sed replace
#!/bin/bash
REPO_PATH="/home/ubuntu"
CONF='[gitosis]\
repositories = /mnt/repositories\
generate-files-in = /mnt/gitosis\
gitweb = no\
daemon = no'
sed -ie "s,\[gitosis\],$CONF," ${REPO_PATH}/gitosis.conf
@flavianmissi
flavianmissi / rsyslog-install.sh
Created June 12, 2012 14:07
Rsyslog installation script (ubuntu 12.04)
#!/bin/bash
sudo apt-get update
sudo apt-get -y install make libmysqlclient-dev x11-apps
wget http://www.rsyslog.com/files/download/rsyslog/rsyslog-4.6.1.tar.gz
tar xvf rsyslog-4.6.1.tar.gz
cd rsyslog-4.6.1
sudo mkdir /var/log/rsyslog # replace by your $WorkDirectory value, if any
@flavianmissi
flavianmissi / ec2_openstack.go
Created July 9, 2012 21:50
Testing goamz against openstack
package main
import (
"fmt"
"launchpad.net/goamz/aws"
"launchpad.net/goamz/ec2"
)
var auth aws.Auth
var region aws.Region