Skip to content

Instantly share code, notes, and snippets.

View jbgutierrez's full-sized avatar

Javier Blanco Gutiérrez jbgutierrez

View GitHub Profile
@henrik
henrik / hash_deep_diff.rb
Created July 14, 2009 08:38
Recursively diff two Ruby hashes.
# Recursively diff two hashes, showing only the differing values.
# By Henrik Nyh <http://henrik.nyh.se> 2009-07-14 under the MIT license.
#
# Example:
#
# a = {
# "same" => "same",
# "diff" => "a",
# "only a" => "a",
# "nest" => {
@tomkersten
tomkersten / somehost.conf
Created October 28, 2011 20:36
Nginx config with CORS headers added globally (for application w/ Basic Auth)
upstream your-app {
# fail_timeout=0 means we always retry an upstream even if it failed
# to return a good HTTP response (in case the Unicorn master nukes a
# single worker for timing out).
server unix:/tmp/your_app.socket fail_timeout=0;
}
server {
listen 80;
@ryanb
ryanb / issues_with_modules.md
Created November 29, 2012 22:38
Points on how modules can make code difficult to read.

My issues with Modules

In researching topics for RailsCasts I often read code in Rails and other gems. This is a great exercise to do. Not only will you pick up some coding tips, but it can help you better understand what makes code readable.

A common practice to organize code in gems is to divide it into modules. When this is done extensively I find it becomes very difficult to read. Before I explain further, a quick detour on instance_eval.

You can find instance_eval used in many DSLs: from routes to state machines. Here's an example from Thinking Sphinx.

class Article &lt; ActiveRecord::Base
require "time"
require "date"
class Date
def to_time
Time.local(year, month, day)
end
end
class Time
@greypants
greypants / timeBasedAnimationPattern.js
Created September 17, 2012 18:48
JS: Time-based animation pattern
// Full Blog Post: http://viget.com/extend/time-based-animation
// requestAnimationFrame() polyfill: https://gist.github.com/1579671
window.APP = window.APP || {};
APP.pause = function() {
window.cancelAnimationFrame(APP.core.animationFrame);
};
APP.play = function() {

Best practices for building Vim plugins

2016-11-05 VimConf 2016

@shripadk
shripadk / gist:652819
Created October 29, 2010 03:10
Express authentication using Redis for session store and Couchdb for database (in coffeescript!)
###
Module dependencies
###
require.paths.unshift "#{__dirname}/lib/support/express-csrf/"
require.paths.unshift "#{__dirname}/lib/support/node_hash/lib/"
express = require 'express'
app = module.exports = express.createServer()
RedisStore = require 'connect-redis'
@creationix
creationix / output.log
Created May 8, 2013 22:02
Working version of generator async code sample. Using node from https://github.com/andywingo/node/tree/v8-3.19
tim@touchsmart:~/Code$ nvm use v0.11.2-generators
Now using node v0.11.2-generators
tim@touchsmart:~/Code$ node --harmony testgen.js
<Buffer 76 61 72 20 66 73 20 3d 20 72 65 71 75 69 72 65 28 27 66 73 27 29 3b 0a 66 75 6e 63 74 69 6f 6e 20 72 65 61 64 46 69 6c 65 28 70 61 74 68 2c 20 65 6e 63 ...>
Sleeping for 2000ms...
Done
@avdi
avdi / fib.rb
Created July 15, 2013 04:08
Fibonacci example from "Programming Elixir" translated to Ruby
require 'thread'
require 'benchmark'
module FibSolver
def self.fib(scheduler_queue, my_queue)
loop do
scheduler_queue << [:ready, my_queue]
message, *args = my_queue.pop
case message
when :fib
@RSpace
RSpace / Gemfile
Created April 23, 2011 12:49
Running Capybara and RSpec without Rails
source 'http://rubygems.org'
gem 'rspec'
gem 'capybara', :git => 'https://github.com/jnicklas/capybara.git'
gem 'launchy'
gem 'ruby-debug19'