Skip to content

Instantly share code, notes, and snippets.

View kotp's full-sized avatar
enjoying life

Victor Goff kotp

enjoying life
View GitHub Profile
@kotp
kotp / dsh.rb
Created July 1, 2010 03:40 — forked from anatman/dsh.rb
def dsh(un, va)
(va.size - 1).downto(1) {|j| va[j] = va[0 .. j].inject(1) { |pr, it| pr * it } }
ar = un.zip va
hs = {}
ar.each {|i| hs[i[0]] = i[1] }
hs
end
@chischaschos
chischaschos / class1.rb
Created November 16, 2010 19:16
Metaprogramming basics post code
class A
end
puts "--" + A.instance_methods(false).join(', ')
class A
def otro
end
end
@RyanScottLewis
RyanScottLewis / rulebook_rewrite.rb
Created December 21, 2010 20:02
Rewrite of my RuleBook gem
module RuleBook
def RuleBook.add_rules(object, instance_or_class, rules)
instance_or_class = instance_or_class.to_s.downcase.strip.to_sym
raise(ArgumentError, "'instance_or_class' must equal :instance or :class") unless [:instance, :class].include?(instance_or_class)
raise(ArgumentError, "'rules' must be a Hash") unless rules.is_a?(Hash)
unless object.instance_variable_get(:@_rulebook_initiated) # Class instance variable. Not class variable. Not instance variable. Is confusing.
object.instance_variable_set(:@_rulebook_initiated, true)
object.instance_variable_set(:@_rulebook, {:instance=>{}, :class=>{}}) # @_rulebook is actually two rulebooks, instance and class
end
@igrigorik
igrigorik / ruby-1.9-tips.rb
Created February 3, 2011 17:19
Ruby 1.9 features, tips & tricks you may not know about...
def tip(msg); puts; puts msg; puts "-"*100; end
#
# 30 Ruby 1.9 Tips, Tricks & Features:
# http://www.igvita.com/2011/02/03/new-ruby-19-features-tips-tricks/
#
tip "Upgrading to Ruby 1.9 is simple: rvm install 1.9.2 && rvm --default 1.9.2"
tip "Ruby 1.9 supports named captures in regular expressions!"
#!/usr/bin/env ruby
#
# A quick script to dump an overview of all the open issues in all my github projects
#
require 'octokit'
require 'awesome_print'
require 'rainbow'
@parndt
parndt / my-gh-issues.rb
Created May 8, 2011 03:35 — forked from copiousfreetime/my-gh-issues.rb
My Github Issues
#!/usr/bin/env ruby
#
# A quick script to dump an overview of all the open issues in all my github projects
#
require 'octokit'
require 'awesome_print'
require 'rainbow'
@danhigham
danhigham / rubyconfvids.rb
Created May 22, 2011 08:03
Script to download all Scotland Ruby 2011 videos
#!/usr/bin/ruby
require 'rubygems'
require 'open-uri'
require 'hpricot'
dependencies = [:wget, :curl]
dependencies.each { |program| !`which #{program.to_s}`.empty? || STDERR.puts( "Requires #{program}") }
index_doc = Hpricot(open("http://confreaks.net/events/scotlandruby2011"))
@RyanScottLewis
RyanScottLewis / proj.gemspec
Created May 29, 2011 06:48
The self-generating, completely amazing, edit and forget it... gemspec!
#!/bin/ruby
Gem::Specification.new do |s|
s.author = "John Doe"
s.email = "j.doe@email.com"
s.description = "helps out with writing your project."
s.summary = "A library helps your project!"
s.require_paths = ["lib"]
@mjackson
mjackson / blocks.rb
Created August 11, 2011 18:30
Demonstrates the difference between Ruby's two different block styles.
def a(*args, &block)
puts "a got a block" if block_given?
end
def b(*args, &block)
puts "b got a block" if block_given?
end
# In this call, `b' is called with the block and the
# return value is given to `a' as an argument.
@IndianGuru
IndianGuru / jruby01.rb
Created August 28, 2011 00:56
JRuby programs
# First get the current local time
t = Time.now
# to get day, month and year with century
# also hour, minute and second
puts t.strftime("%d/%m/%Y %H:%M:%S")
# You can use the upper case A and B to get the full
# name of the weekday and month, respectively
puts t.strftime("%A")
puts t.strftime("%B")