Skip to content

Instantly share code, notes, and snippets.

function getPageQuery() {
var parts = window.location.search.substring(1).split("&");
var query = {};
for (var i = 0; i < parts.length; ++i) {
var pair = parts[i].split("=");
if (pair.length == 2) {
query[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
}
}
return query;
@hisui
hisui / .mm
Created May 22, 2015 00:19
Checking if a given frame is a key frame.
static BOOL isKeyFrame(CMSampleBufferRef sample)
{
auto a = CMSampleBufferGetSampleAttachmentsArray(sample, 0);
if (CFArrayGetCount(a) > 0) {
CFBooleanRef value;
auto b = CFDictionaryGetValueIfPresent
((CFDictionaryRef) CFArrayGetValueAtIndex(a, 0)
, kCMSampleAttachmentKey_NotSync
, reinterpret_cast<const void **>(&value))
;
@hisui
hisui / tags.cpp
Created April 3, 2015 05:28
List of HTML4 Tags
template <size_t N, typename InputIterator> bool is_prefix_of(const char (&src)[N], InputIterator pos, InputIterator end)
{
for (int i = 0; i < N-1; ++i) {
if (pos == end || *pos++ != src[i]) return false;
}
return true;
}
enum Tag: uint32_t
{
digraph exercise_6_1 {
a [shape = box, label = "a: snoc (empty, 0) <3>"];
b [shape = box, label = "b: snoc (a, 1) <3>"];
c [shape = box, label = "c: tail b <2>"];
d [shape = box, label = "d: snoc (b, 2) <2>"];
e [shape = box, label = "e: c ++ d <0>"];
f [shape = box, label = "f: tail c <0>"];
g [shape = box, label = "g: snoc (d, 3) <0>"];
@hisui
hisui / so28789095.swift
Created March 10, 2015 07:19
Array#sortedGroupBy
struct Record {
let time: NSDate
let name: String
}
extension Array {
func sortedGroupBy(isOrderedBefore: (T, T) -> Bool) -> [[T]] {
let tmp = sorted(isOrderedBefore)
var out = [[T]]()
for (i, e) in enumerate(tmp) {
// Playground - noun: a place where people can play
import UIKit
class MyControl {
private var closures: [(UIControlEvents, MyControl -> ())] = []
init() {}
@hisui
hisui / red_black_tree.prolog
Created February 24, 2015 05:57
Red-Black Tree with Zipper in Prolog
:- op(200, xfy, <--).
:- op(200, xfy, /^\).
:- op(200, xfy, /^ ).
:- op(200, xfy, ^\).
tree_empty(zip(nil, [])).
tree_lhs(zip(L, [step(lhs, V, R)|XS]), zip(node(V, L, R), XS)).
tree_rhs(zip(R, [step(rhs, V, L)|XS]), zip(node(V, L, R), XS)).
@hisui
hisui / UD.swift
Last active August 29, 2015 14:14
import Foundation
public class UDKey<T> {
let key: String
let map: BiMap<AnyObject, T>
public init(_ key: String, _ map: BiMap<AnyObject, T>) {
self.key = key
self.map = map
@hisui
hisui / type.swift
Created February 1, 2015 04:00
Type Comparison
// This returns something like an ID of given type
func unsafeGetTypeId(type: Any.Type) -> uintptr_t {
return unsafeBitCast(type, uintptr_t.self)
}
func isOfType(value: Any, type: Any.Type) -> Bool {
return unsafeGetTypeId(reflect(value).valueType) == unsafeGetTypeId(type)
}
let a: Any = "Hello"
var pc = new webkitRTCPeerConnection({"iceServers": [{"url": "stun:stun.l.google.com:19302"}]});
pc.createDataChannel("hello");
pc.createOffer(function (desc){
pc.setLocalDescription(desc, function() {
console.log(desc.sdp);
});
});
/*
v=0