Skip to content

Instantly share code, notes, and snippets.

View grandeforesta's full-sized avatar

Yusuke Obayashi grandeforesta

View GitHub Profile
#import <Foundation/Foundation.h>
typedef void (^completeBlock_t)(NSData *data);
typedef void (^errorBlock_t)(NSError *error);
@interface AsyncURLConnection : NSObject
{
NSMutableData *data_;
completeBlock_t completeBlock_;
errorBlock_t errorBlock_;
#import <Foundation/Foundation.h>
typedef void (^completeBlock_t)(NSData *data);
typedef void (^errorBlock_t)(NSError *error);
@interface AsyncURLConnection : NSURLConnection
{
NSMutableData *data_;
completeBlock_t completeBlock_;
errorBlock_t errorBlock_;
#import "AsyncURLConnection.h"
@implementation AsyncURLConnection
+ (id)request:(NSString *)requestUrl completeBlock:(completeBlock_t)completeBlock errorBlock:(errorBlock_t)errorBlock
{
return [[[self alloc] initWithRequest:requestUrl
completeBlock:completeBlock errorBlock:errorBlock] autorelease];
}
@moyashi
moyashi / gist:982277
Created May 20, 2011 03:11
カーソル行のテキストをshで実行して、結果をカーソル位置に挿入 for TypeIt4Me ( http://bit.ly/iorZdU )
-- このスクリプトを「;sh」とかに割り当てて、行末で実行すると、「;sh」の直前までをクリップボードに送って
-- っていうかCommand + Xを押して、クリップボードに送られたテキストをshで実行する
-- 「;sh」の前にはスペースを開ける必要あり
-- ps ax ;sh
-- ps ax
-- ブワーっとプロセスリスト
-- といった感じ
-- 「;sh」は、打った時点でスクリプトの実行キーとして消化されて消える
@ku
ku / apn.cpp
Created June 15, 2011 22:32
Push Notification(Provider側)をC++で実装する
//
// Push Notification(Provider側)をObjective-Cで実装する - wirehead virtual machine http://d.hatena.ne.jp/wirehead/20091206
// gcc apn.cpp -o apn -lssl -lcrypto -lstdc++
// ./apn 62c844764111be8222715f26c00708b59143af0cc7d55910cc325caf0162994c 'hello'
//
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <openssl/ssl.h>
@robflaherty
robflaherty / csv-to-json.php
Created September 1, 2011 02:26
Convert CSV to JSON
<?php
/*
* Converts CSV to JSON
* Example uses Google Spreadsheet CSV feed
* csvToArray function I think I found on php.net
*/
header('Content-type: application/json');
// Set your CSV feed
import os
import csv
from subprocess import Popen, PIPE
from Foundation import NSMutableDictionary
build_number = os.popen4("git rev-parse --short HEAD")[1].read()
info_plist = os.environ['BUILT_PRODUCTS_DIR'] + "/" + os.environ['WRAPPER_NAME'] + "/Info.plist"
# Open the plist and write the short commit hash as the bundle version
plist = NSMutableDictionary.dictionaryWithContentsOfFile_(info_plist)
@Abizern
Abizern / uuidgen.m
Created December 20, 2011 11:51
A method that returns a UUID in an ARC environment.
- (NSString *)uuidString {
// Returns a UUID
CFUUIDRef uuid = CFUUIDCreate(kCFAllocatorDefault);
NSString *uuidStr = (__bridge_transfer NSString *)CFUUIDCreateString(kCFAllocatorDefault, uuid);
CFRelease(uuid);
return uuidStr;
}
@ellneal
ellneal / gist:2557400
Created April 30, 2012 11:06
Static View at top of UIScrollView - place in layoutSubviews
UIView *staticHeaderView = <#static view#>;
CGRect visibleBounds = self.bounds;
CGRect staticHeaderFrame = staticHeaderView.frame;
CGRect contentRect = CGRectMake(0, 0, self.contentSize.width, self.contentSize.height);
if (CGRectGetMinY(visibleBounds) < CGRectGetMinY(contentRect)) {
staticHeaderFrame = CGRectMake(visibleBounds.origin.x, CGRectGetMinY(contentRect), staticHeaderFrame.size.width, staticHeaderFrame.size.height);
}
@rummelonp
rummelonp / undersky.md
Last active April 16, 2023 03:57
Ubuntu+Nginx+Unicorn+Rails+Capistrano