Skip to content

Instantly share code, notes, and snippets.

@passingloop
passingloop / yaml-vs-json.rb
Created December 17, 2011 14:07
yaml vs json
require 'benchmark'
require 'yaml'
require 'rubygems'
require 'bundler'
Bundler.require(:default)
require 'active_support'
def token
[Array.new(24) { rand(256).chr }.join].pack('m*').chop
end
@passingloop
passingloop / item_test-1.rb
Created December 8, 2011 03:30
Shoulda で Rails テストにコンテキストを導入してみた例
require 'test_helper'
class ItemTest < ActiveSupport::TestCase
context 'with boundary value attributes' do
test 'an item with boundary value attributes is valid' do
assert build(:item_with_boundary_value_attributes).valid?
end
test 'db allows saving an item with boundary value attributes' do
assert build(:item_with_boundary_value_attributes).save
@passingloop
passingloop / 20111125000000_crate_foos.rb
Created November 25, 2011 03:02
ActiveRecord モデルテストの例
class CreateFoos < ActiveRecord::Migration
def change
create_table :foos do |t|
t.string :bar, null: false
t.timestamps
end
add_index :foos, :bar, unique: true
end
end
@passingloop
passingloop / movie_importer.rb
Created October 31, 2011 04:07
iphone 動画変換作業用スクリプト
require 'tmpdir'
class MovieImporter
def initialize(src)
@src = src
end
def self.import(src)
MovieImporter.new(src).run
end
@passingloop
passingloop / oc_test.c
Created October 25, 2011 06:44
ただ malloc し続けるだけのプログラム
#include <stdio.h>
#include <stdlib.h>
#define GB 1073741824
int main()
{
char *p;
int i = 0;
@passingloop
passingloop / Passingloop.hs
Created October 18, 2011 01:24
7l7w-haskell-day-2
module Passingloop where
import Char
wrapJoin :: Int -> (String, Int) -> (String, Int) -> (String, Int)
wrapJoin n (str, lineLength) (word, length)
| lineLength + length < n = (str ++ " " ++ word, lineLength + length)
| otherwise = (str ++ "\n" ++ word, length)
wrap :: Int -> String -> String
wrap n str = fst $ foldl1 (wrapJoin n) [ (w, length w) | w <- words str]
@passingloop
passingloop / sudoku.pl
Created October 12, 2011 14:15
7l7w-prolog-day-3
% -*- mode: prolog; -*-
valid([]).
valid([Head|Tail]) :-
fd_all_different(Head),
valid(Tail).
sudoku(Puzzle, Solution) :-
length(Puzzle, 16),
sudoku4(Puzzle, Solution).
@passingloop
passingloop / sleepy_barber.clj
Created October 12, 2011 14:05
7l7w-clojure-day-3
(ns passingloop.sleepy_barber)
(def rnd (new java.util.Random))
(defn rush [_ chairs]
(do
(Thread/sleep (+ 10 (. rnd nextInt 20)))
(. chairs offer :customer)
(recur :dummy chairs)))
(defn haircut [_ chairs counter]
(do
@passingloop
passingloop / SKK-CFG.diff
Created October 11, 2011 04:01
ddskk-14.3 インストール
--- SKK-CFG.orig 2010-09-05 11:26:01.000000000 +0900
+++ SKK-CFG 2010-10-08 21:34:35.000000000 +0900
@@ -155,3 +155,11 @@
;; http://homepage.mac.com/zenitani/emacs-j.html
+(setq APEL_DIR "~/.emacs.d/elisp/apel")
+(setq EMU_DIR "~/.emacs.d/elisp/emu")
+(setq SKK_DATADIR "~/.emacs.d/etc/skk")
+(setq SKK_INFODIR "~/.emacs.d/info")
+(setq SKK_LISPDIR "~/.emacs.d/elisp/skk")
@passingloop
passingloop / elog.config
Created October 6, 2011 05:57
7l7w-erlang-day-3
[{sasl, [
{sasl_error_logger, {file, "/var/tmp/elog"}}
]}].