Skip to content

Instantly share code, notes, and snippets.

View juanrossi's full-sized avatar

Juan Rossi juanrossi

  • mercadolibre
  • Buenos Aires, Argentina
View GitHub Profile
@stagas
stagas / how-to-run-apache-and-node.js-together-the-right-way.markdown
Created December 24, 2010 14:45
How to run Apache and Node.js together (the right way)

Step 1

Get a VPS that offers 2 or more IP addresses.

Step 2

From the WHM cPanel, find the menu item Service Configuration, select Apache Configuration and then click on Reserved IPs Editor.

Step 3

@MacMaru
MacMaru / wrap_view.py
Created July 31, 2011 16:59
Override Tastypie wrap_view() to return custom (JSON) response
class YourResource(ModelResource):
def wrap_view(self, view):
"""
Wraps views to return custom error codes instead of generic 500's
"""
@csrf_exempt
def wrapper(request, *args, **kwargs):
try:
@lucasfais
lucasfais / gist:1207002
Created September 9, 2011 18:46
Sublime Text 2 - Useful Shortcuts

Sublime Text 2 – Useful Shortcuts (Mac OS X)

General

⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
⌘KB toggle side bar
⌘⇧P command prompt
@peregrinogris
peregrinogris / grepc.sh
Last active December 2, 2021 20:17
Custom flavored grep
#!/bin/bash
EXCLUDEDIR=${EXCLUDEDIR:-"env/*"}
COLOR=${COLOR:-always}
CONTEXT=${CONTEXT:-0}
grep -IiRn --exclude="$EXCLUDE" --exclude-dir="$EXCLUDEDIR" --color=$COLOR -C$CONTEXT "$1" * \
| less -iFRX
@mikeyk
mikeyk / gist:1329319
Created October 31, 2011 22:56
Testing storage of millions of keys in Redis
#! /usr/bin/env python
import redis
import random
import pylibmc
import sys
r = redis.Redis(host = 'localhost', port = 6389)
mc = pylibmc.Client(['localhost:11222'])
@ignacioricci
ignacioricci / select-to-dropdown.js
Created February 6, 2012 18:52
Change select to dropdown list
$('#selectJob').children().hide();
var sel_list = $('<div id="jobDropdown"><strong class="cta"><span></span></strong><ul></ul></div>');
sel_list.find('span').text($('#selectJob label').text());
$('#selectJob select').children('option').each(function(){
sel_list.children('ul').append('<li>' + $(this).text() + '</li>');
});
$('#selectJob').append(sel_list);
$('#jobDropdown').find('li').live('click',function(e){
$('#selectJob select option').eq($(this).index()).attr('selected','selected').siblings('option').removeAttr('selected');
$(this).addClass('selected');
@jboner
jboner / latency.txt
Last active July 23, 2024 14:12
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@nikic
nikic / password_hashing_api.md
Created September 12, 2012 15:04
The new Secure Password Hashing API in PHP 5.5

The new Secure Password Hashing API in PHP 5.5

The [RFC for a new simple to use password hashing API][rfc] has just been accepted for PHP 5.5. As the RFC itself is rather technical and most of the sample codes are something you should not use, I want to give a very quick overview of the new API:

Why do we need a new API?

Everybody knows that you should be hashing their passwords using bcrypt, but still a surprising number of developers uses insecure md5 or sha1 hashes (just look at the recent password leaks). One of the reasons for this is that the crypt() API is ridiculously hard to use and very prone to programming mistakes.

@robhudson
robhudson / gist:3848832
Last active July 12, 2018 15:25
Quick way to set CORS headers on django-tastypie resources
class CORSResource(object):
"""
Adds CORS headers to resources that subclass this.
"""
def create_response(self, *args, **kwargs):
response = super(CORSResource, self).create_response(*args, **kwargs)
response['Access-Control-Allow-Origin'] = '*'
response['Access-Control-Allow-Headers'] = 'Content-Type'
return response
@peregrinogris
peregrinogris / git-usebranch
Last active February 1, 2017 18:17
Use this to checkout a branch ending with a certain string
#!/usr/bin/env bash
branch=`git branch -a | egrep -io "([^/]+/)?[^/]+$1$" | sed 's/* //' | head -1`
git checkout $branch