Skip to content

Instantly share code, notes, and snippets.

View hajipy's full-sized avatar

Kenichi Saito hajipy

  • CureApp Inc.
  • Chiba, Japan
  • X @hajipy
View GitHub Profile
// 理想
if let mediaURL = status["extended_entities"]["media"][0]["media_url"].string {
}
// 現実
if let extendedEntities = status?["extended_entities"] {
if let mediaArray = extendedEntities["media"].array as Array<JSONValue>! {
if let media = mediaArray[0].object as Dictionary<String, JSONValue>! {
if let mediaURL = media["media_url"] as JSONValue! {
@hajipy
hajipy / gist:445b944eb3569cef358c
Created November 10, 2014 15:43
tokenField:shouldAddObjects:atIndex:
func tokenField(tokenField: NSTokenField, shouldAddObjects tokens: [AnyObject], atIndex index: Int) -> [AnyObject] {
var acceptedTokens = NSMutableArray()
if let currentTokens = tokenField.objectValue as? NSArray {
if let tokensArray = tokens as? [NSManagedObject] {
for token in tokensArray {
if currentTokens.indexOfObject(token) == NSNotFound {
acceptedTokens.addObject(token)
}
}
TASK: [install memcached] *****************************************************
failed: [default] => {"cmd": "apt-get update && apt-get install python-apt -y -q", "failed": true, "rc": 127}
stderr: /bin/sh: apt-get: command not found
msg: /bin/sh: apt-get: command not found
FATAL: all hosts have already failed -- aborting
@hajipy
hajipy / gist:833e9101ad412eff3b4d
Created May 30, 2014 12:54
URLのクエリ文字列作成
def build_query_string(params):
query_string = ''
for param in params:
if query_string != '':
query_string += '&'
query_string += param['key'] + '=' + param['value']
return query_string
@hajipy
hajipy / gist:6897339
Created October 9, 2013 07:04
Twitterで話題になったC言語のカンマの挙動テスト
#include <stdio.h>
int main(int argc, char *argv[]) {
int a = 1, b = 2, c = 3, d = 4;
a = b, c, d;
printf("a = %d, b= %d, c = %d, d = %d\n", a, b, c, d); // a = 2, b= 2, c = 3, d = 4
printf("\"a = b, c, d;\" = %d\n", (a = b, c, d)); // "a = b, c, d;" = 4
return 0;
@hajipy
hajipy / gist:6774536
Last active December 24, 2015 08:59
消費税を毎年1%ずつあげるよ!
// 初期実装
int get_tax_rate(int year) {
if (year <= 2013) {
return 5;
}
else if (year >= 2019) {
return 10;
}
else {
return 5 + (year - 2013);
hiyoriTop3({ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}); #=> {10, 9, 8}
hiyoriTop3({ 1, 2, 3, 4, 5, 6, 7, 8, 10, 10}); #=> {10, 10, 8}
hiyoriTop3({ 1, 2, 3, 4, 5, 6, 7, 8, 8, 10}); #=> {10, 8, 8}
hiyoriTop3({ 1, 2, 3, 4, 5, 6, 7, 10, 10, 10}); #=> {10, 10, 10}
hiyoriTop3({10, 10, 10, 10, 10, 10, 10, 10, 10, 10}); #=> {10, 10, 10}
class maxTest {
public static void main(String args[]){
test("test 1", 1, 2, 2);
test("test 2", 2, 1, 2);
test("test 3", 1, 1, 1);
}
public static void test(String name, int a, int b, int excepted) {
int max;
class maxTest {
public static void main(String args[]){
int a, b, max;
// Test 1
a = 1;
b = 2;
max = Math.max(a, b);
if (max == 2) {
System.out.println("test 1 OK");
public class Baisuu{
public static void main(String[] args){
for(i=2;i=<32;i=i*2){
System.out.println(i);
}
}
}