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
#!/bin/bash | |
ls -l $1 | awk '{print $5,$10}'| | |
while read n f | |
do | |
if [ "$f" != "" ]; then | |
xxd -p "$2/$f" | fold -w2 | head -n $n | diff -u "$3/$f" - | |
fi | |
done |
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
//usage: node main.js "14 + 34 * 22 + (3 + 4) * 5" | |
var util = require('util'); var calc = calc || {}; | |
calc.Parser = function() { | |
this.tokens = []; this.parens = []; this.pos = 0; | |
}; | |
calc.Parser.prototype.next = function() { | |
var offset = this.parens[this.parens.length - 1]; | |
if(offset + this.pos < this.tokens.length) return this.tokens[offset + this.pos++]; | |
else return null; | |
}; |
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
#usage: ruby main.rb | |
class Parser | |
def initialize | |
@stack = [] | |
end | |
def parse(line) | |
scanner = Scanner.new(line) | |
while (token = scanner.next) do | |
add_token(token) | |
end |
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
# Guardのマッチング規則を定義 | |
guard :minitest, spring: "bin/rails test", all_on_start: false do | |
watch(%r{^test/(.*)/?(.*)_test\.rb$}) | |
watch('test/test_helper.rb') { 'test' } | |
watch('config/routes.rb') { integration_tests } | |
watch(%r{^app/models/(.*?)\.rb$}) do |matches| | |
"test/models/#{matches[1]}_test.rb" | |
end | |
watch(%r{^app/controllers/(.*?)_controller\.rb$}) do |matches| | |
resource_tests(matches[1]) |
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
$ sqlite3 test.db | |
SQLite version 3.7.9 2011-11-01 00:52:41 | |
Enter ".help" for instructions | |
Enter SQL statements terminated with a ";" | |
sqlite> create table fruits(name string, value integer); | |
sqlite> insert into fruits values('apple', 100); | |
sqlite> insert into fruits values('orange', 130); | |
sqlite> .q |
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
ldf :: Int -> Int -> Maybe Int | |
ldf k n | k ^ 2 > n = Nothing | |
| rem n k == 0 = Just k | |
| otherwise = ldf (k+1) n | |
prime :: Int -> Bool | |
prime n = case (ldf 2 n) of | |
Just m -> m == n | |
Nothing -> True |
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 Parsing (parse, line) | |
import System.IO | |
import System.Environment | |
import Data.Char | |
import Data.Map as M | |
import Data.Time.Clock | |
import Control.Monad.State | |
-- http://d.hatena.ne.jp/mzp/20090308/bench | |
bench f = do from <- getCurrentTime |
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.Writer | |
size :: [[a]] -> Int | |
size = foldr (\ xs n -> length xs + n) 0 | |
move :: [[Int]] -> (Int, Int) -> Writer [String] [[Int]] | |
move xss (from, to) = return([move_ xs y (from, to) i| (xs, i) <- zip xss [0..]]) | |
where (y:_) = xss !! from | |
move_ :: [Int] -> Int -> (Int, Int) -> Int -> [Int] | |
move_ [] y (from, to) i = if i == to then [y] else [] | |
move_ (x:xs) y (from, to) i |i == from = xs |
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.Writer | |
gcd' :: Int -> Int -> Writer [String] Int | |
gcd' a b | |
|b == 0 = do | |
tell["= " ++ show a] | |
return(a) | |
|otherwise = do | |
let nb = a `mod` b | |
expr = "gcd(" ++ show(b) ++ ", " ++ show(nb) ++ ")" | |
msg = show(a) ++ " = " ++ show(b) ++ " * " ++ show(a `div` b) ++ " + " ++ show(nb) |
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
type Matrix = [[Int]] | |
dropAt :: Int -> [a] -> [a] | |
dropAt i xs = [x| (x, j) <- zip xs [0..], i /= j] | |
cofactor :: Int -> Int -> Matrix -> Matrix | |
cofactor i j m = [dropAt j v| (v, k) <- zip m [0..], i /= k] | |
det :: Matrix -> Int | |
type Matrix = [[Int]] | |
dropAt :: Int -> [a] -> [a] | |
dropAt i xs = as ++ bs where (as, _ :bs) = splitAt i xs | |
cofactor :: Int -> Int -> Matrix -> Matrix |
NewerOlder