Skip to content

Instantly share code, notes, and snippets.

@glucero
glucero / gist:1847165
Created February 16, 2012 19:29
Hash#to_class
class Hash
def to_class(name, namespace='Object')
hash = self
namespace = Kernel.const_get namespace.capitalize
name = name.capitalize
namespace.const_get(name).new hash
rescue Exception => err
namespace.const_set(name, Class.new do
attr_accessor *hash.keys
def valid?() true end
@glucero
glucero / gist:3076469
Created July 9, 2012 13:10
Convert integers to english words.
; Convert numbers to english words.
(defn
single
[n]
(nth
'(one two three four five six seven eight nine)
// SomethingAwful Emote Support (http://sae.tweek.us/)
var mapping = {};
var loadEmotes = function(response) {
response.forEach(function(a){a.emoticons.forEach(function(b){mapping[b.code] = b.image})});
window.chat.speaker.filters.unshift(
function(m){
var match;
if(match=m.match(/^:(.*):$/)){
@glucero
glucero / example_1.rb
Created August 12, 2012 03:15
examples for rika
class Person
def speak
puts "My name is #{@name}. I am a #{@occupation}."
end
def occupation(occupation)
@occupation = occupation
end
var array, item, _i, _len;
array = [];
for (_i = 0, _len = items.length; _i < _len; _i++) {
item = items[_i];
doAsyncRequest(item, function(result) {
array << result;
if ((_i + 1) === _len) {
return callback(array);
@glucero
glucero / gist:3899772
Created October 16, 2012 14:53
Starting with this array, how many different ways can you create two arrays of every other element
# Starting with this array, how many different ways can you create two arrays of every other element
array = %w(key_a value_a key_b value_b key_c value_c)
# 1
hash = Hash[*array]
hash.keys
hash.values
# 2
Hash[*array].to_a.transpose
@glucero
glucero / gosper_glider_gun.life
Created November 3, 2012 04:06
gosper glider gun
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
@glucero
glucero / pixel.rb
Created November 26, 2012 03:45
An OpenGLES 'LCD dot-matrix' style pixel
class Pixel
attr_reader :pointer
Minimum = 0.00
Maximum = 1.00
Margin = 0.15
Vertices = [
# 4-point triangle fan
@glucero
glucero / pythagoras-tree
Created December 21, 2012 05:48
pythagoras tree example for Lectronimo
make angle divide [ arcsine divide [ 3 5 ] degree ]
command square [ size ] [
repeat 4 [ forward size left 90 ]
]
command subdivide [ ratio size ] [
multiply [ ratio divide [ size 5 ] ]
]
@ECHO OFF
SET SIZELIMIT=%2
SET FILESIZE=%~z1
SET FILEPATH=%~f1
SET DKEY="OS|Windows|FileSize|%~nx1"
IF %FILESIZE% GTR %SIZELIMIT% (
ECHO %DKEY% %FILESIZE% 2 "%FILEPATH% is greater than %SIZELIMIT%"
) ELSE (