Skip to content

Instantly share code, notes, and snippets.

View Jirapong's full-sized avatar

Jirapong Nanta Jirapong

View GitHub Profile
# For the queasy, this is MIT licensed. See comment at the end.
module MySQLEncryption
# Mimics MySQL's AES_ENCRYPT() and AES_DECRYPT() encryption functions
def mysql_encrypt(s, key)
encrypt(s, mysql_key(key))
end
def mysql_decrypt(s, key)
# for this example the folder structure should be as follow
#
# --+ mailer
# |-- image.jpg
# |-- mailer.rb (this file)
# |--+ notifier
# |-- email.rhtml
require 'rubygems'
require 'action_mailer'
require 'rubygems'
require 'builder'
require 'PresentationCore'
require 'PresentationFramework'
require 'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeytoken=b77a5c561934e089'
module XamlTools
include System::Windows
StringReader = System::IO::StringReader;
XamlReader = System::Windows::Markup::XamlReader
require 'xamltools.rb'
class MyCommand
include System::Windows::Input::ICommand
def add_CanExecuteChanged(h)
@change_handlers << h
end
def remove_CanExecuteChanged(h)
@change_handlers.remove(h)
end
myip = (require 'open-uri'; open("http://www.whatismyip.org/").read)
@Jirapong
Jirapong / sample.rb
Created May 4, 2009 10:59
dynamic add control on-the-fly
require 'winforms'
form = create_form :text => "Hello", :top_most => true
btn = create :text => "Click Me"
txt = create :text => "(Your name)"
layout form, [btn, txt], :top => 100, :spacing => 20
btn.click do |sener, args|
describe "Widget#foo" do
it "does something" do
# This should be the functionality specs specific to the semantics of the method
Widget.new.foo.should == "do something"
end
end
# This captures the "type signature" of the method. Here are recipes for corner cases that you might forget.
# Note that the examples are not self-consistent by design. Only some of them might apply to any given method.
# However, the goal below is to include the union of all possible examples so that you can cut and paste
require 'time'
t = Time.now
puts "UTC #{t.utc}" # fail in IronRuby
puts "RFC2822: #{t.rfc822}" # fail in IronRuby
puts "UTC then RFC2822: #{t.utc.rfc822}" #fail in IronRuby
#!/usr/bin/env ruby
require 'openssl'
require 'base64'
private_key_file = 'private.pem';
password = 'boost facile'
encrypted_string = %Q{
qBF3gjF8iKhDh+g+TOvAzBkJA/1d2lD8RUyz2Ol+s1OpLB5aA3RA7EHm0KGL
IronRuby 0.4 0.4.0.0 on .NET 2.0.0.0
OpenSSL::Cipher's CipherError
- exists under OpenSSL namespace (FAILED - 1)
OpenSSL::HMAC.digest
- returns an SHA1 digest
OpenSSL::HMAC.hexdigest
- returns an SHA1 hex digest