Skip to content

Instantly share code, notes, and snippets.

View kijun's full-sized avatar
🔮
🧙‍♀️

Kijun Seo kijun

🔮
🧙‍♀️
View GitHub Profile
@kijun
kijun / url_dsl.rb
Created December 28, 2009 12:56 — forked from defunkt/url_dsl.rb
require 'open-uri'
# url dsl -- the ultimate url dsl!
#
# You just can't beat this:
#
# $ irb -r url_dsl
# >> include URLDSL
# => Object
# >> http://github.com/defunkt.json
@kijun
kijun / echo.c
Created December 29, 2009 07:00 — forked from paulsmith/echo.c
/**
* A simple preforking echo server in C.
*
* Building:
*
* $ gcc -Wall -o echo echo.c
*
* Usage:
*
* $ ./echo
# If your workers are inactive for a long period of time, they'll lose
# their MySQL connection.
#
# This hack ensures we re-connect whenever a connection is
# lost. Because, really. why not?
#
# Stick this in RAILS_ROOT/config/initializers/connection_fix.rb (or somewhere similar)
#
# From:
# http://coderrr.wordpress.com/2009/01/08/activerecord-threading-issues-and-resolutions/
package org.apache.lucene.analysis;
import java.io.IOException;
import java.io.Reader;
import org.apache.lucene.analysis.tokenattributes.OffsetAttribute;
import org.apache.lucene.analysis.tokenattributes.TermAttribute;
import org.apache.lucene.util.AttributeSource;
/**
package org.apache.lucene.analysis;
import java.io.IOException;
import org.apache.lucene.analysis.tokenattributes.TermAttribute;
/**
* Removes words that are too long or too short from the stream.
*/
public final class LengthFilter extends TokenFilter {
irb(main):001:0> require 'open-uri'
=> true
irb(main):002:0> require 'nokogiri'
=> true
irb(main):003:0> f = open('http://211.254.102.90/web').read
=> "<html><head><title>\xBB\xF5\xB7\xCE\xBF\xEE \xBC\xBC\xBB\xF3\xC0\xBB \xBF\xA9\xB4\xC2 \xB9\xAE, G\xB8\xB6\xC4\xCF</title><meta http-equiv='Content-Type' content='text/html; charset=euc-kr'>\n</head>\n</body>\n</html>\n"
irb(main):011:0> Nokogiri::HTML(f).encoding
=> "euc-kr"
irb(main):012:0> Nokogiri::HTML(f).meta_encoding
=> "euc-kr"
@kijun
kijun / google-reader-current-article.js
Created January 18, 2011 05:45
Google Reader Current Article Bookmarklet
<a href="javascript:var curp = 'id(\'current-entry\')'; var titlep = curp + '//h2[@class=\'entry-title\']/text()'; var hostp = curp + '//span[@class=\'entry-source-title\']/text()'; var urlp = curp + '//a[@class=\'entry-original\']/@href'; function xpath(x) { var r; try { r=document.evaluate(x,document,null,0,null); switch(r.resultType) { case 1:r=r.numberValue;break; case 2:r=r.stringValue;break; case 3:r=r.booleanValue;break; case 4:var n=r,r=[],e;while(e=n.iterateNext())r.push(e);break; } } catch(ex){r=ex.message;} return r; } function parse() { var text = xpath(titlep)[0].nodeValue; text += '\nfrom '+xpath(hostp)[0].nodeValue; text += '\n['+xpath(urlp)[0].nodeValue+']'; alert(text); } parse();">Current Article</a>
@kijun
kijun / sqltypes.py
Created January 20, 2011 05:23
Useful sqlalchemy custom types
import json
import sqlalchemy.types
class JSONType(sqlalchemy.types.PickleType):
"""An example
>>> class User(declarative_base):
... friends = Column(JSONType())
...
@kijun
kijun / sqltypes.py
Created January 20, 2011 05:23
Useful sqlalchemy custom types
import json
import sqlalchemy.types
class JSONType(sqlalchemy.types.PickleType):
"""An example
>>> class User(declarative_base):
... friends = Column(JSONType())
...
@kijun
kijun / gist:3308709
Created August 9, 2012 22:41
psudocode for generic operation transform
# From "Real-Time Cooperative Editing Systems", Chengzheng Sun et al.
import copy
def generic_operation_transform(new_op, HB):
"""
:param new_op: operation to be transformed
:param HB: history buffer
"""
# index of independent ops