Skip to content

Instantly share code, notes, and snippets.

View hayeah's full-sized avatar
🕳️
Focusing

blah blah hayeah

🕳️
Focusing
View GitHub Profile
@hayeah
hayeah / gist:8204839
Created January 1, 2014 03:43
interesting snippet to get the minified key of an object. from react JS
/**
* Allows extraction of a minified key. Let's the build system minify keys
* without loosing the ability to dynamically use key strings as values
* themselves. Pass in an object with a single key/val pair and it will return
* you the string key of that single record. Suppose you want to grab the
* value for a key 'className' inside of an object. Key/val minification may
* have aliased that key to be 'xa12'. keyOf({className: null}) will return
* 'xa12' in that case. Resolve keys you want to use once at startup time, then
* reuse those resolutions.
*/
@hayeah
hayeah / -
Created January 20, 2014 03:54
syscalls that return two values? wtf?
pkg/syscall/zsyscall_darwin_386.go:272: r0, r1, e1 := RawSyscall(SYS_PIPE, 0, 0, 0)
pkg/syscall/zsyscall_darwin_386.go:983: r0, r1, e1 := Syscall6(SYS_LSEEK, uintptr(fd), uintptr(offset), uintptr(offset>>32), uintptr(whence), 0, 0)
pkg/syscall/zsyscall_darwin_386.go:1328: r0, r1, e1 := RawSyscall(SYS_GETTIMEOFDAY, uintptr(unsafe.Pointer(tp)), 0, 0)
pkg/syscall/zsyscall_darwin_amd64.go:272: r0, r1, e1 := RawSyscall(SYS_PIPE, 0, 0, 0)
pkg/syscall/zsyscall_darwin_amd64.go:1328: r0, r1, e1 := RawSyscall(SYS_GETTIMEOFDAY, uintptr(unsafe.Pointer(tp)), 0, 0)
pkg/syscall/zsyscall_dragonfly_386.go:262: r0, r1, e1 := RawSyscall(SYS_PIPE, 0, 0, 0)
pkg/syscall/zsyscall_dragonfly_386.go:973: r0, r1, e1 := Syscall6(SYS_LSEEK, uintptr(fd), 0, uintptr(offset), uintptr(offset>>32), uintptr(whence), 0)
pkg/syscall/zsyscall_dragonfly_amd64.go:262: r0, r1, e1 := RawSyscall(SYS_PIPE, 0, 0, 0)
pkg/syscall/zsyscall_freebsd_386.go:262: r0, r1, e1 := RawSyscall(SYS_PIPE, 0, 0, 0)
pkg/syscall/zsyscall_freebsd_386.go:973: r0, r1, e1 :=
@hayeah
hayeah / events.json
Created February 13, 2014 06:19
github events JSON
[
{
"id": "1978774765",
"type": "PushEvent",
"actor": {
"id": 382747,
"login": "andrepl",
"gravatar_id": "411d2b4791a8de51f98666e93e9f1fde",
"url": "https://api.github.com/users/andrepl",
"avatar_url": "https://gravatar.com/avatar/411d2b4791a8de51f98666e93e9f1fde?d=https%3A%2F%2Fa248.e.akamai.net%2Fassets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png&r=x"
@hayeah
hayeah / gist:9358653
Created March 5, 2014 00:17
ruby method block and yield
# In Ruby, you can always pass a block to a method call.
def foo
end
# Call foo with a block, but foo just ignores the block
foo { puts "doesn't call the block" }
# foo can capture the block
@hayeah
hayeah / callback_stack.rb
Last active August 29, 2015 13:57
callback chain ordering
require "active_support/callbacks"
class Foo
include ActiveSupport::Callbacks
define_callbacks :foo
set_callback :foo, :around, :around_1
set_callback :foo, :before, :before_1
set_callback :foo, :after, :after_1
@hayeah
hayeah / gist:9757971
Created March 25, 2014 09:22
coffeescript __extend helper for defining subclass
__extends = function(child, parent) {
for (var key in parent) {
if (__hasProp.call(parent, key)) child[key] = parent[key];
}
function ctor() {
// why set the prototype's constructor to child?
this.constructor = child;
}
ctor.prototype = parent.prototype;
child.prototype = new ctor;
@hayeah
hayeah / gotcha.go
Created May 26, 2014 12:02
Golang go Pointer Gotcha
package main
import (
"fmt"
"time"
)
type foo struct {
i int
}
@hayeah
hayeah / gist:319aa17754093c05002e
Created June 10, 2014 08:38
NodeSchool Chengdu Announcement

【成都社区活动】 NodeSchool Workshop 六月七号(周六)

NodeSchool

NodeJS 是现在最热门的 JavaScript 后端框架。你对 NodeJS 有兴趣但一直没机会深度接触吗?

  • 你是前端或者移动端开发,想学写简单的后台服务
  • 你是后台开发,想尝试用异步框架写高并发服务
  • 你是学生,想学些学校没教的新技术,想认识社区的一些牛人
@hayeah
hayeah / gist:8e98cb08d1a12e87159d
Last active July 13, 2021 06:57
NodeJS Express 训练营课程安排

暖身周 (可选)

  • 写一个简单的 NPM package
  • 用 mocha 写测试
  • 用 CoffeeScript 写 NPM package
  • 实现 JS 类 (练习原型链)

第一周 - Connect Middleware

@hayeah
hayeah / gist:a8d75339a61ae37ceb55
Last active August 29, 2015 14:02
NodeJS Bootcamp 抽奖程序
weibo = [...] # 所有转发的微博用户
email = [...] # 所有 v2ex 留帖的用户

all = weibo + email

# 随机选两个,打印
i = rand(all.length)
p all.delete_at(i)
i = rand(all.length)