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
| // http://shichuan.github.com/javascript-patterns/ | |
| var mediator = (functuion(){ | |
| var subscribe = function(channel, fn){ | |
| if(!mediator.channels[channel]) mediator.channels[channel] = []; | |
| mediator.channels[channel].push({ context : this, callback : fn }); | |
| return this; | |
| }; | |
| var publish = function(channel){ | |
| if(!mediator.channels[channel]) return false; |
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
| // http://shichuan.github.com/javascript-patterns/ | |
| var observer = { | |
| addSubscriber : function(callback){ | |
| this.subscribers[this.subscribers.length] = callback; | |
| }, | |
| removeSubscriber : function(callback){ | |
| for(var i = 0; i < this.subscribers.length; i++){ | |
| if(this.subscribers[i] === callback){ | |
| delete this.subscribers[i]; |
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
| // http://shichuan.github.com/javascript-patterns/ | |
| var tree = {}; | |
| tree.decorate = function(){ | |
| console.log('Make sure the tree won\'t fall'); | |
| }; | |
| tree.getDecorator = function(deco){ | |
| tree[deco].prototype = this; |
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
| // http://shichuan.github.com/javascript-patterns/ | |
| var agg = (function(){ | |
| var index = 0; | |
| var data = [1, 2, 3, 4, 5]; | |
| var length = data.length; | |
| return { | |
| next : function(){ | |
| var element; | |
| if(!this.hasNext()) return null; |
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する | |
| import cgi | |
| import os | |
| class Request(object): | |
| """ | |
| HTTPのリクエストをハンドリングするクラス |
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 | |
| from xml.etree.ElementTree import ElementTree | |
| from urllib import urlopen | |
| def parse_rss(url): | |
| """ | |
| RSS 2.0をパースして、辞書のリストを返す | |
| """ |
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: urf-8 | |
| from rssparser import parse_rss | |
| from httphandler import Request, Response, get_htmltemplate | |
| import cgitb; cgitb.enable() | |
| form_body = u""" | |
| <form method="POST" action="/cgi-bin/rssreader1.py"> | |
| <p>RSSのURL <input type="text" size="40" name="url" value="%s"></p> |
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
| // http://www.beams.co.jp/catalog/2011winter/ | |
| (function(){ | |
| var hoge = { | |
| _privateVariables : 'private', | |
| publicValiables : 'public', | |
| _privateMethod : function(){ | |
| return _privateVariables; | |
| }, | |
| publicMethod : 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
| // http://dev.opera.com/articles/view/javascript-best-practices/ | |
| // Using some globals | |
| var current = null; | |
| var init = function(){}; | |
| var change = function(){}; | |
| var verify = function(){}; | |
| // Using object literal | |
| var myNameSpace = { |
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 | |
| # http://blog.hogeo.jp/2011/05/how-to-make-twitter-bot-python-twitter.html | |
| from oauth2 import Client, Token, Consumer | |
| consumer_key = 'ENTER_CONSUMER_KEY' | |
| consumer_secret = 'ENTER_CUNSUMER_SECRET' |