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
@dmoisset
dmoisset / timer.py
Created March 10, 2014 22:11
A small timer useful for testing
import contextlib
from datetime import datetime
class Timer(object):
def start(self):
self.start = datetime.now()
def stop(self):
@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()
@aydiv
aydiv / TestPayment.py
Created April 25, 2012 16:51
Paypal Adaptive Payments - Python sample for parallel payment
import urllib
import urlparse
import collections
import httplib
def TestPayment():
#Set our headers
headers = {
'X-PAYPAL-SECURITY-USERID': 'jb-us-seller_api1.paypal.com',
'X-PAYPAL-SECURITY-PASSWORD': 'WX4WTU3S8MY44S7F',
@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'
;
@acdha
acdha / active_value_filter.py
Created August 31, 2012 20:14
Django admin list_filter which filters out values which are not used in the current queryset
from django.contrib.admin import FieldListFilter
from django.utils.translation import ugettext as _
class ActiveValueFilter(FieldListFilter):
"""list_filter which displays only the values for a field which are in use
This is handy when a large range has been filtered in some way which means
most of the potential values aren't currently in use. This requires a
queryset field or annotation named "item_count" to be present so it can
// 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) );
@eykd
eykd / .gitignore
Created January 19, 2012 04:37
Full stack BDD testing with Behave+Mechanize+Django
*.pyc
bin/
include/
lib/
@riccardoscalco
riccardoscalco / README.md
Last active April 1, 2020 14:02
Topojson of Italy (province)
@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
@Vigrond
Vigrond / listlinksmixin.py
Last active May 18, 2020 18:13
A Django 2.2 Admin Mixin that supports foreign key relationship links with list_links attribute
from django.urls import reverse
from django.utils.html import format_html
class ListLinksMixin(object):
"""
Support for list_links attribute. Items in list_links must also be in list_display
Usage to make 'fieldTwo' a link:
list_display = ('fieldOne', 'fieldTwo',)
list_links = ('fieldTwo',)