Skip to content

Instantly share code, notes, and snippets.

class Song < ActiveRecord::Base
composed_of :songinfo, :class_name => "SongInfo", :mapping => [%w(title, title)]
end
class ActiveRecord::Base
def keys
arr = []
self.each do |x, y|
arr.push x
end
return arr
end
end
import getopt
import sys
version = "1.0"
verbose = False
output = "default.out"
try:
options, remainder = getopt.getopt(sys.argv[1:], "o:v", ["output=", "verbose=", "version="])
except Exception as err:
print(err)
sys.exit(1)
@solomon081
solomon081 / doubleeach.rb
Created June 10, 2012 15:12
double_each
class Array
def double_each other, &block
self.each_with_index do |item, index|
yield [item, other[index]]
end
end
end
class GID
# Filters out naughty words
def self.filter! str
words = ["fuck", "shit", "bitch", "cunt", "fag", "douche", "ass", "a55", "b1tch", "f4g", "5h1t"]
substitutes = ["faxf", "spwo", "bawpr", "capf", "fpa", "dclax", "aic", "a21", "b5sea", "f8m", "1z8l"]
words.each do |x|
str.gsub!(x, substitutes[words.index(x)])
end
return str
end
class String
def strpush! push
newstring = push + self
self.replace(newstring)
end
end
class HTMLDocument
private
def refresh_full
@full_doc = @open_doc + @close_doc
@solomon081
solomon081 / sc.html
Created June 2, 2012 17:20
Sin Calculator
<html>
<head>
<script type="text/javascript">
window.onload = function() {
document.getElementsByTagName("form")[0].onsubmit = function() {
document.getElementsByTagName("body")[0].style.color = "Red";
document.getElementsByTagName("input")[1].value = "Calculating...";
var inputted = Number(document.getElementsByTagName("input")[0].value);
inputted /= 57.295779501;
alert(Math.sin(inputted));
Array.class_eval do
def unpack index
temp = self
self[index].map {|item| temp.push item}
temp.delete(self[index])
return temp
end
end
class Proc:
def __init__(self, code):
self.code = code
def call(self):
exec(self.code)
def count(arr):
d = {}
for x in arr:
if x in d.keys():
d[x] += 1
else:
d[x] = 1
return d