Skip to content

Instantly share code, notes, and snippets.

View nitely's full-sized avatar
🟢
online

Esteban C Borsani nitely

🟢
online
View GitHub Profile
@nitely
nitely / pretty_timezones.py
Created June 16, 2014 22:12
Grouped pytz timezones
"""
Result:
TIMEZONE_CHOICES = [
("Africa", [
("Africa/Abidjan", "Abidjan"),
("Africa/Accra", "Accra"),
#...
]),
("America", [
@nitely
nitely / jasmine-ajax-spec.coffee
Last active August 29, 2015 14:03
jasmine 2.0 test ajax/post/getJSON/etc in jQuery
describe "post tests", ->
post = null
beforeEach ->
#jasmine-jquery
#fixtures = do jasmine.getFixtures
#fixtures.fixturesPath = 'base/test/fixtures/'
#loadFixtures 'bookmark.html'
post = spyOn $, 'post'
@nitely
nitely / django_is_checkbox,py
Created July 27, 2014 09:18
Django template filter for checking if a field is a BooleanField (checkbox)
#-*- coding: utf-8 -*-
from django.forms.widgets import CheckboxInput
from .. import register
@register.filter
def is_checkbox(field):
if isinstance(field.field.widget, CheckboxInput):
@nitely
nitely / download.js
Created December 11, 2014 02:29
node-downloaderJS using coroutines and generators
/* This is just a cool example on how to write coros in javascript Ecma6.
* Licence: MIT
* Author: esteban castro borsani
*/
var http = require('http');
var fs = require('fs');
var path = require('path');
var Q = require("q");
var co = require("co");
@nitely
nitely / json.js
Last active August 29, 2015 14:16
First steps: JSON Schema validator
/*
Author: Esteban Castro Borsani
Licence: MIT
*/
/*
This is a schema validator... errrgh.... this is the first step to create a json validator.
It does not do any validation, but it iterates over nested objects and arrays defined in your schema, recording the full path for error outputs.
REQUIRES: lodash
@nitely
nitely / django_compilemessages.py
Last active August 29, 2015 14:25
Django build .mo files for every app
if __name__ == '__main__':
import os
from subprocess import call
BASE = os.getcwd()
for root, dirs, files in os.walk("./spirit"):
if 'locale' not in dirs:
continue
@nitely
nitely / django_split_locale.py
Last active November 25, 2017 19:53
Django split big locale file into locales for every app
"""
Before running this script:
* move all locale folders (en, es, pl, etc) to ./locales, these are the big (original) .po files.
* create a locale folder in every app, then run 'django-admin makemessages -l xx' (where xx is every language)
* move the project root (the one containing the apps) to ./spirit
* run this script
* you should get all the django.po translated from the original locale files (those in the ./locales folder)
"""
@nitely
nitely / riak_multiget.py
Created August 5, 2015 19:26
riak benchmark multiget
"""
Results are in:
user / system / total / (real)
Riak multiget:
Riak Nodes: 5
CPUs: 8
Threads: 8
Keys: 50
Rehearsal -------------------------------------------------
@nitely
nitely / pushd.py
Created August 7, 2015 12:49
python pushd
from contextlib import contextmanager
import os
@contextmanager
def pushd(new_dir):
prev_dir = os.getcwd()
os.chdir(new_dir)
yield
os.chdir(prev_dir)
@nitely
nitely / file_hash.py
Created August 31, 2015 09:07
Django hash from file
import hashlib
def get_hash(file):
md5 = hashlib.md5()
for c in file.chunks():
md5.update(c)
return md5.hexdigest()