Skip to content

Instantly share code, notes, and snippets.

View chakrit's full-sized avatar

Chakrit Wichian chakrit

View GitHub Profile
var _ = require('underscore');
function dud() { }
var result = _.wrap(dud, function(wrapped) {
console.log(arguments);
return 'result';
})('one', 'two', 'three');
console.log(result);

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
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;
@chakrit
chakrit / generic-inh-tree.swift
Last active August 29, 2015 14:14
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.
import Foundation
import XCPlayground
protocol Identifiable: Hashable {
var id: String { get }
}
@objc class IdentifiableObject: NSObject, Identifiable {
private let _id: String
import Foundation
class Model {
func action() {
genericPrint(self.dynamicType.self, self)
}
}
class Child: Model {
func indirect() {
@chakrit
chakrit / gist:04688ff895fa34a1d4bd
Last active August 29, 2015 14:13
Swift ranges weirdness.
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
}
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 / text.md
Last active July 18, 2018 20:34
On Go binary deploys.

Talked with @anthonybouch and @scomma the other day and told them that I don't do source-deploys with Go programs. It was sort of a gut reaction and also because I havn't quite worked out all the details at that time as I was not at the stage to be thinking about deployments just yet.

Cons

@scomma made note that you could still do git deploys with source and compile on the server and that's right that you can do that but there are some complications:

@chakrit
chakrit / main.go
Last active March 23, 2018 14:57
Testing golang's map behavior when the map is nil. Map is defined in the spec as being a reference type (i.e. you can assign maps to multiple variables but they would share the underlying storage). In this case, you can actually index a nil map, but not add values to it. This is nice but could a bit surprising when you are testing for your code'…
package main
import "fmt"
type Values map[string]string
func main() {
var v Values = nil
fmt.Printf("%-15s\t%-15s\t%-15s\n", "nil", "result", "ok")
require('coffee-script');
require('./test.coffee');