Skip to content

Instantly share code, notes, and snippets.

export PATH="/Users/chaos/.rvm/gems/ruby-1.9.2-p180@global/bin:/bin:/bin:/Users/chaos/.rvm/bin:$PATH"
rvm_path='/Users/chaos/.rvm' ; export rvm_path
RUBY_VERSION='ruby-1.9.2-p180' ; export RUBY_VERSION
GEM_HOME='/Users/chaos/.rvm/gems/ruby-1.9.2-p180@global' ; export GEM_HOME
GEM_PATH='/Users/chaos/.rvm/gems/ruby-1.9.2-p180@global:' ; export GEM_PATH
unset MY_RUBY_HOME
unset IRBRC
rvm_ruby_string='ruby-1.9.2-p180' ; export rvm_ruby_string
unset rvm_gemset_name
unset MAGLEV_HOME
irb(main):001:0> hsh = { :a => "A", :b => "B" }
=> {:a=>"A", :b=>"B"}
irb(main):002:0> a_key = "a"
=> "a"
irb(main):003:0> a_val = "a"
=> "a"
irb(main):004:0> key = "#{a_val}.to_sym"
=> "a.to_sym"
irb(main):005:0> hsh[key]
=> nil
class Message
class << self
def some_meth; "Hello from Message"; end
end
end
class Version < Message
class << self
def some_meth; "Hello from Version"; end
@iande
iande / module_maker.rb
Created October 23, 2011 18:33
Module Maker
module SomeAPI
def self.get_var mod, meth
vars_for(mod)[meth]
end
def self.set_var mod, meth, val
vars_for(mod)[meth] = val
end
def self.vars_for mod
@iande
iande / gist:1326593
Created October 30, 2011 23:36
XOR to NAND
A XOR B
(A * ~B) + (~A * B)
F + (A * ~B) + (~A * B) + F
(A * ~A) + (A * ~B) + (~A * B) + (B * ~B)
(A * (~A + ~B)) + ((~A + ~B) * B)
@iande
iande / gist:1779895
Created February 9, 2012 13:18
Wrapping class singleton (eigen) methods with a module
# Note: MyFinalApproach defines a block that takes a block,
# which only works with Ruby >= 1.9. To work with 1.8, you'll need
# to take that bit out.
# Also, I think 'eigen' contains more phonetic badassery than
# 'singleton', which is the real reason I prefer it.
require 'forwardable'
class SomeClass
def self.my_eigen_method; 42; end
@iande
iande / jcart-mods.js
Created March 10, 2012 23:42
jcart modification
// Line 174 of jcart v1.3
// Add an item to the cart
$('.jcart').submit(function(e) {
add($(this));
e.preventDefault();
});
// Try replacing or adding:
@iande
iande / pinkhair.rb
Created March 15, 2012 19:12
quick test of ircbgb
#!env ruby
require 'bundler'
Bundler.setup
require 'ircbgb'
bot = Ircbgb::Client.new do |c|
c.servers = 'irc://pinkhair.gudefrends.net'
c.nicks = ['iande', 'ian-2', 'ian-3']
@iande
iande / Rectangle.java
Created April 10, 2012 13:45
Rectangle Example
public class Rectangle {
public static int COUNTER = 0;
public int width;
public int height;
private int myX;
private int myY;
public Rectangle(int x, int y, int w, int h) {
// Position and dimensions were given, so we construct a rectangle at (x,y)
@iande
iande / Main.java
Created April 17, 2012 14:36
When there is no explicit constructor...
public static void main() {
// Java provides a "default" no-argument constructor for us.
MyCoolShit coolShit = new MyCoolShit();
// But, NEVER rely on it!
System.out.println("Bool: " + coolShit.aBool);
System.out.println("Int: " + coolShit.anInt);
System.out.println("Double: " + coolShit.aDouble);
System.out.println("Char: " + coolShit.aChar);
System.out.println("String: " + coolShit.aString);