Skip to content

Instantly share code, notes, and snippets.

View leandro's full-sized avatar
🏠
Working from home

Leandro Camargo leandro

🏠
Working from home
View GitHub Profile
# recursive Hash#clone extension, because I needed it!
class Hash
def clone(recursive = false)
return super() unless recursive
new_hash = {}
for k, v in self
key = k.is_a?(Hash) ? k.clone(true) : (k.clone rescue k)
# having a pretty dump/print of Hash objects, for debugging clarity purposes (for the sake of having a sane Hash debugging)
class Hash
def to_s(pretty = false)
return super() unless pretty
indent = lambda do |hash, tabs|
tabs += 1 if tabs == 0
indentation = "\t" * tabs
indented_output = []
" checksyntax.vim -- Check syntax when saving a file (php, ruby, tex ...)
" @Author: Tom Link (micathom AT gmail com)
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Created: 04-Mai-2005.
" @Last Change: 2009-08-31.
" @Revision: 356
if exists('g:checksyntax')
finish
endif
" Delete buffer while keeping window layout (don't close buffer's windows).
" Version 2008-11-18 from http://vim.wikia.com/wiki/VimTip165
if v:version < 700 || exists('loaded_bclose') || &cp
finish
endif
let loaded_bclose = 1
if !exists('bclose_multiple')
let bclose_multiple = 1
endif
require 'json'
require 'hpricot'
require 'open-uri'
module Rublickr
AUTH_URL = 'http://flickr.com/services/auth/'.freeze
API_URL = 'http://api.flickr.com/services/rest/'.freeze
# USAGE
#! /bin/sh
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server
# Description: starts nginx using start-stop-daemon
@leandro
leandro / gemspec
Created May 13, 2010 17:47 — forked from defunkt/gemspec
#!/usr/bin/env ruby
# Usage: gemspec [-s] GEMNAME
#
# Prints a basic gemspec for GEMNAME based on your git-config info.
# If -s is passed, saves it as a GEMNAME.gemspec in the current
# directory. Otherwise prints to standard output.
#
# Once you check this gemspec into your project, releasing a new gem
# is dead simple:
#
#!/bin/sh
# Usage: unicorn_github
# Script used to start unicorn in GitHub staging and production environments.
# This is called primarily by god.
set -e
# configure GC settings
export RUBY_HEAP_MIN_SLOTS=800000
export RUBY_HEAP_FREE_MIN=100000
export RUBY_HEAP_SLOTS_INCREMENT=300000
class Hash
def hash_from(*keys)
keys.inject({}) { |memo, obj| memo.merge(obj => self[obj]) }
end
end
# example:
# >> a = {:foo => 1, :bar => 2, :foobar => 3}
require 'benchmark'
class Hash
def hash_from_1(*keys)
keys.inject({}) { |memo, obj| memo.merge(obj => self[obj]) }
end
def hash_from_2(*keys)
self.dup.delete_if { |k, v| !keys.include? k }