Skip to content

Instantly share code, notes, and snippets.

View pingjiang's full-sized avatar
🎯
Focusing

pragmatic_jiang pingjiang

🎯
Focusing
View GitHub Profile
@pingjiang
pingjiang / lisp.cpp
Created March 29, 2013 11:19 — forked from ofan/lisp.cpp
Lisp interpreter in 90 lines of C++
I've enjoyed reading Peter Norvig's recent articles on Lisp. He implements a Scheme interpreter in 90 lines of Python in the first, and develops it further in the second.
Just for fun I wondered if I could write one in C++. My goals would be
1. A Lisp interpreter that would complete Peter's Lis.py test cases correctly...
2. ...in no more than 90 lines of C++.
Although I've been thinking about this for a few weeks, as I write this I have not written a line of the code. I'm pretty sure I will achieve 1, and 2 will be... a piece of cake!
<?php
// PHP Hello World!
echo phpinfo();
?>
@pingjiang
pingjiang / markdown_table_generator.py
Created July 14, 2014 11:40
You can generate markdown table from cvs like text file.
#!/usr/bin/env python
#--*-- coding: UTF-8 --*--
import sys
def generateNewParts(parts, isHeader = True):
if len(parts) == 3:
return parts
pos = parts[1].find('(')
@pingjiang
pingjiang / sae_cdn_libs
Created July 20, 2014 23:02
抓取SAE支持CDN库的列表
#!/usr/bin/env python
#--*-- coding: UTF-8 --*--
import urllib
import re
import sys
sae_cdn_libs = ['angular.js', 'backbone', 'bootstrap', 'dojo', 'ext-core', 'highcharts',
'highstock', 'jq.mobi', 'jquery', 'jquery-mobile', 'jquery-ui', 'jquery.cookie',
'jquery.migrate', 'jquerytools', 'json2', 'lesscss', 'mootools', 'prototype', 'qunit',
@pingjiang
pingjiang / call_cocoa_in_cpp
Created August 15, 2014 09:06
This program shows how to access Cocoa GUI from pure C/C++ and build a truly functional GUI application (although very simple).
/*
* test1.cpp
* This program shows how to access Cocoa GUI from pure C/C++
* and build a truly functional GUI application (although very simple).
*
* Compile using:
* g++ -framework Cocoa -o test1 test1.cpp
*
* that will output 'test1' binary.
*/
Pod::Spec.new do |s|
s.name = "Sparkle"
s.version = "0.1.0"
s.summary = "A software update framework for the Mac"
s.description = <<-DESC
Sparkle is an easy-to-use software update framework for Cocoa developers.
* True self-updating--no work required from the user.
* Displays release notes to the user via WebKit.
* Displays a detailed progress window to the user.
@pingjiang
pingjiang / gen.sh
Created October 11, 2014 04:55
generate mocha testcase
#!/bin/sh
F=fixtures.md
for rar in `ls *.rar`
do
echo "it('test $rar', function() {"
echo "var entries = rar.list('./test/fixtures/${rar}'); "
echo "var expected = ["
unrar lb $rar | sed -e 's/^/ "/' | sed -e 's/$/", /'
@pingjiang
pingjiang / gen1.sh
Created October 11, 2014 06:53
generate mocha testcase
#!/bin/sh
F=fixtures.md
for rar in `ls *.rar`
do
echo "it('test extract $rar', function() {"
echo "rar.extract('./test/fixtures/${rar}', './tmp/'); "
echo "var expected = ["
unrar lb $rar | sed -e 's/^/ "/' | sed -e 's/$/", /'
@pingjiang
pingjiang / fab.js
Created October 13, 2014 14:09
better memoized fabnacci
function fab(n) {
if (n < 3) {
return 1;
}
var p1=1, p2=1, p;
function _fab(m) {
if (m < n) {
p = p1 + p2;
p1 = p2;
p2 = p;
@pingjiang
pingjiang / loop_trap.js
Created October 13, 2014 14:54
NodeJS Loop trap, callback is called nextTick.
var fs = require('fs');
var files = ['a.txt', 'b.txt', 'c.txt'];
for (var i = 0; i < files.length; i++) {
fs.readFile(files[i], 'utf-8', function(err, contents) {
console.log(files[i] + ': ' + contents);
});
}