Skip to content

Instantly share code, notes, and snippets.

View joke2k's full-sized avatar
🏠
Working from home

Daniele Faraglia joke2k

🏠
Working from home
View GitHub Profile
// Console arguments testing
var apc = [].slice;
(function(){
console.log( apc.call(arguments) );
})( "false", 1, undefined, null, ["foo","bar","baz"], {a:1,b:2}, false );
(function(){
console.log.call( console, apc.call(arguments) );
@pratul
pratul / kabala-calc.py
Created January 18, 2011 14:58
A numerological calculator based on the Kabbalah alphabet. (from Linda Goodman's "Star Signs")
#!/usr/bin/python
# authored by Pratul Kalia in January 2011.
# Released into the public domain.
import sys
# Chaldean-Hebrew Kabala Numberical Alphabet.
# Taken from the book "Star Signs" by Linda Goodman.
kabala = {'a': 1, 'b': 2, 'c': 3, 'd': 4,
'e': 5, 'f': 8, 'g': 3, 'h': 5,
@jfsiii
jfsiii / img2data.js
Created January 30, 2011 23:30
base64 encoding images in NodeJS
/*
* Based on https://gist.github.com/583836 from http://stackoverflow.com/questions/3709391/node-js-base64-encode-a-downloaded-image-for-use-in-data-uri.
* Neither that gist nor this one work for me in 0.2.x or 0.3.x.
*/
var request = require('request'),
BufferList = require('bufferlist').BufferList,
sys = require('sys'),
bl = new BufferList(),
url = 'http://nodejs.org/logo.png'
;
@esperlu
esperlu / mysql2sqlite.sh
Created April 27, 2011 05:46
MySQL to Sqlite converter
#!/bin/sh
# Converts a mysqldump file into a Sqlite 3 compatible file. It also extracts the MySQL `KEY xxxxx` from the
# CREATE block and create them in separate commands _after_ all the INSERTs.
# Awk is choosen because it's fast and portable. You can use gawk, original awk or even the lightning fast mawk.
# The mysqldump file is traversed only once.
# Usage: $ ./mysql2sqlite mysqldump-opts db-name | sqlite3 database.sqlite
# Example: $ ./mysql2sqlite --no-data -u root -pMySecretPassWord myDbase | sqlite3 database.sqlite
@acdha
acdha / postmkvirtualenv
Created September 2, 2011 13:07
My virtualenvwrapper postmkvirtualenv hook
#!/bin/bash
# This hook is run after a new virtualenv is activated.
set -e
(cat <<'PYDOC'
#!/usr/bin/env python
import pydoc
if __name__ == '__main__':
pydoc.cli()
@bryanchow
bryanchow / gpg.py
Created October 31, 2011 07:30
Django utility function for encrypting data using GPG
# A simple Django utility function for encrypting data using GnuPG
#
# https://gist.github.com/1327072
import os
import subprocess
from django.core.exceptions import ImproperlyConfigured
from django.conf import settings
@elidickinson
elidickinson / admin.py
Created November 20, 2011 01:16
Using CKEditor with Flatpages
from django.contrib import admin
from django.contrib.flatpages.models import FlatPage
# Note: we are renaming the original Admin and Form as we import them!
from django.contrib.flatpages.admin import FlatPageAdmin as FlatPageAdminOld
from django.contrib.flatpages.admin import FlatpageForm as FlatpageFormOld
from django import forms
from ckeditor.widgets import CKEditorWidget
@insin
insin / bash_prompt.sh
Created December 3, 2011 01:49 — forked from woods/git_svn_bash_prompt.sh
Set color bash prompt according to active virtualenv, git branch and return status of last command.
#!/bin/bash
#
# DESCRIPTION:
#
# Set the bash prompt according to:
# * the active virtualenv
# * the branch/status of the current git repository
# * the return value of the previous command
# * the fact you just came from Windows and are used to having newlines in
# your prompts.
@brantfaircloth
brantfaircloth / cool_argparse_stuff.py
Created December 7, 2011 16:47
Some cool argparse stuff
class FullPaths(argparse.Action):
"""Expand user- and relative-paths"""
def __call__(self, parser, namespace, values, option_string=None):
setattr(namespace, self.dest, os.path.abspath(os.path.expanduser(values)))
def is_dir(dirname):
"""Checks if a path is an actual directory"""
if not os.path.isdir(dirname):
msg = "{0} is not a directory".format(dirname)
raise argparse.ArgumentTypeError(msg)
@cslarsen
cslarsen / ipv4.py
Created January 11, 2012 15:16
Two small Python functions to convert IPv4 address to integer and vice-versa
#!/usr/bin/env python
"""Functions to convert IPv4 address to integer and vice-versa.
Written by Christian Stigen Larsen, http://csl.sublevel3.org
Placed in the public domain by the author, 2012-01-11
Example usage:
$ ./ipv4 192.168.0.1 3232235521
192.168.0.1 ==> 3232235521