This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'celluloid' | |
class Philosopher | |
include Celluloid | |
def initialize(name, left_fork, right_fork) | |
@name = name | |
@left_fork = left_fork | |
@right_fork = right_fork | |
self.think |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Control.Monad | |
import Control.Concurrent | |
import Control.Concurrent.STM | |
import System.Random | |
import Text.Printf | |
-- Forks | |
type Fork = TMVar Int | |
newFork :: Int -> IO Fork |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'celluloid' | |
class Waiter | |
include Celluloid | |
FORK_FREE = 0 | |
FORK_USED = 1 | |
attr_reader :philosophers | |
attr_reader :forks | |
attr_reader :eating |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'thread' | |
class Waiter | |
def initialize | |
@mutex = Mutex.new | |
end | |
def can_eat? philosopher | |
left = philosopher.left_fork | |
right = philosopher.right_fork |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Control.Monad.Reader | |
hello :: Reader String String | |
hello = do | |
name <- ask | |
return ("hello, " ++ name ++ "!") | |
bye :: Reader String String | |
bye = do | |
name <- ask |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE TemplateHaskell #-} | |
import Control.Lens | |
data Point = Point { | |
_x :: Double, | |
_y :: Double | |
} deriving (Show) | |
data Mario = Mario { _location :: Point } deriving (Show) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trap("SIGINT") do | |
puts "goodbye!" | |
# exit | |
end | |
while true | |
end |