Skip to content

Instantly share code, notes, and snippets.

from django import template
register = template.Library()
@register.filter
def gt(a, b):
return a > b
import threading
import time
sort_list = [1, 3, 6, 8, 10, 33, 44, 23]
def sort(lis):
answer_list = []
for num in lis:
thread = threading.Thread(target=sleep, args=(num, answer_list))
def fizz_check(num):
return "fizz" if num % 3 == 0 else ""
def buzz_check(num):
return "buzz" if num % 5 == 0 else ""
def fizz_buzz(num):
return [(fizz_check(n) + buzz_check(n)) or n for n in range(1, num + 1)]
@AyatoKinkori
AyatoKinkori / timebar.m
Created July 22, 2013 00:46
縦置きのタイムバーをcocos2dで実装する。 ref: http://qiita.com/ayahito2828/items/4efea78ec0b65adacb13
CCProgressTimer *time_bar = [CCProgressTimer progressWithSprite:[CCSprite spriteWithFile:@"timebar.png"]];
//タイムバーの生成を行う。
time_bar.percentage = 100.0;
//時間切れでゲームを止めるので初期値を100にする。
time_bar.type = kCCProgressTimerTypeBar;
//タイムバーのタイプレクタングルが他にある。
time_bar.barChangeRate = ccp(0, 1);
@AyatoKinkori
AyatoKinkori / rotate.m
Created July 18, 2013 00:38
cocos2dで、反時計周りにスプライトを回転させたかった時に試したこと ref: http://qiita.com/ayahito2828/items/4650f2f995a236f5042f
CCSprite *rotete_object = [CCSprite initWithFile:@"hadaka_oyaji.png"];
CCRotateBy *rotateby_clockwise = [CCRotateBy actionWithDuration:0.1 angle:180];
[rotate_object runAction: [CCRepeatForever actionWithAction:rotateby_clockwise]];
//これだと、時計回りに永遠に回転し続ける。
CCRotateBy *rotateby_rev_clockwise = [CCRotateBy actionWithDuration:0.1 angle:-180];
//マイナス、を付けている
[rotate_object runAction: [CCRepeatForever actionWithAction:rotateby_rev_clockwise]];
//反時計周りに回転し続ける。
@AyatoKinkori
AyatoKinkori / replace_capturestr.m
Created July 2, 2013 14:49
Objective-Cの正規表現、キャプチャした変数で文字列置換 ref: http://qiita.com/AyatoKinkori@github/items/750af1bcade414f4effc
NSString *str = @"hogehogefugao";
NSRegularExpression *regexp = [NSRegularExpression regularExpressionWithPattern:@"(hoge).+(fugao)" options:0 error:nil];
NSString *new_str = [regexp
stringByReplacingMatchesInString:str options:0 range:NSMakeRange(0, str.length) withTemplate:@"$1山$2"];
//new_strは hoge山fugaoになります。
NSMutableDictionary *mutable_dic = [[NSMutableDictionary alloc] initWithCapacity:2];
//辞書の生成
int i;
for (i = 0; i < 100; i++) {
NSDictionary *dic = [NSDictionary dictionaryWithObject:@"hoge" forKey:@"Key"];
[mutable_dic addEntriesFromDictionary:dict];
}