Skip to content

Instantly share code, notes, and snippets.

View emdeeeks's full-sized avatar

Gareth Griffiths emdeeeks

View GitHub Profile
@cabron
cabron / flags.rb
Created October 26, 2012 12:15
Ruby: flag printer
#!/usr/bin/env ruby
require 'net/http'
require 'uri'
COLOR_SOURCE_VALUES = 256
COLOR_TARGET_VALUES = 5
COLOR_DIVIDE = COLOR_SOURCE_VALUES / COLOR_TARGET_VALUES
TERM_COLOR_BASE = 16
def rgb_to_xterm(r, g, b) # part of grosser.it/2011/09/16/ruby-converting-html-colors-24bit-to-xtermterminal-colors/
@bct
bct / gist:3913085
Created October 18, 2012 16:37
shell functions for lazy ruby developers
function lsgems() {
rubyversion=$(ruby -v | cut -f2 -d' ' | sed 's/p/-p/')
gemroot=~/.rvm/gems/ruby-"$rubyversion"/gems
ls "$gemroot"
}
function cdgem() {
rubyversion=$(ruby -v | cut -f2 -d' ' | sed 's/p/-p/')
gemroot=~/.rvm/gems/ruby-"$rubyversion"/gems
@mweppler
mweppler / emailer.rb
Created September 14, 2012 07:13
A ruby emailer
# http://ruby-doc.org/stdlib-1.9.3/libdoc/net/smtp/rdoc/Net/SMTP.html
require 'digest/md5'
require 'mime/types'
require 'net/smtp'
require 'optparse'
require 'ostruct'
require 'yaml'
class Emailer
@nthomson
nthomson / parse_email
Created September 5, 2012 04:07
Simple email parser in ruby
#!/usr/bin/ruby
#Returns an email dictionary that includes all of an emails headers as well as each part of the email
#You can reference which part of the email you'd like by its content type
#Ex: email['parts']['text/html'] will get you the text/html version of the email body
#You can reference headers by the header name
#Ex: email['headers']['To'] will return the value of the "to" field
def headers_and_parts(file_path)
headers = {}
file = File.new(file_path, "r")
@mcrmfc
mcrmfc / ruby_vars.rb
Created April 29, 2012 22:09
variables in ruby
class A
@@class_var = 'aclassvar'
@class_instance_var = 'aclassinstancevar'
def initialize
@instance_var = 'ainstance_var'
end
def A.class_method
@kulesa
kulesa / gist:2507892
Created April 27, 2012 09:44 — forked from dhh/gist:2492118
nested routes for namespaces
class ActionDispatch::Routing::Mapper
def draw(routes_name)
instance_eval(File.read(Rails.root.join("config/routes", "#{@scope[:shallow_prefix]}", "#{routes_name}.rb")))
end
end
BCX::Application.routes.draw do
draw :projects # => config/routes/projects.rb
namespace :admin do
@Jared-Prime
Jared-Prime / gist:2423065
Created April 19, 2012 18:57
Converting RGB to HEX in Ruby
# Beginning Rubyists: simply run >> ruby hex-convertions.rb to see examples
# or use irb to build the code on the fly
# you can convert HEX to DEC using the method .to_i(base),
# which converts a string to a decimal number from the specified base number
puts "00".to_i(16)
puts "FF".to_i(16)
@mattsgarrison
mattsgarrison / Rakefile
Created April 9, 2012 13:57
Rake task to link up my Dotfiles repo.
require 'pathname'
require 'fileutils'
#This assumes this script is your home directory level Rakefile
namespace :dotfiles do
desc "Link ALL the dotfiles!"
task :link do
path = Pathname.new("#{__FILE__}").dirname
Dir.glob "#{path}/Dotfiles/*" do |f|
@holman
holman / gemspec-usage.md
Created February 12, 2012 07:02
test/spec/mini

Just install this in your apps like so:

gem 'test-spec-mini', :git => 'git://gist.github.com/1806986.git', :require => 'mini'

@hopsoft
hopsoft / resourceful.rb
Created November 30, 2011 21:23
Resourceful Rails actions for free with a Sinatra like DSL for action callbacks
module Resourceful
def self.actions
[:index, :show, :new, :edit, :create, :update, :destroy]
end
def self.callbacks
[:before, :after, :respond_to]
end