Skip to content

Instantly share code, notes, and snippets.

stdin, stdout, stderr, pid = Open4::popen4 "pgp --key-list"
pgps = stderr.select {|x| x.chomp if x =~ /0x/ }
# to parse Key list
@orgs = pgps.inject([]){|enum, pgp| enum << {:hex_id =>pgp[29..38], :org_id => pgp[40..pgp.length].chomp} }
@orgs.each.with_index{ |org, index| puts "#{index}. #{org[:hex_id]} belongs to #{org[:org_id]}" }
@octosteve
octosteve / embedded_images.rb
Created July 13, 2011 21:04
Embedding Images in Outlook Messages With Ruby
require 'win32ole'
email = "someone@anyplace.net"
image1 = "/home/user/images/image1.jpg"
image2 = "/home/user/images/image2.jpg"
outlook = WIN32OLE.new('Outlook.Application')
message = outlook.CreateItem(0)
message.To = email
message.Subject = "My Subject"
message.attachments.add(image1)
@octosteve
octosteve / FizzBuzz.rb
Created November 22, 2011 05:13
FizzBuzz
1.upto(100) do |num|
if num % 3 == 0 || num % 5 == 0
if num % 3 == 0
print "Fizz"
end
if num % 5 == 0
print "Buzz"
end
else
print num
@octosteve
octosteve / FizzBuzzer.java
Created November 23, 2011 01:51
Another FizzBuzz This time in Java
public class FizzBuzzer {
public static void main(String[] args) {
for(int num=1; num<=100; num++){
if (num % 3 == 0 || num % 5 == 0){
if (num % 3 == 0)
System.out.print("Fizz");
if (num % 5 == 0)
System.out.print("Buzz");
}
else
@octosteve
octosteve / hash_bash.rb
Created June 18, 2012 00:20
My version of today's excercise (Hashes)
songs = [
"The Magnetic Fields - 69 Love Songs - Parades Go By",
"The Magnetic Fields - Get Lost - Smoke and Mirrors",
"The Magnetic Fields - Get Lost - You, Me, and the Moon",
"The Magnetic Fields - 69 Love Songs - The Book of Love",
"Neutral Milk Hotel - In An Aeroplane Over the Sea - Holland 1945",
"Neutral Milk Hotel - In An Aeroplane Over the Sea - The King of Carrot Flowers"
]
music = Hash.new {|k,v| k[v] = (Hash.new {|k,v| k[v] = []})}
class Artist
attr_accessor :name, :songs, :genres
@@artists = []
def initialize
@@artists << self
@songs = []
@genres = []
end
class Artist
attr_accessor :name, :songs, :genres
@@artists = []
def initialize
@@artists << self
@songs = []
@genres = []
end
@octosteve
octosteve / songs.rb
Created July 11, 2012 23:53
Silly Rubyness
# 5 songs of the following lengths in seconds
class Song
attr_accessor :duration
def initialize(duration=0)
@duration = duration
end
end
@octosteve
octosteve / magic.rb
Created August 20, 2012 02:17
Evil things with ruby
# I wanted to create a class with lowercase name
my_class = Class.new(Object) do
attr_accessor :why_do_i_work
def initialize
puts "WTF"
end
end
@octosteve
octosteve / conventional_class_reopening.rb
Created October 29, 2012 17:27
Conventional way to add methods to a class
class Cart
def confirm
"Your order is being processed"
end
end
cart = Cart.new
# then reopen the class
class Cart