Skip to content

Instantly share code, notes, and snippets.

View samleb's full-sized avatar
:octocat:
Freelance CTO

Samuel Lebeau samleb

:octocat:
Freelance CTO
View GitHub Profile
fib_generator = Enumerator.new { |y|
a = b = 1
loop {
y << a
a, b = b, a + b
}
}
fib_even_generator = Enumerator.new { |y|
loop {
fib_generator = Enumerator.new { |y|
a = b = 1
loop {
y << a
a, b = b, a + b
}
}
fib_even_generator = Enumerator.new { |y|
fib_generator.each { |n|
@samleb
samleb / linkbucks.user.js
Created January 17, 2012 21:40
[userscript] LinkBucks: Redirect to target URL skipping countdown
// ==UserScript==
// @name LinkBucks.com - Auto redirect
// @namespace samleb.github.com
// @description Redirect to target URL skipping countdown.
// @include http*://*.linkbucks.com/
// ==/UserScript==
(function() {
var REGEXP = /TargetUrl\s*=\s*([^;\n]*)/,
urlLiteral = document.body.innerHTML.match(REGEXP)[1],
@samleb
samleb / gist:4002490
Created November 2, 2012 16:34
Error 500 when browsing SexyScopes documentation on rubydoc.info
% curl -i http://rubydoc.info/gems/sexy_scopes/0.5.0
HTTP/1.1 500 Internal Server Error
Server: nginx
Date: Fri, 02 Nov 2012 16:31:20 GMT
Content-Type: text/plain
Connection: keep-alive
Status: 500 Internal Server Error
X-Frame-Options: sameorigin
X-XSS-Protection: 1; mode=block
Content-Length: 7407
@samleb
samleb / example_use.rb
Created November 22, 2012 13:51
Ruby snippet to get Facebook Like in batches
class Film < ActiveRecord::Base
class << self
def compute_facebook_likes
fb = FacebookLike.new(AppConfig.facebook.access_token)
find_in_batches(:select => 'id, permalink', :batch_size => fb.batch_size) do |group|
urls = group.map { |f| film_url(f) }
likes = fb.request_likes_for_urls(urls)
update_facebook_likes(group, likes)
sleep 0.2
end
@samleb
samleb / gist:5562831
Last active December 17, 2015 06:08
Promised, an Objective-C implementation of Promise Unit Tests
//
// PromisedTests.m
// PromisedTests
//
// Created by Samuel Lebeau on 02/05/13.
// Copyright (c) 2013 Samuel Lebeau. All rights reserved.
//
#import "PromisedTests.h"
#import "PMDeferred.h"
# (c) Copyright 2009 Samuel Lebeau. All Rights Reserved.
require 'erb'
module Bouncer
module JavaScriptMacros
class FilterFunction
attr_reader :name, :condition, :options
DEFAULT_OPTIONS = {
:condition_variable => 'condition',
def association_names_to_joins_argument(names)
joins = names.pop
joins = { names.pop => joins } until names.empty?
joins
end
association_names_to_joins_argument([:memberships])
# => :memberships
association_names_to_joins_argument([:memberships, :members])
@samleb
samleb / gist:5690666
Last active December 17, 2015 23:39
Shell snippets to deal with rubygems (only tested on zsh)
function gems-dir () {
echo `ruby -rrubygems -e "puts Gem.dir"`/gems
}
function gems {
cd `gems-dir`
pwd
}
function gem-home {
$$('.home_theater #carousel').each(function(element) {
var EFFECT_OPTIONS = {
duration: 0.75,
position: 'parallel',
transition: S2.FX.Transitions.easeFromTo
};
var slides = element.select('.slide'),
index = 0;