This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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!" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$scope.safeApply = function(fn) { | |
var phase = this.$root.$$phase; | |
if(phase == '$apply' || phase == '$digest') | |
this.$eval(fn); | |
else | |
this.$apply(fn); | |
}; | |
// OR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @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) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
__author__= 'anonymous_ch' | |
import urllib2 | |
import urllib | |
import cookielib | |
from bs4 import BeautifulSoup |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import datetime | |
import httplib | |
import json | |
import time | |
import urllib2 | |
def urlopen(url): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a[href$=".pdf"] { | |
background: url(../img/pdf_icon_16x16.png) no-repeat; | |
padding-left: 20px; | |
} | |
...or if you don't want to use an icon, but do want to let your users know you're linking to a file: | |
a[href$=".pdf"]:after { | |
content: " (PDF)" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
有时候在使用javascript的时候需要格式化一些输出,比如AJAx回来的JSON数据格式化成HTML片段的时候,使用简单的字符串拼接都闲得比较麻烦,当然有的时候可以使用一些JS模板引擎但是又觉得不合适,可能代码里就只用到了几处这样的功能却引入及时KB的JS库,有些不划算。这里给出一个只要12行代码就可以实现的模板引擎。功能很简单只是替换变量。但是对于一般的需求应该是够用了。 | |
*/ | |
;(function (window) { | |
function Template(str) { | |
this.str = str; | |
} | |
Template.prototype.format = function () { | |
var arg = arguments[0] instanceof Array ? arguments[0] : arguments; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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')] |
OlderNewer