Skip to content

Instantly share code, notes, and snippets.

@dictav
Last active October 11, 2015 15:08
Show Gist options
  • Save dictav/3877796 to your computer and use it in GitHub Desktop.
Save dictav/3877796 to your computer and use it in GitHub Desktop.
Tumblr 貼付け用

Tumblr 貼付け用のGist

ACAccountStore *accountStore = [ACAccountStore new];
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSDictionary *options = @{
ACFacebookAppIdKey : @"facebook_app_id",
ACFacebookPermissionsKey : @[@"email"]
};
[accountStore requestAccessToAccountsWithType:accountType options:options completion:^(BOOL granted, NSError *error) {
if(granted) {
NSLog(@"granted");
NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];
if ([accountsArray count] > 0) {
ACAccount *facebookAccount = [accountsArray objectAtIndex:0];
SLRequest *facebookRequest = [SLRequest requestForServiceType:SLServiceTypeFacebook
requestMethod:SLRequestMethodGET
URL:[NSURL URLWithString:@"https://graph.facebook.com/me/feed"]
parameters:nil];
[facebookRequest setAccount:facebookAccount];
[facebookRequest performRequestWithHandler:^(NSData* responseData, NSHTTPURLResponse* urlResponse, NSError* error) {
NSLog(@"%@", [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]);
}];
}
} else {
NSLog(@"not granted: %@", error);
}
}];
NSString *str = @"hoge";
[str switch:@{
@"hoge" : ^{
NSLog(@"this is hoge");
},
@"piyo" : ^{
NSLog(@"this is piyo");
},
@1 : ^{
NSLog(@"this is 1");
}}
default:^{
NSLog(@"Not found");
}];
// NSURLConnection などを使った際にリダイレクトが発生した時のキャッシュのやりかた。
NSURL *url = @"original.url";
NSURLRequest *request = [NSURLRequest requestWithURL:url
cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
timeoutInterval:60 ];
[NSURLConnection sendAsynchronousRequest:request
queue:downloadQueue
completionHandler:^(NSURLResponse *res, NSData *data, NSError *error) {
NSCachedURLResponse *cachedRes = [[NSCachedURLResponse alloc] initWithResponse:res data:data];
NSURLCache *cache = [NSURLCache sharedURLCache];
[cache storeCachedResponse:cachedRes forRequest:request];
}];
#! /usr/bin/env ruby
# coding:utf-8
require 'date'
title = ARGV[0]
if title.nil? or title.empty?
abort "Usage: jekkyll-add <TITLE>"
end
date = Date.today
filename = "_posts/" + date.to_s + "-" + title + ".md"
content = <<CONTENT
---
title: #{title}
date: #{date}
tags:
css: [blog,syntax]
---
CONTENT
File.open(filename,'w'){|f| f.write content}
system ENV['EDITOR'], filename
#import <Foundation/Foundation.h>
@interface NSObject (IntegrationSwitch)
- (void)switch:(NSDictionary*)blocks default:(void(^)())defaultBlock;
@end
#import "NSObject+switch.h"
@implementation NSObject (IntegrationSwitch)
- (void)switch:(NSDictionary*)blocks default:(void (^)())defaultBlock
{
void (^blk)(void) = blocks[self];
if (blk) {
blk();
} else {
defaultBlock();
}
}
@end
#import <Foundation/Foundation.h>
@interface NSObject (IntegrationSwitch)
- (void)switch:(NSDictionary*)blocks default:(void(^)())defaultBlock;
@end
#import "NSObject+switch.h"
@implementation NSObject (IntegrationSwitch)
- (void)switch:(NSDictionary*)blocks default:(void (^)())defaultBlock
{
void (^blk)(void) = blocks[self];
if (blk) {
blk();
} else {
defaultBlock();
}
}
@end
- (void)viewDidLoad
{
[super viewDidLoad];
UITextView *textView = [[UITextView alloc] initWithFrame:frame];
/* ... setup text view
font, color, background-color, and more
... */
[self.view addSubview:textView];
}
@interface UIWindow (WatchShakeGesture)
- (void)swizz_sendEvent:(UIEvent *)event;
+ (BOOL)toggleWatchShakeGesture;
@end
@implementation UIWindow (WatchShakeGesture)
+ (BOOL)toggleWatchShakeGesture
{
static BOOL watching = NO;
watching = !watching;
SEL originalSelector = @selector(sendEvent:);
SEL overrideSelector = @selector(swizz_sendEvent:);
Method originalMethod = class_getInstanceMethod(self, originalSelector);
Method overrideMethod = class_getInstanceMethod(self, overrideSelector);
method_exchangeImplementations(originalMethod, overrideMethod);
return watching;
}
- (void)swizz_sendEvent:(UIEvent *)event
{
if (event.subtype == UIEventSubtypeMotionShake) {
[TestFlight openFeedbackView];
}
[self swizz_sendEvent:event]; //swizz_sendEvent: was renamed by method_exchangeImplementations()
}
@end
// Google AJAX Feed API
class MyWidgetItem extends WP_Widget {
function MyWidgetItem() {
parent::WP_Widget(false, $name = 'Google AJAX Feed API');
}
function widget($args, $instance) {
extract( $args );
$title = apply_filters( 'widget_title', $instance['title'] );
$feed = apply_filters( 'widget_body', $instance['feed'] );
?>
<div id="google_ajax_feed_api_widghet" class="widget widget_my_calendar_upcoming_widget">
<p><?php echo $title; ?></p>
<p id="gfeed"></p>
<script src="https://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
var xmlUrl = "<?php echo $feed; ?>"; //feedのURL
var setNum = 5; //表示件数
var setID = "gfeed"; //表示させる箇所のID
google.load("feeds", "1");
function initialize() {
var html = '';
var feed = new google.feeds.Feed(xmlUrl);
feed.setNumEntries(setNum);
feed.load(function(result) {
if (!result.error){
var container = document.getElementById(setID);
for (var i = 0; i < result.feed.entries.length; i++) {
var entry = result.feed.entries[i];
var title = entry.title; //記事タイトル取得
var link = entry.link; //記事のリンクを取得
//日付を取得し年月日を整形
var publishedDate = entry.publishedDate;
var pubDD = new Date(publishedDate);
yy = pubDD.getYear();if (yy < 2000) { yy += 1900; }
mm = pubDD.getMonth() + 1;dd = pubDD.getDate();
var pubDate = yy +'年'+ mm +'月'+ dd +'日';
//カテゴリ要素がある場合は取得
for (var j = 0; j < entry.categories.length; j++) {
var categorie = entry.categories[j];
}
//表示する部分を整形
html += '<li><a href="' + link + '">' + title +'</a> - ' + categorie + '(' + pubDate + ')</li>';
}
container.innerHTML = html;
}
});
}
google.setOnLoadCallback(initialize);
</script>
</div>
<?php
}
function update($new_instance, $old_instance) {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
$instance['feed'] = trim($new_instance['feed']);
return $instance;
}
function form($instance) {
$title = esc_attr($instance['title']);
$feed = esc_attr($instance['feed']);
?>
<p>
<label for="<?php echo $this->get_field_id('title'); ?>">
<?php _e('ラベル'); ?>
</label>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('feed'); ?>">
<?php _e('Feed URL'); ?>
</label>
<input class="widefat" id="<?php echo $this->get_field_id('feed'); ?>" name="<?php echo $this->get_field_name('feed'); ?>" type="feed" value="<?php echo $feed; ?>" />
</p>
<?php
}
}
add_action('widgets_init', create_function('', 'return register_widget("MyWidgetItem");'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment