Skip to content

Instantly share code, notes, and snippets.

View awesome's full-sized avatar

So Awesome Man awesome

View GitHub Profile
@ChuckJHardySnippets
ChuckJHardySnippets / string_ext.rb
Created March 8, 2012 11:40 — forked from erskingardner/string_ext.rb
Ruby: Convert String to Boolean
class String
def to_bool
return true if self == true || self =~ (/(true|t|yes|y|1)$/i)
return false if self == false || self.blank? || self =~ (/(false|f|no|n|0)$/i)
raise ArgumentError.new("invalid value for Boolean: \"#{self}\"")
end
end
@citizen428
citizen428 / with.rb
Created March 21, 2012 12:30
ActionScript-like "with" for Ruby, result of SO discussion
module Kernel
def with(obj, &block)
obj.instance_eval &block
obj
end
end
@hjr3
hjr3 / e-commerce.md
Created April 3, 2012 05:35
Examples of RESTful API calls for E-commerce platforms

Examples of RESTful API calls for E-commerce platforms

These examples are type 3 RESTful API requests and responses. The JSON-HAL specification is used to implement HATEOAS.

Some of the examples are based on my work as architect of the RESTful API at http://www.hautelook.com. All proprietary information has been removed.

Relevant links

@futuremill-ltd
futuremill-ltd / gist:2318876
Created April 6, 2012 11:00
Building Ruby 1.9.3 package for Debian Squeeze
# From a fresh install of squeeze
apt-get install ruby rubygems # Need ruby to use fpm
gem1.8 install fpm --no-ri --no-rdoc
apt-get install build-essential openssl libreadline6 libreadline6-dev zlib1g zlib1g-dev libssl-dev ncurses-dev libyaml-dev
wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p125.tar.gz
tar -zxvf ruby-1.9.3-p125.tar.gz
cd ruby-1.9.3-p125
rm -rf /tmp/ruby193
@antonklava
antonklava / favicon-from-png.sh
Created April 11, 2012 08:18
Super simple script to create a favicon.ico from specified png
#!/bin/bash
#
# Super simple script to create a favicon.ico from specified png.
# Requires imagemagick ( http://www.imagemagick.org )
#
# Usage:
# ./favicon-from-png.sh myimage.png
# ls
# myimage.png favicon.ico
#
@xunker
xunker / gist:2481976
Created April 24, 2012 17:50
RVM Error with gemset
#!/usr/bin/env ruby
require 'rubygems'
require 'rvm'
require 'trollop'
opts = Trollop::options do
opt :ruby, "ruby interp to use", :type => :string, :required => true
opt :gem_name, "gem", :type => :string, :required => true
opt :gem_version, "gem", :type => :string, :required => true
end
@repeatedly
repeatedly / ruby_hash_literal_with_here_document.md
Created July 17, 2012 11:15
Why Ruby failed to parse a Hash literal with multiple here documents.

1 element

h = { 
  hoge: <<EOS
Hey!
EOS
}

p h
@hideo55
hideo55 / heredoc.rb
Created July 17, 2012 11:27
Ruby here document
h = {
hoge: <<EOS,
Hey!
EOS
fuga: <<EOS
Yo!
EOS
}
p h
@cupakromer
cupakromer / gist:3371003
Created August 16, 2012 15:23
each_with_object vs inject
my_array = %w[test one two three]
# Inject takes the value of the block and passes it along
# This often causes un-intended errors
my_array.inject({}) do |transformed, word|
puts transformed
transformed[word] = word.capitalize
end
# Output:
# {}
@yurikoval
yurikoval / gist:3663539
Created September 7, 2012 05:47
Passing arguments to an around_filter
# app/controller/articles_controller.rb
around_filter { |controller, action| controller.send(:add_published_scope, Article){ action.call } }
# app/controller/application_controller.rb
def add_published_scope(klass = nil, &block)
unless klass
klass = controller_name.classify.constantize
end
klass.with_scope(:find => klass.where("published_at <= ?", Time.zone.now)) do
yield