This file contains hidden or 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 DynamicallyDefineAndCall | |
def method_missing(method, *args) | |
puts method | |
self.class.send(:define_method, method) do | |
puts 'take it easy now' | |
end | |
send method | |
end |
This file contains hidden or 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
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 |
This file contains hidden or 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 Car < ActiveRecord::Base | |
validates :color, inclusion: { in: [ "green", "red", "None" ] } | |
end |
This file contains hidden or 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 '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 |
This file contains hidden or 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
# 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 |
This file contains hidden or 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 '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 |
This file contains hidden or 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 '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 |
This file contains hidden or 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
// fdgfdgfd | |
public static void main() { | |
for(int i = 0; i < 3; i++) { | |
} | |
} |