Skip to content

Instantly share code, notes, and snippets.

View slezica's full-sized avatar

Santiago Lezica slezica

View GitHub Profile
def init():
# This wrapper avoids global scope contamination
import os, sys, atexit, readline, rlcompleter, pprint, glob
# Enable auto-complete:
readline.parse_and_bind("tab: complete")
# Save command history:
history_path = os.path.expanduser("~/.pyhistory")
#!/usr/bin/env python
import os, sys, shutil
FROM_TO = (
('/origin/dir/1', '/destination/dir/1'),
('/origin/dir/2', '/destination/dir/2'),
('/origin/dir/3', '/destination/dir/3')
# ...
)
# SETTING DEFAULT
sysctl -w net.ipv4.ip_local_port_range="500 65535" # 32768 61000
sysctl -w net.ipv4.tcp_tw_recycle="1" # 0
sysctl -w net.ipv4.tcp_tw_reuse="1" # 0
sysctl -w net.ipv4.tcp_rmem="4096 87380 16777216" # 4096 87380 6291456
sysctl -w net.ipv4.tcp_wmem="4096 16384 16777216" # 4096 16384 4194304
sysctl -w fs.file-max="655300" # 797108
sysctl -w fs.nr_open="3000000" # 1048576
import types, time, functools
from twisted.internet import reactor, protocol, threads
# ---
def async(func):
def wrapper(*args, **kwargs):
@slezica
slezica / TrackingDict.py
Created August 20, 2014 19:49
Detect unused keys in configuration dicts
class TrackingDict(dict):
instances = []
def __init__(self, dct):
super(TrackingDict, self).__init__(dct)
self.used_keys = []
TrackingDict.instances.append(self)
request = Promise.promisifyAll require 'request'
refreshToken = (token, refresh_token, provider) ->
request.postAsync
uri: provider.refreshUrl
headers:
'Authorization': "Bearer #{token}"
'Content-Type' : 'application/json'
# Clásicos

J. D. Salinger      | El Guardián entre el Centeno
Lewis Carroll       | Alicia en el País de las Maravillas
R. L. Stevenson     | Dr. Jekyll y Mr. Hyde
A. Huxley           | Un Mundo Feliz
García Márquez      | Crónica de una Muerte Anunciada
García Márquez      | Cien Años de Soledad
Homero              | La Odisea
@slezica
slezica / convert.coffee
Last active August 29, 2015 14:19
DT db serialized polygon to geoJSON
# Convert from SQL serialized format:
parsePolygon = (polygon_s) ->
for point_s in polygon_s.split('|')
point_s.split(',').map(parseFloat)
toGeoJSON = (polygon) ->
# `polygon` is an array of [lat, lng]
polygon = (point.reverse() for point in polygon)
polygon.push(polygon[0])
@slezica
slezica / validation.coffee
Created May 25, 2015 21:55
Simple coffee validation
kindof = (x) ->
if x? then x.constructor else x
validateWithFunction = (object, func) ->
true_or_reason = func(object)
if true_or_reason is true
{ valid: true }
else
{ valid: false, reason: true_or_reason }
var gulp = require('gulp');
var plumber = require('gulp-plumber');
var concat = require('gulp-concat');
var watch = require('gulp-watch');
var rename = require('gulp-rename');
var gutil = require('gulp-util');
var minifyCss = require('gulp-minify-css');
var sass = require('gulp-sass');
var coffee = require('gulp-coffee');