Skip to content

Instantly share code, notes, and snippets.

View fujimura's full-sized avatar

Daisuke Fujimura fujimura

View GitHub Profile
@fujimura
fujimura / tft2014.md
Last active August 29, 2015 14:06
Tools for trade 2014

% Tools for trade 2014 % fujimura

OS and Application

  • MacBook Pro 15inch
  • Mac OS X
  • Terminal.app
  • MacVim.app
module Api
def self.config
@@_config ||= OpenStruct.new
end
def self.configure
yield self.config
end
end
@fujimura
fujimura / guess.hs
Created December 13, 2014 11:28
Compare "Guessing Game" in The Rust Guide http://doc.rust-lang.org/guide.html#guessing-game
import Control.Applicative
import Control.Exception
import System.Random
import Text.Read
main :: IO ()
main = go
go :: IO ()
go = do
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
@fujimura
fujimura / cabal-sandbox-user-install.sh
Last active August 29, 2015 14:12
cabal-sandbox-user-install.sh
#! /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
@fujimura
fujimura / post-checkout
Created January 6, 2015 02:49
post-checkout hook to prevent from checking out master
#! /usr/bin/env ruby
class String
# colorization
def colorize(color_code)
"\e[#{color_code}m#{self}\e[0m"
end
def red
colorize(31)
require 'test/unit'
require 'test/unit/ui/testrunnermediator'
require 'test/unit/ui/testrunnerutilities'
require 'rubygems'
require 'redgreen'
module Test::Unit
class TestCase
def name
module SMarkUp
def markup(&block)
yield
end
TAGS = %w(body h1 h2 p div)
TAGS.each do |tag|
send(:define_method, tag) do |*args, &block|
r = block.call
r = case r
when Array
class Test::Unit::TestCase
def self.should_require_login(http_method, method)
should "require login wth #{http_method.to_s.upcase} :#{method}" do
raise "http verb(#{http_method} is not my cup of tea)" unless [:put, :get, :post, :delete].include? http_method.to_sym
if UserSession.find
UserSession.find.destroy
end
eval(http_method.to_s + "(\"#{method}\")")
assert_redirected_to new_user_session_path
end
module RecordNotFoundMacros
def should_raise_record_not_found(&block)
should "raise 'Record not Found'" do
assert_raise(ActiveRecord::RecordNotFound) {block.bind(self).call}
end
end
end