This file contains hidden or 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
def json_response | |
json_with_indifferent_access JSON.parse response.body | |
end | |
def json_with_indifferent_access(json) | |
traverse_json(json) {|j| j.is_a?(Hash) ? j.with_indifferent_access : j } | |
end | |
def traverse_json(json, &block) |
This file contains hidden or 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 Data.List | |
main = IO () | |
main = do | |
f ["one"] | |
f ["one", "two", "three"] | |
f ["ein", "zwei", "drei"] | |
f [] | |
f :: [String] -> IO () |
This file contains hidden or 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.Exception | |
import GHC.IO.Handle | |
import System.IO | |
import System.IO.Temp | |
main :: IO () | |
main = do | |
runWithStdin "Ornette Coleman Trio\nAt the Golden Circle Stockholm" $ do | |
getLine >>= putStrLn | |
getLine >>= putStrLn |
This file contains hidden or 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 System.IO | |
import System.IO.Temp | |
main :: IO () | |
main = do | |
withSystemTempFile "uuu" $ \path handle -> do | |
hPutStrLn handle "hello\nbye" | |
hClose handle | |
handle' <- openFile path ReadMode | |
go handle' stdout |
This file contains hidden or 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 System.Process | |
import System.IO | |
main :: IO () | |
main = do | |
(Just hi, Just ho, _, ph) <- createProcess (proc "ruby" ["-e", "f = gets; puts f "]) { std_in = CreatePipe, std_out = CreatePipe } | |
hPutStrLn hi "foobar" | |
hGetLine ho >>= print |
This file contains hidden or 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 | |
class String | |
# colorization | |
def colorize(color_code) | |
"\e[#{color_code}m#{self}\e[0m" | |
end | |
def red | |
colorize(31) |
This file contains hidden or 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
#! /bin/sh | |
# Original idea came from http://maoe.hatenadiary.jp/entry/2014/12/25/064900 | |
hash $1 2>/dev/null || { | |
cabal get $1 | |
r=`ls | grep $1 | head -1` | |
cd $r | |
cabal sandbox init | |
cabal install -j --bindir ~/.cabal/bin --datadir ~/.cabal/share |
This file contains hidden or 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
ubuntu@box69:~/hi$ hpc-coveralls spec --display-report -p --exclude-dir=test | |
{"source_files":[{"coverage":[null,null,null,null,null,null,null,null,null,null,null,null,0,null,null,null,2,null,null,0,0,0,0,0,null,null,0,0,0,0,0,null,null,0,0,0],"name":"dist/build/autogen/Paths_hi.hs","source":"module Paths_hi (\n version,\n getBinDir, getLibDir, getDataDir, getLibexecDir,\n getDataFileName, getSysconfDir\n ) where\n\nimpor | |
t qualified Control.Exception as Exception\nimport Data.Version (Version(..))\nimport System.Environment (getEnv)\nimport Prelude\n\ncatchIO :: IO a -> (Exception.IOException -> IO a) -> IO a\ncatchIO = Exception.catch\n\n\nversion :: Version\nversion = Version {versionBranch = [1,0,0,0], versionTags = []}\nbindir, libdir, datadir, libexecdir, sysconfdir | |
:: FilePath\n\nbindir = \"/home/ubuntu/hi/.cabal-sandbox/bin\"\nlibdir = \"/home/ubuntu/hi/.cabal-sandbox/lib/x86_64-lin |
This file contains hidden or 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 Control.Exception | |
import System.Random | |
import Text.Read | |
main :: IO () | |
main = go | |
go :: IO () | |
go = do |
This file contains hidden or 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
module Api | |
def self.config | |
@@_config ||= OpenStruct.new | |
end | |
def self.configure | |
yield self.config | |
end | |
end |