Skip to content

Instantly share code, notes, and snippets.

View lemonlatte's full-sized avatar

Jim Yeh lemonlatte

  • Taipei, Taiwan
  • 19:49 (UTC +08:00)
View GitHub Profile
@lemonlatte
lemonlatte / mgoExample.go
Created March 21, 2016 06:24 — forked from border/mgoExample.go
mgo example
package main
import (
"fmt"
"labix.org/v2/mgo"
"labix.org/v2/mgo/bson"
"time"
)
type Person struct {
@lemonlatte
lemonlatte / images_dimensions.go
Created March 31, 2016 06:26 — forked from sergiotapia/images_dimensions.go
Golang - Getting the dimensions of an image. jpg, jpeg, png
package main
import (
"fmt"
"image"
"os"
_ "image/jpeg"
_ "image/png"
)
@lemonlatte
lemonlatte / notes.md
Created April 14, 2016 14:09
Notes on implementing setTimeout() and setInterval() functions in Objective-C for use by javascript code running in JSContext.

Overview

Apple's JSContext class provides a very clean, simple sandbox for running javascript code. It turns out, though, that there are some features that node.js and web browsers implement outside of the javascript language to enable additional important functionality. One of those pieces is the setTimeout function, which the popular async module relies on in order to provide control of asynchronous code flow. As an experiment, I want to implement setTimeout in Objective-C as a block that can be attached to JSContext instances to polyfill the important functionality that it provides in the browser and in the node.js runtime.

Research notes

package main
import (
"net"
"gopkg.in/redis.v3"
)
func main () {
b := random.Buffer
l := net.Listen(":7878")
@lemonlatte
lemonlatte / reflection.go
Created June 8, 2016 11:56 — forked from drewolson/reflection.go
Golang Reflection Example
package main
import (
"fmt"
"reflect"
)
type Foo struct {
FirstName string `tag_name:"tag 1"`
LastName string `tag_name:"tag 2"`
func (bc *BaseConfig) ParseEnv() {
s := reflect.ValueOf(f).Elem()
for i := 0; i < s.NumField(); i++ {
typeField := s.Type().Field(i)
tag := typeField.Tag
envKey := tag.Get("json")
value := os.Getenv(envKey)
if value != "" {
@lemonlatte
lemonlatte / index.js
Last active July 1, 2016 14:51
Example packace.json
#!/usr/bin/env node
console.log("my exec")
@lemonlatte
lemonlatte / wscat.sh
Created July 1, 2016 15:05
wscat-usage
$ npm install -g wscat
$ wscat -c "localhost:10000"
@lemonlatte
lemonlatte / create_nvm.sh
Created July 1, 2016 15:27
create_nvm_env
#!/bin/sh
NODE_VER=4.4.4
adduser --shell /bin/bash user
su -l user -c "touch /home/user/.bash_profile"
su -l user -c "curl https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh | bash"
su -l user -c "nvm install $NODE_VER"
su -l user -c "nvm alias default $NODE_VER"
su -l user -c "nvm alias default $NODE_VER"
@lemonlatte
lemonlatte / my_exec
Created July 1, 2016 15:38
nvm-my_exec
#!/bin/sh -e
export PATH=/home/user/.nvm/versions/node/v4.4.4/bin:PATH; my_exec $@