Skip to content

Instantly share code, notes, and snippets.

import time
import multiprocessing
import memcache
key = 'foo'
process = 100
count = 1000
def f():
mc = memcache.Client(['127.0.0.1:11212'])
import os.path
import markdown
HTML = """
<html>
<head>
<style type="text/css">
<!--
body {
font-family: Halvetica, sans-serif;
import scrapemark # http://arshaw.com/scrapemark/
scrapemark.user_agent = 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)'
pattern = '<div id="topicsfb">{*<li>{{[]}}</li>*}</div>'
for i in scrapemark.scrape(pattern, url='http://www.yahoo.co.jp/'):
print i
@hikoz
hikoz / MocksRegistry.java
Created October 28, 2010 07:03
targetsに作りたい型を放り込んでおけばMockitoがMockを作ってSpringに登録してくれる
import org.mockito.Mockito;
import org.springframework.beans.BeansException;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.PropertyValue;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
@hikoz
hikoz / dd.py
Created December 15, 2010 04:45
dd with progress in python
#!/usr/bin/env python
import sys
import time
import signal
from subprocess import Popen, PIPE
dd = Popen(['dd'] + sys.argv[1:], stderr=PIPE)
while dd.poll() is None:
time.sleep(.3)
dd.send_signal(signal.SIGUSR1)
@hikoz
hikoz / excelcol.py
Created November 4, 2011 05:59
Excel列名変換をPythonで
def col2row(col):
"""
>>> col2row('B')
2
>>> col2row('Z')
26
>>> col2row('AA')
27
>>> col2row('AZ')
@hikoz
hikoz / excelcol.clj
Created November 4, 2011 06:00
Excel列名変換をClojureで
(defn pow [^long m ^long n]
(apply * (repeat n m)))
(defn ^long col2row [^String col]
(apply + (map-indexed (fn [i c] * (- (int c) 64) (pow 26 i))
(reverse col))))
(defn ^String row2col [^long row]
(let [n (mod (- row 1) 26)
@hikoz
hikoz / gist:1350905
Created November 9, 2011 09:06
tmux.conf
set-option -g prefix C-t
unbind-key C-b
bind C-r source-file ~/.tmux.conf
set-window-option -g mode-keys vi
bind -r C-h resize-pane -L 6
bind -r C-l resize-pane -R 6
bind -r C-j resize-pane -D 6
bind -r C-k resize-pane -U 6
bind -r s swap-pane -U
@hikoz
hikoz / gist:2701515
Created May 15, 2012 12:51
request parameter
function getParams() {
var params = {}
var h = location.href.replace(/^.*\?/, '').split('&')
for (var i = 0; i < h.length; ++i) {
var p = h[i].split('=')
params[p[0]] = p[1];
}
return params;
}
@hikoz
hikoz / Echo.scala
Created May 19, 2012 08:19
finagle failover
import java.net.InetSocketAddress
import org.jboss.netty.channel.ChannelPipelineFactory
import org.jboss.netty.channel.Channels
import org.jboss.netty.handler.codec.frame.DelimiterBasedFrameDecoder
import org.jboss.netty.handler.codec.frame.Delimiters
import org.jboss.netty.handler.codec.string.StringDecoder
import org.jboss.netty.handler.codec.string.StringEncoder
import org.jboss.netty.util.CharsetUtil
import com.twitter.finagle.builder.ClientBuilder