Skip to content

Instantly share code, notes, and snippets.

Aditya Bhargava egonSchiele

Block or report user

Report or block egonSchiele

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@egonSchiele
egonSchiele / pretty_hive.rb
Created Sep 6, 2013
Display a bunch of data from a hive table in a pretty HTML table
View pretty_hive.rb
#!/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 Aug 15, 2013
Generate a valid ISBN number in ruby
View generate_valid_isbn.rb
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 Jul 29, 2013
can't kill this
View crazy.rb
trap("SIGINT") do
puts "goodbye!"
# exit
end
while true
end
View githubNotifications.hs
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 Jul 16, 2013
Drawing timer in Haskell
View Timer.hs
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 Jul 15, 2013
Lens example using Mario
View Mario.hs
{-# 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 Jun 19, 2013
Search hackage from vim
View searchHackage.rb
#!/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 Jun 10, 2013
Reader monad example
View reader.hs
import Control.Monad.Reader
hello :: Reader String String
hello = do
name <- ask
return ("hello, " ++ name ++ "!")
bye :: Reader String String
bye = do
name <- ask
@egonSchiele
egonSchiele / dining_with_waiter.rb
Created May 16, 2013
Dining philosophers using locks in Ruby. This implements a Waiter who is in charge of forks.
View dining_with_waiter.rb
require 'thread'
class Waiter
def initialize
@mutex = Mutex.new
end
def can_eat? philosopher
left = philosopher.left_fork
right = philosopher.right_fork
@egonSchiele
egonSchiele / dining.rb
Last active Sep 22, 2018
Dining philosophers in Ruby with Celluloid. Modified from https://gist.github.com/bugant/4984042
View dining.rb
require 'rubygems'
require 'celluloid'
class Waiter
include Celluloid
FORK_FREE = 0
FORK_USED = 1
attr_reader :philosophers
attr_reader :forks
attr_reader :eating
You can’t perform that action at this time.