Skip to content

Instantly share code, notes, and snippets.

View ainame's full-sized avatar

Satoshi Namai ainame

View GitHub Profile
@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,
)
@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 / 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 / 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 / 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; }
};
(defun func1 (func)
(funcall func))
(defun func2 (func)
(func1
(lambda ()
(funcall func))))
(func2
(lambda ()
(defun func1 (func)
(funcall func))
(defun func2 (func)
(func1
(lambda ()
(funcall func))))
(func2
(lambda ()
(require 'cl-lib)
(defvar newline-or-open-line/open-line-count 0)
(make-variable-buffer-local 'newline-or-open-line/open-line-count)
(defun newline-or-open-line/increment-open-line ()
(setq newline-or-open-line/open-line-count (+ newline-or-open-line/open-line-count 1)))
(defun newline-or-open-line/clear-open-line-count ()
(setq newline-or-open-line/open-line-count 0))
(require 'cl-lib)
(defvar newline-or-open-line/open-line-count nil)
(make-variable-buffer-local 'newline-or-open-line/open-line-count)
(defun newline-or-open-line/increment-open-line ()
(push 'open-line newline-or-open-line/open-line-count))
(defun newline-or-open-line/clear-open-line-count ()
(progn
(defun newline-or-open-line ()
"newline-or-openline is a new command for merging C-m and C-o"
(interactive)
(let ((string-exists-before-cursor (string-match "[^\\\s\\\n\\\t]" (buffer-substring (point-at-bol) (point))))
(string-exists-after-cursor (string-match "[^\\\s\\\n\\\t]" (buffer-substring (point) (point-at-eol)))))
(cond ((or (eolp)
(not string-exists-after-cursor)
(and string-exists-before-cursor string-exists-after-cursor))
(progn (newline) (indent-according-to-mode)))
(t (progn (open-line 1) (indent-according-to-mode))))))