Skip to content

Instantly share code, notes, and snippets.

View ibigbug's full-sized avatar
🏓
Focusing

Yuwei Ba ibigbug

🏓
Focusing
View GitHub Profile
@ibigbug
ibigbug / expr.c
Created March 30, 2014 13:23
Calculate Reverse Polish notation Demo
#include <stdio.h>
#include <stdlib.h>
int main (int argc, char * argv[])
{
int a = 0, b = 0;
int * stack = malloc(sizeof(int) * 20);
if (stack == NULL)
return -1;
@ibigbug
ibigbug / flatten.js
Last active August 29, 2015 14:05
Flatten Array
function flatten(input) {
'use strict';
if (!Array.isArray(input)) // need polyfill
return input;
var ret = [];
(function inner(input, ret) {
if (input.length === 0)
return ret;
var car = input.shift(0);
@ibigbug
ibigbug / imageScroll.html
Created June 9, 2012 18:37
Image Scoll Demo
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>imageScroll</title>
</head>
<body>
</body>
<script type="text/javascript">
function $(e) { return document.getElementById(e); }
@ibigbug
ibigbug / count_online_number.py
Created July 21, 2012 06:45
Tornado count online number
#!/usr/bin/env python
# -*- coding:utf8 -*-
import os
import tornado.web
from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop
import uuid
@ibigbug
ibigbug / clean_google_contacts.py
Last active December 12, 2015 05:48
Clean up your google contacts
#!/usr/bin/env python
def is_cn_char(c):
"""
Chinese char detecting
"""
return 0x4e00 <= ord(c) <= 0x9fa5
@ibigbug
ibigbug / derived-function.clj
Last active December 14, 2015 10:10
Solve the derived function of a given function.
(defn diff [f]
(fn [x]
(let [dx (/ 1 Integer/MAX_VALUE)] ;nearly 0
(/ (- (apply f [(+ x dx)]) (apply f [x])) dx))))
(defn g [x] ; given function
(* x x))
(def dg (diff g)) ; get dg
(print (float (dg 3))) ; 6
@ibigbug
ibigbug / dichotomy.clj
Created March 4, 2013 12:54
Dichotomy theorems in Clojure
(defn F [a b c]; generate the target function
(fn [x]
(+ (* (+ (* a x) b) x) c)))
(def f1 (F 1 2 1))
(defn
^{:doc "(Solve f a b)
f-- the target function
a,b the interval for isolating the root"
@ibigbug
ibigbug / gene_wave.py
Created March 23, 2013 11:31
Generate simple.wav using python
#!/usr/bin/env python2
#coding:utf-8
import numpy
import wave
class MainHandler(object):
def __init__(self, duration=10, frequency=2000):
@ibigbug
ibigbug / tieba_crawler.py
Created April 9, 2013 17:05
Baidu Tieba Crawler
#!/usr/bin/env python2
#coding:utf-8
import re
import time
import os
import urllib
import requests
@ibigbug
ibigbug / node-walk.js
Created May 15, 2013 08:48
node-walk
var fs = require('fs'),
path = require('path');
exports.walk = function(abspath, callback){
/*
* callback will get { dirname: {file1: file1_abs_path, subdir: { fil2: file2_abs_path, subdir2: {}.. }};
* if not callback passed, it just returns a tree like above;
*/