Skip to content

Instantly share code, notes, and snippets.

@norio-nomura
norio-nomura / gist:62940
Created Feb 12, 2009
wait NSURLConnection's finish
View gist:62940
NSString *connectionRunLoopMode = @"connectionRunLoopMode";
NSURLConnection *connection = [[NSURLConnection alloc]initWithRequest:urlRequest delegate:urlConnectionDelegate startImmediately:NO];
NSRunLoop *currentRunLoop = [NSRunLoop currentRunLoop];
[connection unscheduleFromRunLoop:currentRunLoop forMode:NSDefaultRunLoopMode];
[connection scheduleInRunLoop:currentRunLoop forMode:connectionRunLoopMode];
[connection start];
while ([currentRunLoop runMode:connectionRunLoopMode beforeDate:[NSDate distantFuture]]);
@norio-nomura
norio-nomura / UIWebView target="_blank" hack
Created Feb 13, 2009
UIWebView target="_blank" hack
View UIWebView target="_blank" hack
static NSObject *webViewcreateWebViewWithRequestIMP(id self, SEL _cmd, NSObject* sender, NSObject* request) {
return [sender retain];
}
Class UIWebViewWebViewDelegate = objc_getClass("UIWebViewWebViewDelegate");
class_addMethod(UIWebViewWebViewDelegate, @selector(webView:createWebViewWithRequest:), (IMP)webViewcreateWebViewWithRequestIMP, "@@:@@");
View My Reachability
//
// Reachability.h
//
#import <Foundation/Foundation.h>
#import <SystemConfiguration/SystemConfiguration.h>
@interface Reachability : NSObject {
NSString *hostName;
SCNetworkReachabilityFlags reachabilityFlags;
View SecItemDelete sample
- (void)removeObjectForKey:(NSString*)key {
#if !TARGET_IPHONE_SIMULATOR
@synchronized(self) {
if (!deleteQueryDictionary) {
deleteQueryDictionary = [[NSMutableDictionary alloc]initWithObjectsAndKeys:
(id)kSecClassGenericPassword, (id)kSecClass,
key, (id)kSecAttrAccount,
(id)kSecMatchLimitAll, (id)kSecMatchLimit,
(id)kCFBooleanTrue, (id)kSecReturnAttributes,
nil];
View gist:315394
javascript:var%20d=document,w=window,enc=encodeURIComponent,e=w.getSelection,k=d.getSelection,x=d.selection,s=(e?e():(k)?k():(x?x.createRange().text:0)),s2=((s.toString()=='')?s:('%22'+enc(s)+'%22%20')),f='echofon:',l=d.location,p=enc(d.title)+'%20'+s2+enc(l.href),u=f+p;try%7Bif(!/%5E(.*%5C.)?tumblrzzz%5B%5E.%5D*$/.test(l.host))throw(0);tstbklt();%7Dcatch(z)%7Ba%20=function()%7Bwindow.location=u;%7D;if(/Firefox/.test(navigator.userAgent))setTimeout(a,0);else%20a();%7Dvoid(0)
@norio-nomura
norio-nomura / increment_bundle_version.rb
Created Apr 22, 2010
Ad Hoc なら CFBundleVersion を増やす
View increment_bundle_version.rb
#!/usr/bin/env ruby
#
# gem install plist
#
# On Xcode, right-click on your Target where you want to use this and select
# Add->New Build Phase->New Run Script Build Phase.
#
# Set the Shell to
# /usr/bin/ruby
#
@norio-nomura
norio-nomura / gist:397255
Created May 11, 2010
j.mp で短縮した url を渡して Echofon を呼び出す。login と apiKey を埋め込んでください。
View gist:397255
javascript:var c='login=YOUR_LOGIN_HERE&apiKey=YOUR_API_KEY_HERE',d=document,w=window,enc=encodeURIComponent,j=w.getSelection,k=d.getSelection,x=d.selection,s=(j?j():(k?k():(x?x.createRange().text:0))),s2=((s.toString()=='')?s:('"'+enc(s)+'" ')),l=d.location,e=d.createElement('script');
if(typeof(BitlyCB)=='undefined')var BitlyCB={};
BitlyCB.shortenResponse=function(r){
if (r.status_code==200) {
p=enc(d.title)+' '+s2+enc(r.data.url),u='echofon:'+p;
try{if(!/^(.*\.)?tumblrzzz[^.]*$/.test(l.host))throw(0);tstbklt();}
catch(z){
a=function(){w.location=u;};
if(/Firefox/.test(navigator.userAgent))setTimeout(a,0);
else a();
View gist:427557
javascript:window.opener=window;var%20win=window.open(location.href,%22_self%22);win.close();
View oyakata-test.m
#import <Foundation/Foundation.h>
@interface Oyakata : NSObject { int gakkari; }
@property int gakkari;
@end
@implementation Oyakata
@synthesize gakkari;
@end
@norio-nomura
norio-nomura / simpleBookmarkletWhichSendUstreamToAirFlick.js
Created Jan 10, 2011
simple bookmarklet which send Ustream to AirFlick
View simpleBookmarkletWhichSendUstreamToAirFlick.js
javascript:(function(){
var w=window,enc=encodeURIComponent;
if (w.ustream && w.ustream.vars.liveHttpUrl) {
var u='airflick://play-media?MediaLocation='+enc(w.ustream.vars.liveHttpUrl),
a=function(){w.location=u;};
if(/Firefox/.test(navigator.userAgent))setTimeout(a,0);
else a();
} else {
alert('this ustream is not compatible with Apple TV!');
}