Skip to content

Instantly share code, notes, and snippets.

View girvan's full-sized avatar
Hello World!

Hi girvan

Hello World!
View GitHub Profile
@girvan
girvan / lite__init__.py
Created August 28, 2011 06:57
你覺的第18行這樣子寫如何?
import sys
import types
import os
import urllib
import cgi
import logging
from Cookie import SimpleCookie
# instance
_liter = None
@girvan
girvan / main.py
Created September 10, 2011 03:14
hello world demo by using pili.lite
from pili import lite
def main():
lite.init(globals())
echo('hello world')
if __name__ == '__main__':
main()
@girvan
girvan / gist:1390751
Created November 24, 2011 06:22
Javascript bookmark for scrolling test
javascript:(function () { var scroll_length = 20; var stuck_threshold = 2; var height = 4000; var url = window.location.href.split("url=")[1]; var wait = parseInt(url.split("#")[1]); var start_time = new Date().getTime() / 1000; var yo = function () { document.getElementById('ttt').contentWindow.document.getElementById('footer-links').innerHTML += "<div style='background-color:gray;width:10px;position:absolute;height:" + height + "px;top:0;left:0;'>&nbsp;<\/div>"; var win = document.getElementById('ttt').contentWindow; var doc = document.getElementById('ttt').contentWindow.document; var i = 0; var last = 0; while (i < height) { win.scrollTo(0, i); i += scroll_length; } alert("#take:" + ((new Date().getTime() / 1000) - start_time - wait / 1000)); }; setTimeout(yo, wait); document.body.innerHTML = ("<iframe id='ttt' src='" + url + "' width='100%' height='100%'></iframe>"); })();
@girvan
girvan / gist:2155315
Created March 22, 2012 02:54
把下面這一段貼到bashrc裡面即可
function wtitle(){ echo -ne "\033]0; $@ \007"; }
@girvan
girvan / fetch-content-by-using-gae.py
Created March 22, 2012 03:03
到shell.appspot.com,然後執行下列指令即可
from google.appengine.api import urlfetch
result = urlfetch.fetch("http://software.sopili.net/")
result.content
function htmlhex_decode($str){
if(preg_match_all("/&#(\d+);/",$str,$match)){
foreach($match[1] as $key=>$value){
$str=str_replace($match[0][$key],"\u".dechex($value),$str);
}
}
$str=preg_replace("/&#x(\d+);/","\\u$1",$str);
$str=str_replace(Array("\r","\n"),Array("\\r","\\n"),$str);
function big52utf8($big5str) {
$blen = strlen($big5str);
$utf8str = "";
for($i=0; $i<$blen; $i++) {
$sbit = ord(substr($big5str, $i, 1));
//echo $sbit;
//echo "<br>";
if ($sbit < 129) {
//一開始總是必要的
require '/home/www/config.php';
//或是這樣
require '../config.php'; //但這樣子在crontab不能跑
//當然,接下來的路徑就使用變數或常數來寫程式
require SOPILI_PATH.'/lib/db_connection.php';
<?php
require '../../config.php'; //原本是這樣
require dirname(__FILE__)."/../../config.php"; //改成這樣
<?php
//宣告
var url_arr=new Array('software.sopili.net','dev.sopili.net');
//讀取
for(var i in url_arr){
document.write(url_arr[i]+'<br>');
}