Skip to content

Instantly share code, notes, and snippets.

View alainravet's full-sized avatar

Alain Ravet alainravet

  • Braine l'Alleud, Belgium
View GitHub Profile
@croaky
croaky / single_recipient_smtp.rb
Created March 15, 2012 06:32
Set staging environment email to go to a single email address you control in order to not accidentally send production email addresses staging data.
module SingleRecipientSmtp
def self.included(clazz)
clazz.class_eval do
cattr_accessor :single_recipient_smtp_settings
end
end
def perform_delivery_single_recipient_smtp(mail)
mail.to = single_recipient_smtp_settings[:to]
mail.cc = nil
@marcel
marcel / gist:2100703
Created March 19, 2012 07:24
giftube – Generates an animated gif from a YouTube url.
#!/usr/bin/env ruby
# giftube – Generates an animated gif from a YouTube url.
#
# Usage:
#
# giftube [youtube url] [minute:second] [duration]
#
# ex.
#
@cayblood
cayblood / rake_autocomplete.rb
Created April 26, 2012 14:21
Bash autocomplete script for rakefiles
#!/usr/bin/env ruby
# Complete rake tasks script for bash
# Save it somewhere and then add
# complete -C path/to/script -o default rake
# to your ~/.bashrc
# Bug-fix from Xavier Shay's version
require 'fileutils'
@panthomakos
panthomakos / benchmark.rb
Created May 3, 2012 20:06
Benchmark Your Bundle
#!/usr/bin/env ruby
require 'benchmark'
REGEXPS = [
/^no such file to load -- (.+)$/i,
/^Missing \w+ (?:file\s*)?([^\s]+.rb)$/i,
/^Missing API definition file in (.+)$/i,
/^cannot load such file -- (.+)$/i,
]
@JEG2
JEG2 / tweet_oge_price_signal.rb
Created August 1, 2012 19:20
A simple bot for tweeting OGE's daily price signal
require "rest_client"
require "twitter"
URL = "http://www.oge.com/residential-customers/products-and-services/" +
"Positive-Energy-Smart-Grid/Pages/PriceSignal.aspx"
DATE_RE = Time.now.strftime("%A,\\s+%B\\s+%d,\\s+%Y")
unless ARGV.size == 4
abort "USAGE: #{$PROGRAM_NAME} CONSUMER_KEY CONSUMER_SECRET " +
"OAUTH_TOKEN OAUTH_TOKEN_SECRET"
@piscisaureus
piscisaureus / pr.md
Created August 13, 2012 16:12
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@clarkware
clarkware / lyrics.rb
Created September 10, 2012 20:05
Random Lyrics
#!/usr/bin/env ruby
# API Documentation at http://api.wikia.com/wiki/LyricWiki_API
require 'open-uri'
require 'json'
require 'tmpdir'
ARTIST = "Johnny Cash"
anonymous
anonymous / concerning.rb
Created December 18, 2012 18:00
class Module
# We often find ourselves with a medium-sized chunk of behavior that we'd
# like to extract, but only mix in to a single class.
#
# We typically choose to leave the implementation directly in the class,
# perhaps with a comment, because the mental and visual overhead of defining
# a module, making it a Concern, and including it is just too great.
#
#
# Using comments as lightweight modularity:
@michaelfairley
michaelfairley / immutable-ruby.md
Last active October 8, 2019 14:15
Immutable Ruby

Immutable Ruby

Libraries I talked about

  • ice_nine: Deep freeze ruby objects
  • Values: Simple immutable value objects for ruby
  • immutable_attributes: specify attributes within an ActiveRecord model that can be set but not modified
  • hamster: Efficient, Immutable, Thread-Safe Collection classes for Ruby

Next Steps

@alainravet
alainravet / binary_file_string_utils.rb
Last active December 14, 2015 04:49
extract POIs from a TomTom *.ov2 file (in Ruby)
module BinaryFileStringUtils
def byte_to_int
self.unpack('U').first
end
def little_endian_to_int
# source : http://stackoverflow.com/questions/5236059/unpack-signed-little-endian-in-ruby
arr, bits, num = self.unpack('V*'), 0, 0
arr.each do |int|
num += int << bits