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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"labix.org/v2/mgo" | |
"labix.org/v2/mgo/bson" | |
"time" | |
) | |
type Person struct { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"image" | |
"os" | |
_ "image/jpeg" | |
_ "image/png" | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"net" | |
"gopkg.in/redis.v3" | |
) | |
func main () { | |
b := random.Buffer | |
l := net.Listen(":7878") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"reflect" | |
) | |
type Foo struct { | |
FirstName string `tag_name:"tag 1"` | |
LastName string `tag_name:"tag 2"` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 != "" { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
console.log("my exec") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ npm install -g wscat | |
$ wscat -c "localhost:10000" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -e | |
export PATH=/home/user/.nvm/versions/node/v4.4.4/bin:PATH; my_exec $@ |