Skip to content

Instantly share code, notes, and snippets.

View ainame's full-sized avatar

Satoshi Namai ainame

View GitHub Profile
@ainame
ainame / chain_query.rb
Created August 27, 2015 17:55
ChainQuery allow you to build query by method chains.
class ChainQuery
def initialize(init_value)
@init_value = init_value
@filters = []
end
def add_filter(&block)
@filters << block
self
end
@ainame
ainame / a.pl
Created January 30, 2014 16:23
こういうテストを書こうとしたら、末端のsubtestでbeforeの処理が実行されて欲しくなる
use strict;
use warnigns;
use Test::More;
use Test::More::Hooks;
package Foo {
sub new{ bless { counter => $_[1] }, $_[0]; }
sub count_up { shift->{counter} += shift; }
};
@ainame
ainame / AMEHTTPRequestTestCase.h
Last active August 29, 2015 14:01
非同期+HTTPリクエストをスタブしたいときに使うと便利なテストクラス
#import <XCTest/XCTest.h>
#import <TKRGuard.h>
#import <OHHTTPStubs.h>
@interface AMEHTTPRequestTestCase : XCTestCase
@property (nonatomic, strong) NSURLRequest *lastRequest;
- (void)stubAllRequestWithResponseFileName:(NSString *)responseFileName statuCode:(NSInteger)statusCode;
@ainame
ainame / Gemfile
Last active August 29, 2015 14:05
開発環境ではarproxy+explain_parserでexplainをログに吐く. arproxy.rbはconfig/initializer/arproxy.rb などに置く.
gem 'arproxy'
gem 'explain_parser'
@ainame
ainame / bug.rb
Created October 10, 2014 02:56
user = {
id: 1,
name: 'ainame',
}
if flag
user[:gender] = 'male', # ← 末尾にカンマが入ってしまっていたけどシンタックスエラーにはならない
user[:age] = 100
end
@ainame
ainame / aws.rb
Last active August 29, 2015 14:07
AWS SDKのラッパーを作るとき用の便利concern ref: http://qiita.com/ainame/items/ae6fa3ed3df87d51e523
module MyApp
module AWS
class SNS
def self.stub_configuration
AWS::Core::Configuration.new(
access_key_id: 'ACCESS_KEY_ID',
secret_access_key: 'SECRET_ACCESS_KEY',
stub_requests: true,
)

住所

〒 153-0064 東京都目黒区下目黒5-11-24 シェアハウス(中村・矢口・荻原宅)

行き方

best practice

@ainame
ainame / identity.rb
Last active September 17, 2015 13:31
.idがidenitityを提供するということを示すmixinモジュールの名前どれが良いか
# 1
class Coriander
include MyApp::Entity::HasId
end
# 2
class Coriander
include MyApp::Entity::Identifiable
end
@ainame
ainame / remove_resnpond_block.rake
Created July 14, 2011 16:35
Rails3のscaffoldで生成されたコントローラーからrespond_toブロックを消す。lib/taskに配置して使う
# -*- coding: utf-8 -*-
require "tempfile"
desc "scaffoldで生成されたコントローラーからrespond_toブロックを消す"
namespace :my do
task :rm_respond_to do
Dir::glob("app/controllers/*_*.rb") do |ctrl|
if !(File::basename(ctrl) =~ /application/)
temp = Tempfile::new("tmp",Dir::pwd)
open(ctrl) do |f|
text = f.read
@ainame
ainame / jyanken_game.pl
Created August 3, 2011 12:08
じゃんけんをCUI上で行うだけの糞プログラム。Perl使って初めてプログラム書きました。
#! /usr/bin/env perl
use warnings;
use strict;
use 5.010;
sub prompt{
do{
my $hand;
say "グー[g], チョキ[c], パー[p]";
print "入力してください:";