Skip to content

Instantly share code, notes, and snippets.

View sonsongithub's full-sized avatar

Yuichi Yoshida sonsongithub

View GitHub Profile
@sonsongithub
sonsongithub / gist:ec1962ecd1530e3c2869
Created July 14, 2015 09:06
Simple movie view using AVKit
import UIKit
import AVFoundation
import AVKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let item = AVPlayerItem(URL: NSURL(string: "http://i.imgur.com/4WHLcYw.mp4")!)
@sonsongithub
sonsongithub / gist:46f9bafdee6edfd178e8
Created July 21, 2015 01:25
Create Thing class enum from HTML?
def main
types = ["Comment", "Link", "Message", "More", "Subreddit", "Listing", "Multireddit", "MultiredditDescription", "Account"]
part1 = ""
part2 = ""
part3 = ""
types.each{|type|
part1 = part1 + sprintf($temp1, type, type)
@sonsongithub
sonsongithub / fold.swift
Created August 2, 2015 20:25
foldr and foldl in Swift2.0
extension CollectionType {
func foldr<B>(accm:B, f: (Self.Generator.Element, B) -> B) -> B {
var g = self.generate()
func next() -> B {
return g.next().flatMap {x in f(x, next())} ?? accm
}
return next()
}
func foldl<B>(accm:B, f: (Self.Generator.Element, B) -> B) -> B {
@sonsongithub
sonsongithub / foldr.swift
Last active August 29, 2015 14:26
Implemented "foldr" using recursive, loop and reduct.
//
// foldrTests.swift
// foldrTests
//
// Created by sonson on 2015/08/04.
// Copyright © 2015年 sonson. All rights reserved.
//
import XCTest
@sonsongithub
sonsongithub / symposium.swift
Last active September 1, 2015 10:52
Code snippets for Swift symposium #2
// About character counting in UTF-8 and Swift
var str = "かきくがぎぐ🇯🇵"
str.characters.count
str.unicodeScalars.count
let s1 = "\u{E9}"
let s2 = "\u{65}\u{301}"
// Compatibility equivalence and Canonical Equivalent
@sonsongithub
sonsongithub / test.swift
Created September 17, 2015 18:09
Speed performance test for URL percent escaping.
//
// escapeTests.swift
// escapeTests
//
// Created by sonson on 2015/09/18.
// Copyright © 2015年 sonson. All rights reserved.
//
import XCTest
//@testable import escape
@sonsongithub
sonsongithub / test.c
Created September 18, 2015 06:31
Arguments are ignored?
#include <stdio.h>
int hoge();
int main(int argc, char**argv) {
hoge(1);
printf("test\n");
return 0;
}
@sonsongithub
sonsongithub / parse.swift
Created September 23, 2015 09:19
very simple, reddit markdown parser
//
// RedditParser.swift
// redditParser
//
// Created by sonson on 2015/09/22.
// Copyright © 2015年 sonson. All rights reserved.
//
import Foundation
// Halide
#include "Halide.h"
// Include some support code for loading pngs.
#include "halide_image_io.h"
// for performance test
#include <sys/time.h>
double currentTime() {
timeval t;
@sonsongithub
sonsongithub / sizeof_test.c
Created November 7, 2015 07:45
sizeof..?
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char **argv) {
printf("%ld\n", sizeof("ab "));
return 0;
}