Skip to content

Instantly share code, notes, and snippets.

View lyhcode's full-sized avatar

Kyle Lin lyhcode

View GitHub Profile
@lyhcode
lyhcode / app.js
Created May 14, 2012 12:45
Node.js + express + connect-cache
var express = require('express')
, routes = require('./routes')
, cache = require('connect-cache');
// all urls contains "cached" will be cached for 1min. e.g. /services/cached/list.json
var app = module.exports = express.createServer(
cache({rules: [
{regex: /\/cached\/.*/, ttl: 60 * 1000}
]})
@lyhcode
lyhcode / npm.log
Created May 24, 2012 02:36
npm install connect-mongodb (win32)
mongodb 0.9.7 dependency break the "npm install connect-mongodb" installation on win32 platform.
newer mongodb like 1.0.2 will fix this problem
thanks
npm ERR! error rolling back connect-mongodb@1.1.3 Error: ENOTEMPTY, rmdir 'C:\project\node_modules\connect-mongodb'
npm ERR! Unsupported
npm ERR! Not compatible with your operating system or architecture: mongodb@0.9.7
npm ERR! Valid OS: linux,darwin,freebsd
npm ERR! Valid Arch: any
@lyhcode
lyhcode / git-pull.bat
Created May 25, 2012 10:16
ACAD_TAJ project build files for windows
@echo off
set path=C:\Program Files (x86)\Git\bin;%path%
git pull
pause
@lyhcode
lyhcode / pdf.groovy
Created June 14, 2012 13:01
PDF processing with iText
//中文字型
BaseFont.createFont('MHei-Medium', 'UniCNS-UCS2-H', BaseFont.NOT_EMBEDDED)
//檔案加密
def stamper = new PdfStamper(reader, response.outputStream)
stamper.setEncryption(null, OWNER, ~(PdfWriter.ALLOW_PRINTING|PdfWriter.ALLOW_COPY|PdfWriter.ALLOW_MODIFY_CONTENTS|PdfWriter.ALLOW_MODIFY_ANNOTATIONS), PdfWriter.ENCRYPTION_AES_128 | PdfWriter.DO_NOT_ENCRYPT_METADATA)
@lyhcode
lyhcode / DESSample.groovy
Created September 5, 2012 14:04
Groovy + DES Encryption
import java.security.*
import javax.crypto.*
import javax.crypto.spec.*
def source = new File('input.dat').text
def cipher = Cipher.getInstance('DES')
cipher.init(Cipher.ENCRYPT_MODE, SecretKeyFactory.getInstance('DES').generateSecret(new DESKeySpec('secret12'.getBytes('UTF-8'))))
def target = cipher.doFinal(source.bytes).encodeBase64()
@lyhcode
lyhcode / gwstest.groovy
Created September 25, 2012 06:05
Groovy Web Start Testing
println "Hello"
@lyhcode
lyhcode / hcsr04.ino
Created October 10, 2012 08:30
Arduino + HC-SR04 超音波測距控制 LED 燈閃爍
#define TRIGPIN 10
#define ECHOPIN 13
#define LED1 8
#define LED2 9
long ping() {
digitalWrite(TRIGPIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIGPIN, HIGH);
delayMicroseconds(10);
@lyhcode
lyhcode / gist:3884579
Created October 13, 2012 13:06
solved: paypal Data does not match input character set or default encoding.
<!--
Solve the PayPal error:
paypal Data does not match input character set or default encoding.
-->
<input type="hidden" name="charset" value="UTF-8">
@lyhcode
lyhcode / nekohtml.groovy
Created December 27, 2012 10:51
Groovy + NekoHTML simple demo
@Grab('net.sourceforge.nekohtml:nekohtml:1.9.16')
def parser = new org.cyberneko.html.parsers.SAXParser()
def page = new XmlParser(parser).parse('https://news.google.com/nwshp?hl=zh-TW&tab=wn')
page.depthFirst().DIV.grep{ it.'@class'=='title' }.each {
println it.A.SPAN.text()
}
n02.jpg 0.052
s10.jpg 0.037
n05.jpg 0.099
b02.jpg 0.110
b04.jpg 0.085
n04.jpg 0.088
n10.jpg 0.064
s04.jpg 0.028
n03.jpg 0.064
b03.jpg 0.066