Skip to content

Instantly share code, notes, and snippets.

View dz1984's full-sized avatar

Donald Zhan dz1984

View GitHub Profile
@dz1984
dz1984 / testCase.js
Created April 14, 2013 02:39
Using URL path to determine test case with QUnit framework.
(function() {
/*
* BaseTestCase class
*/
function BaseTestCase(name) {
this.name = name;
this.func = [];
}
/*
@dz1984
dz1984 / gae_decode.py
Last active December 16, 2015 04:59
下載之後,再次執行轉換高低位元。 http://donaldknuth.blogspot.tw/2010/03/gae.html
in_file = file('some_file','rb');
out_file = file('some_file_decode','wb');
exchange = (lambda x: chr((lambda h:(ord(h)%16)*16)(x)+(lambda l:(ord(l)/16))(x)));
in_file.seek(0,2);
counter = in_file.tell();
in_files.seek(0,0);
while counter>0:
out_file.write(exchange(in_file.read(1)));
counter-=1;
in_file.close();
@dz1984
dz1984 / gae_main.py
Created April 14, 2013 02:49
使用GAE去做跳板下載功能
#coding: utf8
import wsgiref.handlers;
from sgmllib import SGMLParser;
from google.appengine.ext import db;
from google.appengine.ext import webapp;
from google.appengine.api import users;
from google.appengine.api import urlfetch;
class Files(db.Model):
@dz1984
dz1984 / FSRv02.pde
Created April 14, 2013 02:50
把Arduino抓到的數值,透過Serial方式傳到Processing程式,利用Processing的互動特性,將這些數值視覺化,方便觀察數字變化關係。 (Processing)
import processing.serial.*;
Serial port;
int x;
float val;
float easing = 0.1;
float easedVal;
void setup(){
size(440,255);
frameRate(30);
@dz1984
dz1984 / FSRv02.ino
Created April 14, 2013 02:53
把Arduino抓到的數值,透過Serial方式傳到Processing程式,利用Processing的互動特性,將這些數值視覺化,方便觀察數字變化關係。 (Arduino)
//A0 - input pin
int fsrPin = 0;
byte fsrReading;
void setup(){
pinMode(fsrPin,INPUT);
Serial.begin(9600);
}
void loop(){
@dz1984
dz1984 / FSRv01.ino
Created April 14, 2013 02:55
把類比數值經過一道道的計算,轉換成壓力單位。 (Arduino)
//A0-input pin
int fsrPin = 0;
int fsrReading;
double fsrVoltage;
double fsrResistance;
double fsrConductance;
double fsrForcelb;
double fsrForceN;
@dz1984
dz1984 / pca_reduce_dim.r
Created April 14, 2013 02:57
使用R軟體執行主成份分析(Principal Components Analysis, PCA)減少資料維度。
dat = as.matrix(read.table("marks.dat",head=T));
dim(dat);
plot(dat);
#Step 1: 求出共變異矩陣(covariance matrix)
covMat = cov(dat);
#Step 2 計算特徴值(eigenvalues)及特徴向量(eigenvectors)。
eig = eigen(covMat);
@dz1984
dz1984 / book.js
Last active December 16, 2015 04:59
Practice the QUnit.js and the Backbone.js framework.
//Define Model class
var BookModel = Backbone.Model.extend();
BookModel.prototype.sync = function(method,model){
console.log(model.cid);
if (method==="create")
model.id = 1;
};
@dz1984
dz1984 / index.html
Last active December 16, 2015 08:18
Catch the hash of URL to determine the test case with QUnit framework.
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="Using URL path to determine test case with QUnit framework." />
<link href="http://code.jquery.com/qunit/qunit-git.css" rel="stylesheet" type="text/css" />
<link href="main.css" rel="stylesheet" type="text/css" />
<script src="http://code.jquery.com/qunit/qunit-git.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="http://documentcloud.github.io/underscore/underscore-min.js"></script>
<script src="http://documentcloud.github.io/backbone/backbone-min.js"></script>
@dz1984
dz1984 / readable_code.md
Last active December 16, 2015 15:59
閱讀What Makes Code Readable: Not What You Think這篇文章後的感想。

想要寫出容易閱讀程式碼

在**無瑕的程式碼(Clean Code)**這本書,第一章就說到:

沒有辦法不先讀程式碼就去寫程式,所以讓程式碼更容易閱讀,也會讓程式碼變得更容易撰寫。

可見得寫出令人容易閱讀的程式是一件多麼重要的事,一位專業的程式設計師就是能寫出讓人一目瞭然的程式碼。

What Makes Code Readable: Not What You Think在這篇文章,提到寫出可讀性高的程式碼,有下列幾個標準答案: