Skip to content

Instantly share code, notes, and snippets.

View siongui's full-sized avatar

Siong-Ui Te (戴上為) siongui

View GitHub Profile
@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:7498693
Created November 16, 2013 10:39
利用BeautifulSoup解析社交網路人人網好友狀態, From http://www.oschina.net/code/snippet_1253232_26481
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__= 'anonymous_ch'
import urllib2
import urllib
import cookielib
from bs4 import BeautifulSoup
@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
/**
* @see http://docs.angularjs.org/guide/dev_guide.services.creating_services
* Lastly, it is important to realize that all Angular services are application singletons.
* This means that there is only one instance of a given service per injector.
*/
// code snippet from: http://stackoverflow.com/a/13763886
app.service('myService', function() {
// service is just a constructor function
// Source: https://groups.google.com/forum/#!topic/angular/hVrkvaHGOfc
// jsFiddle: http://jsfiddle.net/pkozlowski_opensource/PxdSP/14/
// author: Pawel Kozlowski
var myApp = angular.module('myApp', []);
//service style, probably the simplest one
myApp.service('helloWorldFromService', function() {
this.sayHello = function() {
return "Hello, World!"