This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Dir.glob(**/*.*){ |f| puts "#{f} #{File.size(f)}" } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//#import <sqlite3.h> | |
sqlite3* d = nil; | |
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); | |
NSString *documentsDirectory = [paths objectAtIndex:0]; | |
NSString *path = [documentsDirectory stringByAppendingPathComponent: @"testdb.db"]; | |
if (sqlite3_open([path UTF8String], &d) != SQLITE_OK) { | |
// Even though the open failed, call close to properly clean up resources. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun quote-word() | |
(interactive) | |
(forward-char) ;; 単語先頭対策 | |
(backward-word) | |
(insert "\"") | |
(forward-word) | |
(insert "\"") | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module AcmeHttp | |
module Error; end | |
end | |
begin | |
begin | |
raise IOError, "Some IO error" | |
rescue Exception => error | |
error.extend(AcmeHttp::Error) | |
# class << error; p self.ancestors; end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSString *urlString = [NSString stringWithFormat:@"http://example.com/foo"]; | |
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString]]; | |
NSString *userAgent = [NSString stringWithFormat:@"igaiga Browser"]; | |
[request setValue:userAgent forHTTPHeaderField:@"User-Agent"]; | |
NSURLResponse *response; | |
NSError *error = nil; | |
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSString *urlString = [NSString stringWithFormat:@"http://example.com/foo"]; | |
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString]]; | |
// get User Agent in UIWebView | |
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectZero]; | |
NSString *userAgent = [webView stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"]; | |
NSLog(@"UserAgent: %@", userAgent); | |
[webView release]; | |
[request setValue:userAgent forHTTPHeaderField:@"User-Agent"]; | |
NSURLResponse *response; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface ImageUploader : NSObject { | |
NSData *theImage; | |
} | |
@property (retain) NSData *theImage; | |
- (void) syncUpload:(NSData *) uploadImage; | |
@end | |
#import "ImageUploader.h" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; color design for background black | |
;(add-to-list 'default-frame-alist '(alpha . (0.95 0.85))) | |
(set-background-color "black") | |
(set-foreground-color "white") | |
(custom-set-faces | |
'(font-lock-comment-face ((((class color) (min-colors 88) (background dark)) (:foreground "wheat1")))) | |
'(font-lock-function-name-face ((((class color) (min-colors 88) (background dark)) (:foreground "HotPink1" :weight bold)))) | |
'(font-lock-keyword-face ((((class color) (min-colors 88) (background dark)) (:foreground "LightSalmon1")))) | |
'(font-lock-string-face ((((class color) (min-colors 88) (background dark)) (:foreground "bisque1")))) | |
'(font-lock-type-face ((((class color) (min-colors 88) (background dark)) (:foreground "DarkSeaGreen1" :weight bold)))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# Arrayオブジェクトの要素が奇数の項目を全て足すコードを書いてください。 | |
# 例えば array = [2,3,5,7,11] の場合、 3+5+7+11 = 26 が表示されればOKです。 | |
# ヒント:奇数かどうか調べるのは Fixnum#odd? メソッド | |
# 1.odd? → true, 2.odd? → false | |
# ちなみに偶数か調べるのは Fixnum#even? メソッドです。 | |
array = [2,3,5,7,11] | |
sum = 0 | |
array.each do |i| | |
sum += i if i.odd? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
items = [{:title => "a", :price => 70}, | |
{:title => "b", :price => 200}, | |
{:title => "c", :price => 50}] | |
items.each do |item| | |
item[:special] = 'Low price!' if item[:price] < 100 | |
end | |
#[{:title=>"a", :price=>70, :special=>"Low price!"}, | |
# {:title=>"b", :price=>200}, | |
# {:title=>"c", :price=>50, :special=>"Low price!"}] |