Skip to content

Instantly share code, notes, and snippets.

require 'msgpack/rpc'
c = MessagePack::RPC::Client.new('localhost',9090)
c.call(:print, 'hello') #=> サーバー側に'hello'が表示される
c.notify(:print, 'hello') #=> 何も起きない
@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
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 / 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)
call textobj#user#plugin('rubyexpr', {
\ '-': {
\ '*pattern*': ['#{', '}'],
\ 'select-a': 'a#',
\ 'select-i': 'i#',
\ },
\ })
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
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);
job.setOutputFormatClass(classOf[TextOutputFormat]) // エラー
job.setOutputFormatClass(classOf[TextOutputFormat[Text, Text]]) // OK
@choplin
choplin / impala.rb
Created November 16, 2012 04:16
chef recipe for impala
yum_key "Impala-GPG-KEY" do
url "http://beta.cloudera.com/impala/redhat/6/x86_64/impala/RPM-GPG-KEY-cloudera"
action :add
end
yum_repository "Impala" do
url "http://beta.cloudera.com/impala/redhat/6/x86_64/impala/0/"
gpg "Impala-GPG-KEY"
action :add
end
scala> import org.fluentd.logger.scala.FluentLoggerFactory
import org.fluentd.logger.scala.FluentLoggerFactory
scala> val l = FluentLoggerFactory.getLogger("debug")
l: org.fluentd.logger.scala.FluentLogger = org.fluentd.logger.FluentLogger{tagPrefix=debug,sender=localhost_24224_3000_1048576}
scala> l.log("hoge", Map("a" -> 1))
<console>:12: error: overloaded method value log with alternatives:
(label: String,data: scala.collection.immutable.Map[String,java.lang.Object])Boolean <and>
(label: String,data: scala.collection.mutable.Map[String,java.lang.Object])Boolean