Skip to content

Instantly share code, notes, and snippets.

View yorkie's full-sized avatar
🎯
Focusing

Yorkie Makoto yorkie

🎯
Focusing
View GitHub Profile
@yorkie
yorkie / ex.rs
Created July 17, 2014 12:54
properly use {} in rust
fn main() {
struct House { owner: Box<Person> }
struct Person { age: int }
let mut house = box House {
owner: box Person {age: 30}
};
{ // this pair of braces is required
// here the brace is the operator, it release the reference
@yorkie
yorkie / example.rs
Last active August 29, 2015 14:03
why use a not age?
// an example shows how rust make @ in match expression systax
match age {
a @ 0..20 => println!("{} years old", age),
_ => println!("older than 21")
}
// That's because we can
fn inc_age(mut age: int) -> int {
@yorkie
yorkie / node.tree
Created June 29, 2014 08:13
node structure
node
├── AUTHORS
├── BSDmakefile
├── CONTRIBUTING.md
├── ChangeLog
├── LICENSE
├── Makefile
├── README.md
├── android-configure
├── benchmark
#include <uv.h>
#include <stdio.h>
static void
exit_cb(uv_process_t *handle, int64_t status, int signal) {
printf("child exit: %lld, %d\n", status, signal);
}
int main(int argc, char **args) {
@yorkie
yorkie / count-your-source-code.awk
Last active August 29, 2015 14:02
my-code-lines.awk
# this awk script just count the effective lines of your source codes
/^.+$/ {
plus(count)
}
/^{/ {
minus(count)
}
@yorkie
yorkie / awk-loop.js
Created June 19, 2014 06:02
A simple javascript script to help you take the **awk** main loop
// This simple javascript script what @yorkie write is just show you my
// knowledge on awk main loop.
var fs = require('fs');
var lines = fs.readFileSync('your awk file path').toString('utf8').split('\r\n');
var rules = [
// Here you define the rule for input
]
@yorkie
yorkie / client.js
Last active August 29, 2015 14:02
JSON Stream Protocol Example
// client - side
var client = XMLStream('xmlstream.com', 3000);
client.on('data', function(stanza) {
// TODO
});
client.on('connect', function() {
// writeMessage
client.writeMessage({
type: 'auth',
@yorkie
yorkie / gc-bf.js
Created May 26, 2014 15:25
gc example
var http = require('http');
function request(callback) {
var option = {
host: 'www.baidu.com',
port: 80,
path: '/',
method: 'GET'
};
package main
import (
"flag"
"net/http"
"crypto/tls"
"crypto/x509"
"io/ioutil"
"log"
)
@yorkie
yorkie / lexical-scope-in-es.js
Created May 4, 2014 16:08
it prints 10 not 20, because javascript use static(lexical) scope for function variable
var x = 10;
function foo() {
console.log(x);
}
(function(func) {
var x = 20;
foo();