Skip to content

Instantly share code, notes, and snippets.

View FiNGAHOLiC's full-sized avatar
🐰
Strugglin'

Yukihiko Okuyama FiNGAHOLiC

🐰
Strugglin'
  • Root Communications
  • Tokyo Japan
  • 13:08 (UTC +09:00)
View GitHub Profile
@FiNGAHOLiC
FiNGAHOLiC / gist:1619358
Created January 16, 2012 06:15
Mediator Pattern
// 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;
@FiNGAHOLiC
FiNGAHOLiC / gist:1620926
Created January 16, 2012 13:41
Observer Pattern
// 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];
@FiNGAHOLiC
FiNGAHOLiC / gist:1639352
Created January 19, 2012 10:42
Decorator Pattern
// 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;
@FiNGAHOLiC
FiNGAHOLiC / gist:1639430
Created January 19, 2012 11:05
Iterator Pattern
// 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;
@FiNGAHOLiC
FiNGAHOLiC / gist:1661171
Created January 23, 2012 06:29
httphandler.py
#! /usr/bin/env python
# coding: utf-8
# 標準モジュールをimportする
import cgi
import os
class Request(object):
"""
HTTPのリクエストをハンドリングするクラス
@FiNGAHOLiC
FiNGAHOLiC / gist:1661204
Created January 23, 2012 06:39
rssparser.py
#! /usr/bin/env python
# coding: utf-8
from xml.etree.ElementTree import ElementTree
from urllib import urlopen
def parse_rss(url):
"""
RSS 2.0をパースして、辞書のリストを返す
"""
@FiNGAHOLiC
FiNGAHOLiC / gist:1661289
Created January 23, 2012 06:49
rssreader1.py
#! /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>
@FiNGAHOLiC
FiNGAHOLiC / gist:1661348
Created January 23, 2012 07:14
JS Coding Style
// http://www.beams.co.jp/catalog/2011winter/
(function(){
var hoge = {
_privateVariables : 'private',
publicValiables : 'public',
_privateMethod : function(){
return _privateVariables;
},
publicMethod : function(){
@FiNGAHOLiC
FiNGAHOLiC / gist:1661418
Created January 23, 2012 07:39
JS Coding Style
// 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 = {
@FiNGAHOLiC
FiNGAHOLiC / gist:1669332
Created January 24, 2012 09:52
Twitter OAuth by Python
#! /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'