Skip to content

Instantly share code, notes, and snippets.

View kalmanh's full-sized avatar

Kalman Hazins kalmanh

  • T. Rowe Price
  • Baltimore, MD
View GitHub Profile
class DynamicallyDefineAndCall
def method_missing(method, *args)
puts method
self.class.send(:define_method, method) do
puts 'take it easy now'
end
send method
end
@kalmanh
kalmanh / allScrape.js
Last active December 3, 2017 05:54 — forked from bmorelli25/allScrape.js
Scrape all books on the homepage - without a for loop
const puppeteer = require('puppeteer');
let scrape = async () => {
const browser = await puppeteer.launch({headless: true});
const page = await browser.newPage();
await page.goto('http://books.toscrape.com/');
const result = await page.evaluate(() => {
let elements = document.querySelectorAll('.product_pod'); // Select all Products
@kalmanh
kalmanh / car.rb
Created July 30, 2017 04:23
Example of inclusion validation
class Car < ActiveRecord::Base
validates :color, inclusion: { in: [ "green", "red", "None" ] }
end
@kalmanh
kalmanh / gist:7a9880b5fefa2b9b2cef
Created May 22, 2014 14:01
Using symbols as keys in hash vs. strings
require 'benchmark'
NUM_TIMES = 100000000
ARR = (5000..10000).to_a
hash1 = {}
strings = %w{"Lorem ipsum bla abra kadabra"}
strings.each do |str|
hash1[str] = ARR.sample
end
@kalmanh
kalmanh / converter_script.rb
Last active October 24, 2016 19:34
Ruby script to convert .mdb db file into .csv
# Export data from Microsoft Access .mdb database into .csv files
# using https://github.com/brianb/mdbtools
# Install with homebrew - "brew install mdbtools"
class ConverterScript
tables = `mdb-tables -d , your_db_name.mdb`.chop.split(",")
tables.each do |table|
exists = system("mdb-export your_db_name.mdb '#{table}'")
`mdb-export your_db_name.mdb '#{table}' > #{table.gsub(" ", "_")}.csv` if exists
@kalmanh
kalmanh / rand_benchmarker.rb
Created July 19, 2013 05:59
Shows how much slower Random.new.rand() is vs. Kernel's rand()
require 'benchmark'
NUM_TIMES = 10000
Benchmark.bmbm do |x|
x.report("Random.new") do
NUM_TIMES.times do
Random.new.rand(2.0...4.0)
end
end
@kalmanh
kalmanh / fibonacci_test.rb
Created April 25, 2013 22:33
Comparing Fibonacci memoization using class variable vs. class instance variable
require 'benchmark'
class Fibonacci_Class_Data_Variable
@@memo = { 0 => 0, 1 => 1 }
def self.fib_rec(n)
@@memo[n] ||= fib_rec(n - 1) + fib_rec(n - 2)
end
end
// fdgfdgfd
public static void main() {
for(int i = 0; i < 3; i++) {
}
}