Skip to content

Instantly share code, notes, and snippets.

View sonsongithub's full-sized avatar

Yuichi Yoshida sonsongithub

View GitHub Profile
@sonsongithub
sonsongithub / gist:44768b95a6175c836886
Created September 12, 2014 14:22
debug NSAttriutedString and CoreText
if (self.attributedString != nil && [self.attributedString.string rangeOfString:@"これになる不思議"].location != NSNotFound) {
DNSLog(@"%@", self.attributedString);
UniChar *p = (UniChar*)malloc(sizeof(UniChar) * self.attributedString.string.length);
[self.attributedString.string getCharacters:p];
FILE *fp = fopen("/Users/sonson/bug_data.bin", "wb");
fwrite(p, sizeof(UniChar), self.attributedString.string.length, fp);
fclose(fp);
free(p);
@sonsongithub
sonsongithub / line_counter.rb
Created October 23, 2014 10:58
line counter for itch
#!/usr/bin/env ruby
paths = []
paths.push(ARGV[0] + "/**/*.h")
paths.push(ARGV[0] + "/**/*.m")
blacklist = ["/imobile/", "/nend/", "/Google/", "/Evernote/", "/admob/", "/TestFlight/", "/UICoderz/"]
lines = 0
@sonsongithub
sonsongithub / gestureRecognizerShouldBegin.m
Created December 16, 2014 01:47
detect direction of UIKIt gesture recognizer
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
// スワイプのジェスチャを開始するかを判定する
if ([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]) {
UIPanGestureRecognizer *panGesture = (UIPanGestureRecognizer *)gestureRecognizer;
CGPoint velocity = [panGesture velocityInView:panGesture.view];
double radian = atan(velocity.y/velocity.x);
double degree = radian * 180 / M_PI;
// 指定した角度よりも大きく(斜めに)スワイプした場合は,ジェスチャは開始されない
@sonsongithub
sonsongithub / gist:37a7c05ef9bb88038b43
Last active August 29, 2015 14:14
NSPredicate - predicateWithFormat
// This is OK
NSString *temp = [NSString stringWithFormat:@"title BEGINSWITH %@", searchBar.text];
NSPredicate *predicate = [NSPredicate predicateWithFormat:temp];
// Bad...
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"title BEGINSWITH %@", searchBar.text];
@sonsongithub
sonsongithub / gist:32aa13cfa382f97da94b
Created March 17, 2015 07:10
post-commit script for 2tch
#!/bin/bash
GIT_MARKETING_VERSION=`git describe --abbrev=0 --tags`
GIT_REVISION=`git rev-parse --short HEAD`
GIT_COMMIT_TIMES_STRING=`git log --since=2000-01-01 --oneline --no-merges | wc -l`
let GIT_COMMIT_TIMES=GIT_COMMIT_TIMES_STRING+13000
cat > ./2tch/info.prefix <<EOT
@sonsongithub
sonsongithub / gist:25b8b0598c7201af5a60
Created April 16, 2015 07:16
Ruby script to create github issue from reddit.com API list.
require 'octokit'
api_div_html_text = <<"EOS"
<div class="toc"><ul><li><strong>API methods</strong><span class="mode-selector"><a class="mode mode-current" href="/dev/api">by section</a><a class="mode " href="/dev/api/oauth">by oauth scope</a></span><ul><li><a href="#section_account" class="section">account</a><ul><li class="supports-oauth"><a href="#GET_api_v1_me">/api/v1/me</a></li><li class="supports-oauth"><a href="#GET_api_v1_me_blocked">/api/v1/me/blocked</a></li><li class="supports-oauth"><a href="#GET_api_v1_me_friends">/api/v1/me/friends</a></li><li class="supports-oauth"><a href="#GET_api_v1_me_karma">/api/v1/me/karma</a></li><li class="supports-oauth"><a href="#GET_api_v1_me_prefs">/api/v1/me/prefs</a></li><li class="supports-oauth"><a href="#GET_api_v1_me_trophies">/api/v1/me/trophies</a></li><li class="supports-oauth"><a href="#GET_prefs_blocked">/prefs/blocked</a></li><li class="supports-oauth"><a href="#GET_prefs_friends">/prefs/friends</a></li><li class="supports-oauth"><a href="#GET_prefs_{
@sonsongithub
sonsongithub / gist:7d1559f6cd1749fecc15
Created April 16, 2015 14:49
Ruby script to create label which means reddit.com API category.
require 'octokit'
client = Octokit::Client.new(:access_token => "")
labels = [
"account",
"captcha",
"flair",
"reddit gold",
#
# generate HttpStatus.swift from wikipedia
# for reddift project
# https://github.com/sonsongithub/reddift
#
# http://en.wikipedia.org/wiki/List_of_HTTP_status_codes
#
require 'net/http'
@sonsongithub
sonsongithub / gist:91217e252be445dfa277
Last active August 29, 2015 14:22
Playground crushes when running the following code in Xcode7.
import UIKit
func doit(value:Int) throws -> String {
if value > 0 {
return String(value)
}
else {
throw NSError(domain: "test.sonson.com", code: 0, userInfo: [:])
}
}
@sonsongithub
sonsongithub / gist:f1714cbcfcaa7d4aab74
Created June 25, 2015 11:34
Result<A> meets flatMap
//: Playground - noun: a place where people can play
import UIKit
public enum Result<A> {
case Success(A)
case Failure(NSError)
public init(value:A) {
self = .Success(value)