Skip to content

Instantly share code, notes, and snippets.

View junfenglx's full-sized avatar
🏠
Working from home

junfeng_hu junfenglx

🏠
Working from home
View GitHub Profile
var name="Window";
var Top={
name:"top",
Inner:{
name:"inner",
getName:function(){
var that=this;
var i=0;
function increase(){
var rt="this binding:"+this.name+"\n\n"+"number i:"+i;
@junfenglx
junfenglx / dfa.py
Created November 9, 2013 16:21
DFA simulate
DFA={"A":{0:"B",1:"C"},"B":{0:None,1:"D"},"C":{0:"D",1:None},"D":{0:"A",1:"B"}}
def genstr(n,s,inputs):
if n==0:
inputs.append(s)
return
genstr(n-1,s+"0",inputs)
genstr(n-1,s+"1",inputs)
def simulate():
for n in range(1,15):
@junfenglx
junfenglx / decorators.py
Created November 9, 2013 16:23
decorators run
def makebold(fn):
def wrapped():
return "<b>" + fn() + "</b>"
return wrapped
def makeitalic(fn):
def wrapped():
return "<i>" + fn() + "</i>"
return wrapped
@junfenglx
junfenglx / semaphores.c
Created November 11, 2013 13:12
named semaphores use example.
#include <stdio.h> /* printf() */
#include <stdlib.h> /* exit(), malloc(), free() */
#include <unistd.h>
#include <sys/types.h> /* key_t, sem_t, pid_t */
#include <sys/wait.h>
#include <sys/shm.h> /* shmat(), IPC_RMID */
#include <errno.h> /* errno, ECHILD */
#include <semaphore.h> /* sem_open(), sem_destroy(), sem_wait().. */
#include <fcntl.h> /* O_CREAT, O_EXEC */
@junfenglx
junfenglx / readers_preference.c
Created November 14, 2013 10:53
readers and writers.readers_preference
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <semaphore.h>
int count = 0;
int share=0;
pthread_t maintid;
sem_t roomEmpty;
sem_t mutex;
@junfenglx
junfenglx / pcprocess.c
Created November 15, 2013 15:57
producer and consumer problem,process version. using Posix mqueue.
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <semaphore.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <mqueue.h>
#define N 1
#define BUFSIZE 1024
@junfenglx
junfenglx / chardev.c
Created December 8, 2013 14:39
char driver demo
#include "chardev.h"
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/uaccess.h>
//global varibles
static int unused=1;
static int number=0;
static char msg[N]="13111387\0";
import os
import os.path
ROOT = "."
THEME = "holo_dark"
SRC = os.path.join(ROOT, THEME)
TO = os.path.join(ROOT, "res")
@junfenglx
junfenglx / cpp_move_copy.cc
Last active August 29, 2015 14:13
use push_back demonstrates
#include <iostream>
#include <ostream>
#include <string>
#include <vector>
//comment this define to see reallocate
#define F4
class Test {
public:
std::string tag;
Test(std::string &t) : tag(t) {
@junfenglx
junfenglx / test_virtual_func.cc
Created February 9, 2015 13:23
In class constructor and destructor call virtual functions
#include <iostream>
class Base {
public:
Base() {
std::cout << "Base Constructor" << std::endl;
ctor();
}
virtual ~Base() {
std::cout << "Base Destructor" << std::endl;