Skip to content

Instantly share code, notes, and snippets.

View norio-nomura's full-sized avatar

Norio Nomura norio-nomura

View GitHub Profile
@norio-nomura
norio-nomura / gist:62940
Created February 12, 2009 23:29
wait NSURLConnection's finish
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 February 13, 2009 07:23
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, "@@:@@");
//
// Reachability.h
//
#import <Foundation/Foundation.h>
#import <SystemConfiguration/SystemConfiguration.h>
@interface Reachability : NSObject {
NSString *hostName;
SCNetworkReachabilityFlags reachabilityFlags;
@norio-nomura
norio-nomura / SecItemDelete sample
Created February 23, 2010 01:36
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];
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 April 22, 2010 06:48
Ad Hoc なら CFBundleVersion を増やす
#!/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 12:38
j.mp で短縮した url を渡して Echofon を呼び出す。login と apiKey を埋め込んでください。
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();
@norio-nomura
norio-nomura / gist:427557
Created June 6, 2010 12:30
Close Bookmarklet
javascript:window.opener=window;var%20win=window.open(location.href,%22_self%22);win.close();
#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 January 10, 2011 05:52
simple bookmarklet which send Ustream to AirFlick
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!');
}