Skip to content

Instantly share code, notes, and snippets.

View JohnathanWeisner's full-sized avatar

Johnathan Weisner JohnathanWeisner

View GitHub Profile
import { comments } from "./mock-response.json";
const mockResponse = (response) => {
return new Promise((resolve) => {
setTimeout(() => {
resolve({
success: 200,
json: () =>
new Promise((resolve) => {
return resolve(response);
@JohnathanWeisner
JohnathanWeisner / boardSearch.js
Created September 7, 2017 02:23
A script to search for all dictionary words on a stupid facebook post.
const fs = require('fs');
let words = fs.readFileSync('/usr/share/dict/words', 'utf8')
.split('\n');
let board = [
'moronqisioteqwo',
'gdouchebagopzay',
'frnvfkttdnjddsk',
'eawtcolcaeoksru',
'lsiiwamchnwurcg',
'isddraecyipdjoa',
@JohnathanWeisner
JohnathanWeisner / SudokuSolver.js
Last active February 21, 2019 04:36
OO Javascript Sudoku Solver solving the hardest puzzles.
class SudokuSolver {
constructor(board) {
this.board = board;
}
solve() {
const index = this.board.indexOf('0');
if (index === -1) return this.board;
for (let possibility = 1; possibility < 10; possibility++) {
require 'date'
def random_date_between(args)
start, finish = args[:start], args[:finish]
start, finish = [start, finish].map do |datetime|
case
when datetime.is_a?(DateTime) then datetime.to_time.to_i
when datetime.is_a?(Date) then DateTime.parse(datetime.to_s).to_time.to_i
when datetime.is_a?(String) then DateTime.parse(datetime).to_time.to_i
else
@JohnathanWeisner
JohnathanWeisner / karatsuba_vs_third_grade.rb
Created October 15, 2014 09:14
A test to compare the run-times of the Karatsuba Multiplication Algorithm and the Third Grade Multiplication Algorithm
def karatsuba x, y
return x * y if (x < 10) || (y < 10)
n = [x.to_s.size, y.to_s.size].max
n2 = n/2
a, b = x.divmod(10**n2)
c, d = y.divmod(10**n2)
step_1 = karatsuba(a,c)
step_2 = karatsuba(b,d)
@JohnathanWeisner
JohnathanWeisner / sudoku.rb
Last active August 29, 2015 14:07
Shortest Ruby Sudoku Solver
# From
#
# $*.map{|a|(i=a=~/0/)?(v=*?1..?9).fill{|j|v-=[a[j+i-k=i%9],a[
# k+j*=9],a[j%26+i-i%3-i%27+k]]}+v.map{|k|$*<<$`+k+$'}:p(a)}
#
#
# To
start = Time.now
counter = 1
@JohnathanWeisner
JohnathanWeisner / merge_sort.rb
Last active August 29, 2015 14:07
Ruby Merge Sort
def merge_sort(ary)
size = ary.size
return ary if size <= 1
mid = size/2
left, right = ary[0..mid-1], ary[mid..-1]
left, right = merge_sort(left), merge_sort(right)
merge(left, right)
@JohnathanWeisner
JohnathanWeisner / karatsuba.rb
Last active August 29, 2015 14:07
karatsuba multiplication
def karatsuba(x, y)
return x * y if (x < 10) || (y < 10)
n = [x.to_s.size, y.to_s.size].max
n2 = n/2
a, b = x.divmod(10**n2)
c, d = y.divmod(10**n2)
step_1 = karatsuba(a,c)
step_2 = karatsuba(b,d)

All of the commands that start with '$' should be done in the terminal with out the '$' part.

As an example when you see:

$rails c

You should type

rails c
# From
#
# $*.map{|a|(i=a=~/0/)?(v=*?1..?9).fill{|j|v-=[a[j+i-k=i%9],a[
# k+j*=9],a[j%26+i-i%3-i%27+k]]}+v.map{|k|$*.<<$`<<k<<$'}:p(a)}
#
#
# To
start = Time.now
ARGV.map do |board|