This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Array.class_eval do | |
def detect_index &block | |
det = self.detect &block | |
return self.index(det) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.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() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function makeArray() { | |
var arr = [] | |
for (x=0; x < arguments.length; x++) { | |
arr.push(arguments[x]) | |
} | |
return arr | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(".") |