Skip to content

Instantly share code, notes, and snippets.

@bricklife
bricklife / numbers.hs
Created March 3, 2012 17:34
generate numbers list
numbers :: Int -> Int -> Int -> [[Int]]
numbers _ _ 0 = [[]]
numbers start end num = [n:ns | n <- [start..end], ns <- numbers n end (num - 1)]
@bricklife
bricklife / gist:3300336
Created August 9, 2012 02:11
URL processing test
NSString* urlString = @"javascript:(function(){var%20a='日本語';prompt(a);})();";
//NSString* urlString = @"dpad://?text=日本語&title=タイトル";
//NSString* urlString = @"dpad://bookmark?title=日本語&url=http://bricklife.com/日本語";
NSString* decodeString = [urlString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSLog(@"decodeString:\t%@", decodeString);
NSString* encodeString = [decodeString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSLog(@"encodeString:\t%@", encodeString);
NSURL* url = [NSURL URLWithString:encodeString];
@bricklife
bricklife / gist:3369833
Created August 16, 2012 12:33
removing characters
// making a string
NSMutableString *s = [[NSMutableString alloc] initWithCapacity:256];
for (char c = 0x20; c < 0x7f; c++) {
[s appendFormat:@"%c", c];
}
[s appendString:@"日本語"];
NSString *original = [NSString stringWithString:s];
NSLog(@"original:[%@]", original);
// setting a character set
@bricklife
bricklife / gist:3402767
Created August 20, 2012 09:59
MFC + Windows 版 MySQL で UTF-8 な日本語を扱う
#include <my_global.h>
#include <mysql.h>
void TestMySQL()
{
TRACE("MySQL client version: %s\n", mysql_get_client_info());
MYSQL *conn = mysql_init(NULL);
if (conn == NULL) {
TRACE("Error %u: %s\n", mysql_errno(conn), mysql_error(conn));
@bricklife
bricklife / gist:3916645
Created October 19, 2012 07:03
dpad scheme
NSArray *input = [NSArray arrayWithObjects:
@"dpad://?text=abc",
@"dpad:///insert?text=abc",
@"dpad://editor/?text=abc",
@"dpad://editor/insert?text=abc&location=overwrite",
@"dpad://bookmark/add?title=Google&url=http://www.google.com/",
@"dpad://clip/add?title=abc&code=ABC",
@"dpad://browser/open?url=http://www.google.com/",
@"dpad://clipboard/copy?text=abc",
nil];
@bricklife
bricklife / gist:5624811
Last active December 17, 2015 14:29
ARC + Blocks examination
# MyObject.h
@interface MyObject : NSObject
@property (nonatomic, copy) void (^block)();
@property (nonatomic, copy) NSString *str;
- (void)performBlock;
@end
@bricklife
bricklife / gist:8885492
Created February 8, 2014 15:31
generate Content-MD5 in shell
cat <file path> | openssl dgst -md5 -binary | openssl enc -base64
RAC(self, text) = self.textField.rac_textSignal;
=>
RACSubscriptingAssignmentTrampoline *trampoline = [[RACSubscriptingAssignmentTrampoline alloc] initWithTarget:self nilValue:nil];
trampoline[@keypath(self, text)] = self.textField.rac_textSignal;
=>
[self.textField.rac_textSignal setKeyPath:@keypath(self, text) onObject:self nilValue:nil];
@bricklife
bricklife / gist:439e69c97f251b4364db
Last active August 29, 2015 14:25
RACDelegateProxy in UITableVIewController
#import "TableViewController.h"
#import <ReactiveCocoa/ReactiveCocoa.h>
#import <ReactiveCocoa/RACDelegateProxy.h>
@interface TableViewController ()
@property (nonatomic, strong) RACDelegateProxy *tableViewDelegate;
@end
@bricklife
bricklife / gist:68a04a6171063c8429a9
Last active May 9, 2018 05:25
Resizable inputAccessoryView on UITableView in iOS 8
import UIKit
class InputAccessoryTableViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.becomeFirstResponder()
}