Skip to content

Instantly share code, notes, and snippets.

View droxer's full-sized avatar
🎯
Focusing

Fei He droxer

🎯
Focusing
  • Internet
  • 13:22 (UTC +08:00)
View GitHub Profile
@droxer
droxer / rx-example.java
Created July 15, 2015 05:55
RxJava example.
package rxexamples;
import rx.schedulers.Schedulers;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@droxer
droxer / data-container.sh
Created June 10, 2015 01:07
Docker data only container backup/restore
# backup
docker run --volumes-from mongodata -v $(pwd):/backup busybox tar cvf /backup/backup.tar /data/db
# restore
docker run --volumes-from mongodata -v $(pwd):/backup busybox tar xvf /backup/backup.tar
# Dockerfile
FROM centos
@droxer
droxer / inherit.js
Created June 2, 2015 13:12
javascript inherit.js
#!/usr/local/bin/node
var assert = require('assert')
function Animal (name) {
this.name = name;
}
assert.equal(new Animal("animal").constructor, Animal)
assert.equal(new Animal("animal") instanceof Animal, true)
@droxer
droxer / eval.js
Created June 2, 2015 13:11
javascript eval example.
#!/usr/local/bin/node
var assert = require('assert')
function foo () {
return "foobar";
}
eval("var bar = " + foo.toString())
@droxer
droxer / bind.js
Created June 2, 2015 13:11
javascript bind example.
#!/usr/local/bin/node
var assert = require("assert")
function talk (who) {
return this.name + " is talking with " + who
}
var michael = {
name : "michael"
}
@droxer
droxer / select.c
Created February 28, 2015 14:10
Linux select example.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <sys/select.h>
@droxer
droxer / oo.c
Created February 28, 2015 13:49
OO implementation by C.
#include <stdio.h>
struct greet_api
{
int (*say_hello)(char *name);
int (*say_goodbye)(void);
};
int say_hello_fn(char *name) {
printf("Hello %s\n", name);
package main
import (
"bufio"
"net"
)
type Client struct {
incoming chan string
outgoing chan string
def rota(people):
_people = list(people)
current = 0
while len(_people):
command = yield _people[current]
current = (current + 1) % len(_people)
if command:
comm, name = command
if comm == "add":
_people.append(name)
def rota(people):
_people = list(people)
current = 0
while len(_people):
yield _people[current]
current = (current + 1) % len(_people)
if __name__ == "__main__":
people = ["Ant", "Bernard", "Carly", "Deb", "Englebert"]
r = rota(people)