Skip to content

Instantly share code, notes, and snippets.

View sukhchander's full-sized avatar
💭
console.log('Solutions' ? '' ? 'Architect' ? '@aws' : '' : '🚀☁️' : '🍺🍜')

sukhchander sukhchander

💭
console.log('Solutions' ? '' ? 'Architect' ? '@aws' : '' : '🚀☁️' : '🍺🍜')
View GitHub Profile
@sukhchander
sukhchander / twitter_search.rb
Created May 11, 2011 16:46
search twitter for the latest keyword / hashtag
# encoding: UTF-8
require 'rubygems'
require 'set'
require 'uri'
require 'yajl'
require 'yajl/http_stream'
#####################################
# TwitterFeed
# represents the twitter feed / stream
class Player
def play_turn(warrior)
# cool code goes here
warrior.walk!
end
end
class Player
def play_turn(warrior)
# cool code goes here
@sukhchander
sukhchander / problem67.rb
Created March 26, 2014 04:16
project euler problem 67
require 'debugger'
require 'awesome_print'
# project euler problem 67 depends on problem 18
# maximum path sum
# use a bottom up strategy
# split into subproblems
# store subproblem result
# don't recompute subproblem
@sukhchander
sukhchander / cross_river.rb
Created April 2, 2014 03:00
can cross river?
river = “************~~~”
river1 = “****~~~~”
river2 = “****************~~*~~~*”
# NOTES:
#
# acc. by 1
# stay the same speed
def multiples(max)
(1...max).select {|i| i % 3 == 0 || i % 5 == 0 }.reduce(:+)
end
puts multiples(1000)
@sukhchander
sukhchander / collapse.rb
Created June 18, 2014 14:41
collapse entries
input = [
{ time: 201_201, x: 2 },
{ time: 201_201, y: 7 },
{ time: 201_201, z: 2 },
{ time: 201_202, a: 3 },
{ time: 201_202, b: 4 },
{ time: 201_202, c: 0 }
]
output = [
@sukhchander
sukhchander / install-go.sh
Last active August 29, 2015 14:07
install-go.sh
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin
brew update
brew install go
brew install git
brew install mercurial
mkdir $HOME/go
mkdir -p $GOPATH/src/github.com/user
SSID BSSID RSSI CHANNEL HT CC SECURITY (auth/unicast/group)
DIRECT-roku-138 b0:a7:37:0b:17:2b -45 11 Y US WPA2(PSK/AES/AES)
DIRECT-roku-696 b0:a7:37:0e:3c:c3 -48 11 Y US WPA2(PSK/AES/AES)
VCHO0 00:26:b8:11:6d:e4 -70 6 Y US WEP
SBG65803E 20:10:7a:7f:59:55 -81 1 Y -- WPA(PSK/AES/AES) WPA2(PSK/AES/AES)
@sukhchander
sukhchander / max_sum_path.rb
Created December 31, 2015 17:22
max sum path
#!/usr/bin/env ruby
def max_path_sum(file)
input = File.open(file).readlines
numbers = input.collect { |line| line.split(" ").map(&:to_i) }
# started from the bottom
triangle_size = numbers.size - 2
@sukhchander
sukhchander / flatflat.rb
Last active April 19, 2016 21:02
flatten an array of arbitrarily nested arrays of integers into a flat array of integers
class Array
def flatflat
result = []
self.each do |elem|
if elem.is_a?(Array)
result.concat(elem.flatflat)
else
result.push(elem)
end
end