Skip to content

Instantly share code, notes, and snippets.

job.setOutputFormatClass(classOf[TextOutputFormat]) // エラー
job.setOutputFormatClass(classOf[TextOutputFormat[Text, Text]]) // OK
DROP FUNCTION eval(text);
CREATE FUNCTION eval(sql Text) RETURNS SETOF Record AS $$
BEGIN
RETURN QUERY EXECUTE sql;
RETURN;
END;
$$ LANGUAGE plpgsql;
SELECT * FROM eval('SELECT * FROM( VALUES (1,''a''), (3,''b'') ) AS t') AS (i Int, c Text);
nnoremap <buffer> <SID>[ghcmod] <Nop>
nmap <buffer> <Leader>h <SID>[ghcmod]
nnoremap <buffer> <silent> <SID>[ghcmod]y :<C-u>call <SID>paste_type_signature()<CR>
function! s:paste_type_signature()
try
let signature = expand('<cword>').' :: '.ghcmod#type()[1]
catch
return
endtry
call textobj#user#plugin('rubyexpr', {
\ '-': {
\ '*pattern*': ['#{', '}'],
\ 'select-a': 'a#',
\ 'select-i': 'i#',
\ },
\ })
@choplin
choplin / process_pool.rb
Created August 21, 2012 15:14
Process Pool in Ruby
require 'msgpack'
require 'thread'
class ProcessPool
def initialize(num_process, args={})
queue_size, worker_class = parse_args([
:queue_size, nil,
:worker_class, Worker,
], args)
nnoremap <SID>[tweetvim] <Nop>
nmap <Leader>t <SID>[tweetvim]
nnoremap <silent> <SID>[tweetvim]s :<C-u>TweetVimSay<CR>
nnoremap <silent> <SID>[tweetvim]t :<C-u>call <SID>tweetvim_open('TweetVimHomeTimeline')<CR>
nnoremap <silent> <SID>[tweetvim]m :<C-u>call <SID>tweetvim_open('TweetVimMentions')<CR>gnmgn
function! s:check_tweetvim_buffer()
let bufnlist = tabpagebuflist()
for num in bufnlist
if getbufvar(num, '&filetype') ==# 'tweetvim'
@choplin
choplin / fizzbuzz.sql
Created August 9, 2012 08:53
fizzbuzz with SQL (imcomplete)
CREATE OR REPLACE FUNCTION fizzbuzz(num Int) RETURNS SETOF Text AS $$
WITH RECURSIVE
fizz(f) AS (
SELECT ARRAY[NULL,NULL,'fizz']
)
,buzz(b) AS (
SELECT ARRAY[NULL,NULL,NULL,NULL,'buzz']
)
,fizzbuzz(fb) AS (
SELECT
require 'msgpack/rpc'
c = MessagePack::RPC::Client.new('localhost',9090)
c.call(:print, 'hello') #=> サーバー側に'hello'が表示される
c.notify(:print, 'hello') #=> 何も起きない
@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)
@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'