Skip to content

Instantly share code, notes, and snippets.

Avatar

Chakrit Wichian chakrit

View GitHub Profile
View container.swift
class Container {
typealias Resolver = () -> AnyObject
private var _resolvers: [String: Resolver] = [:]
func register<T: AnyObject>(resolver: @autoclosure () -> T) {
let name = NSStringFromClass(T.self)
_resolvers[name] = resolver
}
func get<T: AnyObject>() -> T {
@chakrit
chakrit / gist:04688ff895fa34a1d4bd
Last active Aug 29, 2015
Swift ranges weirdness.
View gist:04688ff895fa34a1d4bd
import Foundation
let a = 1
let b = 10
func thisFailsToCompile() -> Bool {
// type 'Range<Int>' does not conform to protocol 'IntervalType'
let range = a..<b
return range ~= 3
}
View gist:7ba69fa2b714ebb25989
import Foundation
class Model {
func action() {
genericPrint(self.dynamicType.self, self)
}
}
class Child: Model {
func indirect() {
@chakrit
chakrit / generic-inh-tree.swift
Last active Aug 29, 2015
Defining functions `==` on a protocol or generically on a protocol does not quiet work. The difference between the 3 versions is in where `Equatable` is applied and how `==` is defined.
View generic-inh-tree.swift
import Foundation
import XCPlayground
protocol Identifiable: Hashable {
var id: String { get }
}
@objc class IdentifiableObject: NSObject, Identifiable {
private let _id: String
View BrandsAdapter.java
package com.example.adapters;
import android.graphics.drawable.ColorDrawable;
import android.view.View;
import android.view.ViewGroup;
import com.example.R;
import com.example.models.Brand;
import com.example.models.ImageKind;
View horses.md

5th round (5x5x5x5x5)

If we split the 25 hourses into groups of 5 and have each group race among themselves, we'd be able to establish the ranking inside each group:

group:        1 2 3 4 5
1st finisher: a b c d e
2nd finisher: f g h i j
3rd finisher: k l m n o
View gist:f704a48644864d9465bc
var _ = require('underscore');
function dud() { }
var result = _.wrap(dud, function(wrapped) {
console.log(arguments);
return 'result';
})('one', 'two', 'three');
console.log(result);
View fix-issue-28.patch
diff --git a/src/node_http.cc b/src/node_http.cc
index 5ccc53b..d01912b 100644
--- a/src/node_http.cc
+++ b/src/node_http.cc
@@ -277,8 +277,13 @@ HTTPConnection::on_headers_complete (http_parser *parser)
message_info->Set(version_minor_symbol,
Integer::New(connection->parser_.http_minor));
- message_info->Set(should_keep_alive_symbol,
- http_should_keep_alive(&connection->parser_) ? True() : False());
View gist:262250
# sending { "Connection": "close" }
# wget 0.0.0.0:8000
HELLO....
HELLO....
HELLO....
HELLO....
HELLO....
HTTP/1.1 200 OK
View gist:391843
import re
# http://atomboy.isa-geek.com/plone/Members/acoil/programing/double-metaphone
from metaphone import dm as double_metaphone
# get the Redis connection
from jellybean.core import redis
import models
# Words which should not be indexed