Skip to content

Instantly share code, notes, and snippets.

Array.class_eval do
def count
h = {}
self.each do |i|
if h.keys.include? i
h[i] += 1
else
h[i] = 1
end
end
require 'set'
class DallasDB
attr_reader :filename, :structs
def initialize filename, password=""
@filename = filename.split(".")
@filename = "#{@filename[0]}.db"
if Dir.entries('.').detect {|f| f.match "#{@filename}"}
@db_file = File.open(@filename, "r").each_line do |l|
if l.chomp == password.crypt("DallasDB")
load_structs
@solomon081
solomon081 / det_index.rb
Created May 22, 2012 11:54
detect_index
Array.class_eval do
def detect_index &block
det = self.detect &block
return self.index(det)
end
end
class Square
attr_reader :area, :perimiter, :diagonal
def initialize(side)
@side = side
@area = side ** 2
@perimiter = side * 4
@diagonal = Math.sqrt(side ** 2 + side ** 2)
end
$.getScript("http://dean.edwards.name/base/Base.js");
var CustomRandom = Base.extend({
constructor: function(num) {
this.argNum = num
this.num = Math.random() * num;
},
succ: function() {
this.num += 1;
},
randSucc: function() {
class FloatRange:
def __init__(self, start, stop, step=1):
self.start = start
self.stop = stop
self.step = step
def __str__(self):
return "Range: {0}-{1}".format(self.start, self.stop)
def num_list(self):
num_list = []
current_num = self.start
@solomon081
solomon081 / read_zip.py
Created May 16, 2012 16:04
Read Zip File
import zipfile
import time
zipath = input("Enter the path to the zipfile: ")
fileinzip = input("Enter the file in the zipfile to read: ")
time.sleep(2)
z = zipfile.ZipFile(zipath)
return z.read(fileinzip)
function makeArray() {
var arr = []
for (x=0; x < arguments.length; x++) {
arr.push(arguments[x])
}
return arr
}
@solomon081
solomon081 / examples.rb
Created May 13, 2012 02:11
KeyDB Examples
>>> require 'keydb'
>>> x = KeyDB.new("foo.db")
>>> x.new_key "ruby", "rocks"
>>> x.get_key "ruby"
=> 'rocks'
>>> x.new_key "go", "ruby"
>>> x.get_key "go"
=> 'ruby'
>>> x.new_key "ruby", "is bad"
=> Error! Keynames must be unique.
module KeyDB
class DB
# Makes filename and version into attributes
attr_reader :filename, :version
# Global version variable
$KEYDB_VERSION = "5.0.0"
def initialize filename
# Makes sure the filename ends in .db
@filename = filename.split(".")