Skip to content

Instantly share code, notes, and snippets.

$ ruby -v bench.rb
ruby 1.9.2dev (2010-01-05 trunk 26241) [x86_64-darwin10.2.0]
Content-Type: text/html
Result:500000500000<br>
Sec:0.058694
$ php -v
PHP 5.3.0 (cli) (built: Jul 19 2009 00:34:29)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2009 Zend Technologies
@sandinist
sandinist / gist:1519600
Created December 25, 2011 18:46
gsed magic comment
gsed -i '1s/.*/# encoding:utf-8\n&/' **/*.rb
@sandinist
sandinist / gist:1593309
Created January 11, 2012 06:08
magic comment for all .rb
ruby -p -i -0777 -e '$_.insert(0,"# encoding : UTF-8\n")' **/*.rb
@sandinist
sandinist / gist:1603692
Created January 12, 2012 23:03
NSArray+Map
#import "NSArray+Map.h"
@implementation NSArray (Map)
- (NSArray *)map:(id(^)(id))block {
NSMutableArray * newArray = [NSMutableArray array];
for (id item in self) {
id obj = block(item);
[newArray addObject:obj];
}
@sandinist
sandinist / gist:1609147
Created January 13, 2012 22:36
#clrh66 demo
r g scaffold attend name:string mail:string receipt_name:string be_lightning:boolean be_party:boolean other:text
#config/application.rb
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.default_url_options = { :host => 'clrh66.heroku.com' }
ActionMailer::Base.smtp_settings = {
:enable_starttls_auto => true,
:address => 'smtp.gmail.com',
@sandinist
sandinist / gist:1640113
Created January 19, 2012 13:44
clrh回数取得
require "rubygems"
require "nokogiri"
require "open-uri"
doc = Nokogiri.HTML(open("http://clr-h.jp"))
p doc.search("//td[@class='ListTitle']//a")[0].text
@sandinist
sandinist / gist:1659881
Created January 23, 2012 01:38
pry iterm forward delete
-If you're using a Mac terminal, take a look at [this article](http://www.21croissants.com/howto/fix-forward-delete-key-on-snow-leopard-for-irb).
+#### iTerm2
+
+* Go to iTerm > Preferences... > Keys
+* Add a Global Shortcut Key
+* Type the `delete` key as Shortcut
+* Select Send Hex Codes as Action and type 0x004
+* Click on `OK` and you're good to go
+
+#### iTerm
@sandinist
sandinist / gist:1866683
Created February 20, 2012 00:08
TapDisco/ViewController.m
#import "ViewController.h"
#import <AVFoundation/AVFoundation.h>
@implementation ViewController
static AVCaptureSession * captureSession;
static AVCaptureDevice * captureDevice;
static AVAudioPlayer * tapaudio, * moveaudio;
static UIAcceleration * accele;
static BOOL shaking;
const float power = 2.0;
@sandinist
sandinist / gist:1909445
Created February 25, 2012 16:37
NSSetUncaughtExceptionHandler
#import "AppDelegate.h"
void uncaughtExceptionHandler(NSException *exception) {
NSLog(@"CRASH: %@", exception);
NSLog(@"Stack Trace: %@", [exception callStackSymbols]);
// Internal error reporting
}
@implementation AppDelegate
@sandinist
sandinist / gist:2035912
Created March 14, 2012 11:35
[sed]replace migration column name int -> integer
sed -i.bak s/t.int\ :/t.integer\ :/ *.rb