Skip to content

Instantly share code, notes, and snippets.

@choplin
choplin / sake.py
Created November 10, 2011 18:35
一番酒が飲まれている言語を調べる
import urllib2
import chardet
from pyquery import PyQuery as pq
import re
import sys
base_url = 'http://togetter.com/li/212550'
more_url = 'http://togetter.com/api/moreTweets/212550?page='
def get_content(url):
@choplin
choplin / main.sql
Created December 1, 2011 12:18
Prime Factorization with SQL (Project Euler #3)
SELECT prime_factorization(600851475143);
-- prime_factorization
---------------------
{71,839,1471,6857}
(1 row)
@choplin
choplin / :messages
Created December 30, 2011 04:05
TweetVimのエラー
function tweetvim#timeline..tweetvim#request..<SNR>163_twibill..tweetvim#twibill#new の処理中にエラーが検出されました:
行 1:
E117: 未知の関数です: twibill#new
E15: 無効な式です: twibill#new(a:config)
行 5:
E121: 未定義の変数です: twibill
行 7:
E121: 未定義の変数です: a:param
E15: 無効な式です: a:param
行 9:
@choplin
choplin / inverse_fizzbuzz.hs
Created May 16, 2012 11:06
Inverse FizzBuzz implementation of Haskell
module Main where
data FizzBuzz = Fizz | Buzz | FizzBuzz deriving (Eq, Show)
type Pattern = (Int,[FizzBuzz])
patterns :: [Pattern]
patterns = [
(6,[Fizz,Fizz])
,(3,[Fizz,Buzz,Fizz,Fizz])
,(9,[Fizz,Buzz,Fizz,FizzBuzz])
@choplin
choplin / json_operator.sql
Created May 17, 2012 14:30
operator to json type in PostgreSQL with plv8
CREATE OR REPLACE FUNCTION json_access(obj json, path text) RETURNS json AS $$
var obj = JSON.parse(obj);
var paths = path.split(".");
var p;
var ret;
while (p = paths.shift()) {
if (typeof obj[p] == 'undefined'){
obj = null;
break
}
@choplin
choplin / include_img.rb
Created May 26, 2012 16:52
include image tag for jekyll(Octopress)
# Title: Include Image Tag for Jekyll
# Authors: choplin
# Description: Include <img> tag with src from a specified directory
# Configuration: as below in your _config.yml (images/blog as default)
#
# image_dir: images/blog
#
# Syntax {% include_img [class name(s)] image_file.(jpg|jpeg|png|gif) [width [height]] [title text | "title text" ["alt text"]] %}
#
# Examples:
@choplin
choplin / neko.rb
Created June 6, 2012 16:21
homebrew formula for nekovm, which install binary file downloaded from official page
require 'formula'
class Neko < Formula
url 'http://nekovm.org/_media/neko-1.8.2-osx.tar.gz'
homepage 'http://nekovm.org/'
md5 'd801e1e4bedd5c18fef2617ff5076253'
def install
prefix.install %w{include}
bin.install %w{neko nekoml nekotools nekoc}
@choplin
choplin / jsonp_proxy.pl
Created July 3, 2012 07:46
JSONP Proxy with Mojolicious::Lite
#!/usr/bin/perl
use strict;
use warnings;
use utf8;
use feature ':5.10';
use Encode;
use Mojolicious::Lite;
use XML::Simple;
use JSON::Any;
@choplin
choplin / out_msgpack_rpc.rb
Created July 30, 2012 09:05
Fluent output plugin for MessagePack RPC
module Fluent
class MessagePackRPCOutput < Fluent::BufferedOutput
Fluent::Plugin.register_output('msgpack_rpc', self)
config_param :host , :string , :default => 'localhost'
config_param :port , :integer
config_param :method , :string
config_param :unit , :string , :default => 'chunk'
@choplin
choplin / msgpack.py
Created August 1, 2012 09:15
With python-msgpack, array is converted to tuple through pakcing/unpacknig process
import msgpack
b = msgpack.packb([1,2,3])
print msgpack.unpackb(b) # => (1, 2, 3)