Skip to content

Instantly share code, notes, and snippets.

@masakielastic
masakielastic / takeWhile_and_dropWhile_and_span.hs
Created January 17, 2012 01:43
takeWhile、dropWhile、span の比較
ghci > takeWhile (6>) [1..10]
[1,2,3,4,5]
ghci > dropWhile (6>) [1..10]
[6,7,8,9,10]
ghci > span (6>) [1..10]
([1,2,3,4,5],[6,7,8,9,10])
@masakielastic
masakielastic / natural_numbers.hs
Created January 17, 2012 03:24
自然数のリスト
Prelude> [1..10]
[1,2,3,4,5,6,7,8,9,10]
Prelude> take 10 $ iterate (+1) 1
[1,2,3,4,5,6,7,8,9,10]
Prelude> take 10 $ enumFrom 1
[1,2,3,4,5,6,7,8,9,10]
Prelude> enumFromThenTo 1 2 10
[1,2,3,4,5,6,7,8,9,10]
@masakielastic
masakielastic / take_and_drop_and_splitAt.hs
Created January 17, 2012 03:46
take、drop、splitAt の比較
Prelude> take 10 [1..20]
[1,2,3,4,5,6,7,8,9,10]
Prelude> drop 10 [1..20]
[11,12,13,14,15,16,17,18,19,20]
Prelude> splitAt 7 [1..20]
([1,2,3,4,5,6,7],[8,9,10,11,12,13,14,15,16,17,18,19,20])
@masakielastic
masakielastic / php.rb
Created January 21, 2012 19:38 — forked from bc-zz/php.rb
Homebrew formula for PHP 5.4.4 (default: without-readline because of compile error)
# modified from https://github.com/lifepillar/homebrew-alt/blob/master/duplicates/php.rb
require 'formula'
def mysql_installed?
`which mysql_config`.length > 0
end
def postgres_installed?
`which pg_config`.length > 0
@masakielastic
masakielastic / ghc.rb
Created January 24, 2012 03:29
homebrew fomula for GHC 7.4.1RC
require 'formula'
class Ghc < Formula
homepage 'http://haskell.org/ghc/'
version '7.4.1RC1'
if ARGV.include? '--64bit'
url "http://www.haskell.org/ghc/dist/7.4.1-rc1/ghc-7.4.0.20111219-x86_64-apple-darwin.tar.bz2"
else
url "http://www.haskell.org/ghc/dist/7.4.1-rc1/ghc-7.4.0.20111219-i386-apple-darwin.tar.bz2"
end
@masakielastic
masakielastic / embed_gist.css
Created February 13, 2012 16:08
Tumblr に埋め込む gist の CSS
# https://gist.github.com/stylesheets/gist/embed.css
div#content .gist .gist-file {
border: none;
}
div#content .gist .gist-file .gist-data {
border-top-left-radius: 20px;
border-top-right-radius: 20px;
}
@masakielastic
masakielastic / last-in_last-out.hs
Created May 24, 2012 15:17
後入後出 (Last In, Last Out)
> let a = [1, 2, 3]
> last $ a ++ [7]
7
> let b = [3, 4, 5]
> last $ b ++ [6, 9]
9
> let c = [6, 7, 8]
> last $ c ++ [10]
10
@masakielastic
masakielastic / composer.rb
Created June 22, 2012 21:27
Formula for Composer 1.0-alpha3 (MD5 fixed)
require 'formula'
def php_installed?
`which php`.length > 0
end
def composer_reqs?
`curl -s http://getcomposer.org/installer | /usr/bin/env php -d allow_url_fopen=On -d detect_unicode=Off -- --check`.include? "All settings correct"
end
@masakielastic
masakielastic / benchmark.php
Created August 12, 2012 08:14
Benchmark curl_setopt_array vs curl_setopt
<?php
function benchmark(callable $block) {
$start = microtime(true);
for ($i = 0; $i < 100000; ++$i) {
$block();
}
$end = microtime(true);
@masakielastic
masakielastic / php.sh
Created September 1, 2012 21:41 — forked from ircmaxell/php.sh
PHP Run Script
#!/bin/bash
BIN=""
if [ "$PHP" == "/usr/local/bin/php" ]
then
PHP=""
fi
BIN="/usr/local/php/$1/bin/php"