Skip to content

Instantly share code, notes, and snippets.

@rafacv
rafacv / venv.sh
Created July 22, 2016 20:28
Simple bash/zsh functions to use VirtualEnv
# VirtualEnv
function venv() {
if [ -n "$1" ]; then
venv=$1
shift
if [ ! -d ~/.venv/$venv ]; then
virtualenv ~/.venv/$venv $*
fi
source ~/.venv/$venv/bin/activate
fi
@rafacv
rafacv / npm_dependencies.sh
Created November 13, 2015 18:12
List all root npm dependencies with locked down versions
npm ls | grep -E "^(├|└)─" | cut -d" " -f2 | awk '{FS = "@"; print "\""$1"\"", ":", "\""$2"\""}'
@rafacv
rafacv / event-with-delay.js
Last active October 16, 2015 22:42
Delay responses to events
/*
* Sometimes it's useful to wait for the user to complete the action
* he's engaged on instead of trying to handle it right away. A practical
* example is to avoid flooding servers with tons of autocompletion requests
* for each key stroke the user types in. A more efficient approach is to wait
* until the user feeds enough before attempting make requests for only one or
* two letters.
*
* Usage:
* listenToEventAndDelay(textInput, 'keydown', autoCompleteFunction, 500);
@rafacv
rafacv / install_python.sh
Last active December 14, 2015 19:58
Install Py2.7.3 CentOS
cd /tmp
curl -O http://python.org/ftp/python/2.7.3/Python-2.7.3.tar.bz2
tar xf Python-2.7.3.tar.bz2
cd Python-2.7.3
./configure --enable-shared --prefix=/usr/local
make
sudo make altinstall

Jim Weirich:

This is how I explain it… Ruby has Procs and Lambdas. Procs are created with Proc.new { }, lambdas are created with lambda {} and ->() {}.

In Ruby 1.8, proc {} creates lambda, and Ruby 1.9 it creates procs (don't ask).

Lambdas use method semantics when handling parameters, procs use assignment semantics when handling parameters.

This means lambdas, like methods, will raise an ArgumentError when called with fewer arguments than they were defined with. Procs will simply assign nil to variables for arguments that were not passed in.

@rafacv
rafacv / apt-init.pp
Created December 24, 2012 13:53 — forked from fnando/apt-init.pp
class apt-get::update {
exec { "apt-get update":
command => "apt-get update"
}
}
@rafacv
rafacv / skype-search
Created October 18, 2012 01:54 — forked from leandro/skype-search
Search Skype history for given terms
@rafacv
rafacv / pyperclip.py
Created February 27, 2012 16:45
Unified interface to access clipboard across major OSes
# Source: http://coffeeghost.net/2010/10/09/pyperclip-a-cross-platform-clipboard-module-for-python/
# Pyperclip v1.3
# A cross-platform clipboard module for Python. (only handles plain text for now)
# By Al Sweigart al@coffeeghost.net
# Usage:
# import pyperclip
# pyperclip.copy('The text to be copied to the clipboard.')
# spam = pyperclip.paste()
@rafacv
rafacv / encoding.rb
Created February 17, 2012 00:09
IronRuby doesn't respect encoding comments when eval'ing
eval <<ENC
# coding: utf-8
def method
puts "".encoding.inspect
end
ENC
eval <<ENC
# coding: big5
def method2
@rafacv
rafacv / index.erb
Created December 13, 2011 21:15
Code to get a hanging post request on windows using webrick over ironruby.
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>
$(function () {
$("#myb").click(function () {
$.ajax({
url: "/showme",
type: "POST",
data: {nome: "Jose", sobrenome: "Valim"},