Skip to content

Instantly share code, notes, and snippets.

View siongui's full-sized avatar

Siong-Ui Te (戴上為) siongui

View GitHub Profile
@siongui
siongui / draggable.js
Created February 17, 2013 00:40
AngularJS draggable element (position must be absolute)
/**
* @see https://github.com/siongui/palidictionary/blob/master/static/js/draggable.js
* @see http://docs.angularjs.org/guide/compiler
*/
angular.module('draggableModule', []).
directive('draggable', ['$document' , function($document) {
return {
restrict: 'A',
link: function(scope, elm, attrs) {
@siongui
siongui / gist:4969449
Last active April 7, 2020 08:49
AngularJS safe $apply (prevent "Error: $apply already in progress")
$scope.safeApply = function(fn) {
var phase = this.$root.$$phase;
if(phase == '$apply' || phase == '$digest')
this.$eval(fn);
else
this.$apply(fn);
};
// OR
@siongui
siongui / gist:7504643
Created November 16, 2013 20:04
獲取人人好友列表,包括帳號及姓名, From: http://www.oschina.net/code/snippet_1253232_26503 Related: https://gist.github.com/siongui/7498693
#! /bin/env python
# -*- coding: utf-8 -*-
__author__ = 'anonymous_ch'
import urllib,urllib2,cookielib,re
def login_func():
login_page = "http://www.renren.com/ajaxLogin/login"
data = {'email': 'your_email', 'password': 'your_password'}
post_data = urllib.urlencode(data)
@siongui
siongui / gist:8240270
Created January 3, 2014 15:55
使用Go并发下载图片资源 From: http://my.oschina.net/qbit/blog/189928
package img
import (
"database/sql"
"fmt"
_ "github.com/go-sql-driver/mysql"
"io"
"log"
"net/http"
"os"
package main
import (
"container/list"
"crypto/md5"
// "errors"
"flag"
"fmt"
"io"
"os"
@siongui
siongui / AI.js
Created December 14, 2013 12:54
HTML5实现中国象棋游戏(无人能敌) From: http://www.oschina.net/code/snippet_1384503_27300
var AI = AI||{};
AI.historyTable = {}; //历史表
//人工智能初始化
AI.init = function(pace){
var bill = AI.historyBill || com.gambit; //开局库
if (bill.length){
var len=pace.length;
@siongui
siongui / gist:7908402
Created December 11, 2013 10:46
linux命令行版有道词典 From: http://www.oschina.net/code/snippet_942897_27191
#!/bin/bash
ARGS=1
E_BADARGS=65
TEM_FILE="/tmp/dict.tmp"
if [ $# -ne "$ARGS" ]
then
echo "Usage:`basename $0` word"
exit $E_BADARGS
fi
#include <stdio.h>
#include <stdlib.h>
typedef struct Node{
int data;
int bf;
struct Node *lchild;
struct Node *rchild;
}Node;
#define LH 1
@siongui
siongui / sweep_mine.c
Created December 7, 2013 11:16
用C写的Linux终端扫雷小游戏 From: http://my.oschina.net/u/1387955/blog/182288
/*------------------------------------------------------------------------------
程序名:sweep_mine.c
程序功能:在Linux终端通过输入每个小格子的坐标和flag来模拟Window平台自带的扫雷小游戏
作者:张峰 [mailto:frankzhang02010@gmail.com]
修改日期:2013-12-6
------------------------------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
# -*- encodeing:utf-8 -*-
from wsgiref.simple_server import make_server
def simple_app(environ, start_response):
status = '200 OK'
response_headers = [('Content-type', 'text/plain')]
start_response(status, response_headers)
return [u"This is hello wsgi app".encode('utf8')]