Skip to content

Instantly share code, notes, and snippets.

View JohnathanWeisner's full-sized avatar

Johnathan Weisner JohnathanWeisner

View GitHub Profile
@JohnathanWeisner
JohnathanWeisner / jquery_example.html
Last active August 29, 2015 13:57 — forked from dbc-challenges/jquery_example.html
Intro to jQuery for Phase 0
<!DOCTYPE html>
<html>
<head>
<title>DOM manipulation with jQuery</title>
<!-- Add a link to jQuery CDN here script here -->
<script type="text/javascript" src="jquery_example.js"></script>
</head>
<body>
require 'snoo'
require 'json'
config = {
export_file_name: 'comments_for_ginger',
subreddit: 'askreddit'
}
class RedditParser
attr_accessor :subreddit
#left-column {
height: 600px;
width: 48%;
float: left;
margin: 16px 1% 0 2%;
background-color: blue;
}
#center-nav, #right-column {
height: 600px;
@JohnathanWeisner
JohnathanWeisner / peter-norvig_11-hardest-puzzles.txt
Last active August 29, 2015 14:04
Simple Sudoku Solver with backtracking
850002400720000009004000000000107002305000900040000000000080070017000000000036040
005300000800000020070010500400005300010070006003200080060500009004000030000009700
120040000005069010009000500000000070700052090030000002090600050400900801003000904
000570030100000020700023400000080004007004000490000605042000300000700900001800000
700152300000000920000300000100004708000000060000000000009000506040907000800006010
100007090030020008009600500005300900010080002600004000300000010040000007007000300
100034080000800500004060021018000000300102006000000810520070900006009000090640002
000920000006803000190070006230040100001000700008030029700080091000507200000064000
060504030100090008000000000900050006040602070700040005000000000400080001050203040
700000400020070080003008079900500300060020090001097006000300900030040060009001035
require 'artoo'
connection :arduino, adaptor: :firmata, port: '/dev/cu.usbmodem1421' # linux
device :board, :driver => :device_info
device :serv, :driver => :servo, :pin => 5 # pin must be a PWM pin
work do
puts "Firmware name: #{board.firmware_name}"
puts "Firmata version: #{board.version}"
# 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|

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
@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)
@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 / 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