Skip to content

Instantly share code, notes, and snippets.

@egonSchiele
egonSchiele / why.markdown
Last active July 20, 2018 01:40
Why read Grokking Algorithms?

If you have already taken a course in algorithms, why read Grokking Algorithms (manning.com/bhargava)?

If you were learning graph algorithms, which approach would you prefer:

  1. Imagine you have to take public transit from your home to your office. How do you figure out the fastest route? Use graph algorithms! OR

  2. We can choose between two standard ways to represent a graph G = (V, E): as a collection of adjacency lists or as an adjacency matrix. Either way applies to both directed and undirected graphs.

I prefer the first way: lead with lots of examples, and clear writing. The second way is an excerpt from "Introduction to Algorithms"...that's how they start their section on graph algorithms.

@egonSchiele
egonSchiele / notes_on_cameras.markdown
Created February 12, 2014 17:03
Notes on cameras

Notes on cameras

Lenses

Focal length

Prime (fixed) lens

If it says 17mm, it's fixed at that...you can't zoom in or out. Advantages: cheaper.

@egonSchiele
egonSchiele / pretty_hive.rb
Created September 6, 2013 00:46
Display a bunch of data from a hive table in a pretty HTML table
#!/usr/bin/env ruby
require 'tempfile'
def make_row cols, style=""
"<tr style='#{style}'><td>" + cols.join("</td><td>") + "</td></tr>"
end
if ARGV.empty?
puts %{
Usage: #{$0} [file] where file has col list for a hive table, then a blank line, then some sample rows
@egonSchiele
egonSchiele / generate_valid_isbn.rb
Created August 15, 2013 20:29
Generate a valid ISBN number in ruby
def generate_valid_isbn
prefix = 978.to_s # must be 978 or 979
registration_group_element = rand(10).to_s
registrant_element = (rand(90000) + 10000).to_s
publication_element = (rand(900) + 100).to_s
_isbn = prefix + registration_group_element + registrant_element + publication_element
check_digit = 0
i = 0
_isbn.each_char do |letter|
i+= 1
@egonSchiele
egonSchiele / crazy.rb
Created July 29, 2013 05:10
can't kill this
trap("SIGINT") do
puts "goodbye!"
# exit
end
while true
end
import Control.Applicative
import Github.Gists
import Github.Users.Followers
import System.Directory
import Control.Monad
import qualified Data.Set as S
import Text.Printf
import System.Process
import System.IO.Unsafe
@egonSchiele
egonSchiele / Timer.hs
Created July 16, 2013 02:00
Drawing timer in Haskell
import Control.Concurrent
import System.Process
import System.Environment
say str = system $ "say '" ++ str ++ "'"
timer :: Int -> IO ()
timer 1 = do
say "one minute left! oh crap!"
threadDelay $ 30 * 1000 * 1000
@egonSchiele
egonSchiele / Mario.hs
Created July 15, 2013 01:41
Lens example using Mario
{-# LANGUAGE TemplateHaskell #-}
import Control.Lens
data Point = Point {
_x :: Double,
_y :: Double
} deriving (Show)
data Mario = Mario { _location :: Point } deriving (Show)
@egonSchiele
egonSchiele / searchHackage.rb
Created June 19, 2013 23:22
Search hackage from vim
#!/usr/bin/env ruby
_import = $stdin.gets
import = _import.chomp.gsub("import", "").gsub("qualified", "").gsub(/as .*/, "")
cmd = "hoogle -i '#{import}'"
puts cmd
packages = `#{cmd}`
lines = packages.split("\n")
package = lines.find do |line|
@egonSchiele
egonSchiele / reader.hs
Created June 10, 2013 20:51
Reader monad example
import Control.Monad.Reader
hello :: Reader String String
hello = do
name <- ask
return ("hello, " ++ name ++ "!")
bye :: Reader String String
bye = do
name <- ask