Skip to content

Instantly share code, notes, and snippets.

View JRJurman's full-sized avatar

Jesse Jurman JRJurman

View GitHub Profile
@JRJurman
JRJurman / Meta_m
Last active December 12, 2015 02:38
def m
def m
puts "bar"
end
puts "foo"
end
m #=> prints "foo\n"
m #=> prints "bar\n"
@JRJurman
JRJurman / Meta_Buffer.rb
Last active December 12, 2015 03:18
META PROGRAMMING!
class Meta_Buffer
def save
puts "no modifications"
end
def read
""
end
#birthday.rb
birthdays_taken = []
doubles = false
while( !doubles ) do
if birthdays_taken.include?(y=rand(365))
doubles = true
end
birthdays_taken << y
end
require 'console_splash'
splsh = ConsoleSplash.new()
colorSchemes = [{:bg=>:black}, {:bg=>:white}]
(0..splsh.lines-1).each do |line|
(0..splsh.columns-1).each do |column|
splsh.write_pixel(line, column, ' ', colorSchemes[0])
colorSchemes.reverse!
end
colorSchemes.reverse!
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@JRJurman
JRJurman / Mult.rb
Created May 12, 2013 21:18
Multiplication without multiplier operator
def mult(a, b)
(a.to_s(b)+"0").to_i(b)
end
public class Herp {
Herp cur;
public Herp() {
cur = this;
}
/* Doesn't work... :(
public void test() {
System.out.println(this.this.this);
@JRJurman
JRJurman / blankslate.rb
Last active December 17, 2015 19:19
BlankSlate class which has only the reserved and protected methods based on the builder example: https://github.com/jimweirich/builder/blob/master/lib/blankslate.rb
class BlankSlate
# BlankSlate provides a class with only the bare-bones recommended methods
# without, you know, breaking ruby really really bad...
# go through every method
instance_methods.each do |func|
# if it's a reserved method, don't remove it << these methods actually
# prompt a warning if you try to remove them!
if !func.match(/^(__|instance_eval|object_id)/)
@JRJurman
JRJurman / Greeter.rb
Created September 1, 2013 05:07
Greeter, the CORRECT WAY!
print "Enter Name: "
name = gets.chomp
Greeter = Class.new do
puts "Hold up a second #{name}, Greeter is starting up..."
define_method :greet do
puts "#{['hey', 'hello', 'howdy', 'yo'].shuffle[0]} #{name}"
end
end
@JRJurman
JRJurman / OddOrEven.js
Last active December 23, 2015 07:19
Someone asked how to get an odd or even value...
var cap = -Math.log(0);
var ultimateSwitchCase = "switch(x.toString())\n{";
for( var i=0; i < cap; i++ ) {
ultimateSwitchCase += "\tcase "+i+":\n\t\treturn \""+['even','odd'][i%2]+"\";\n";
}
ultimateSwitchCase += "}";
eval(ultimateSwitchCase);