Skip to content

Instantly share code, notes, and snippets.

View oinume's full-sized avatar
🏠
Working from home

oinume oinume

🏠
Working from home
View GitHub Profile
#!/usr/bin/env perl
use strict;
use warnings;
use Getopt::Compact;
use Data::Dumper;
my $getopt = Getopt::Compact->new(
name => 'mygzip',
modes => [ qw(verbose) ],
@oinume
oinume / to_innodb.py
Created February 21, 2011 11:02
Convert all tables to InnoDB
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# INSTALL ====================
# $ sudo easy_install argparse
# $ sudo easy_install mysql-python
import argparse
import MySQLdb
import os
@oinume
oinume / StringBuilder_VS_StringFormat.java
Created September 4, 2011 13:40
Benchmark to concat strings with StringBuilder#append() and String.format()
package net.lampetty.samples;
/**
* StringBulder V.S. String.format to concat strings.
*/
public class StringBuilder_VS_StringFormat {
public static void main(String[] args) {
new StringBuilder_VS_StringFormat().run(args);
}
@oinume
oinume / config.py
Created September 10, 2011 15:59
Flask + python-oauth2 + python-twitter sample
# app/config.py
# -*- coding: utf-8 -*-
import os
class Config(object):
DEBUG = False
SQLALCHEMY_ECHO = False
SECRET_KEY = 'dev_key_h8hfne89vm'
CSRF_ENABLED = True
CSRF_SESSION_LKEY = 'dev_key_h8asSNJ9s9=+'
@oinume
oinume / kwargs.py
Created December 3, 2011 06:48
**つけるとdictオブジェクトをキーワード引数に変換できる
def f(**kwargs):
for k, v in kwargs.iteritems():
print "%s => %s" % (k, v)
f(**{ 'key1': 'value1', 'key2': 'value2' })
# output:
# key2 => value2
# key1 => value1
@oinume
oinume / capture.py
Created May 20, 2012 08:52
Capture stdout in Python
import cStringIO
import sys
class StdoutCapture(object):
def __init__(self):
self.captured = cStringIO.StringIO()
def start(self):
sys.stdout = self.captured
return self
@oinume
oinume / install_rvm.sh
Created June 15, 2012 16:19
install_rvm.sh
#!/bin/sh
set -eux
sudo apt-get -y install curl git-core bzip2 build-essential zlib1g-dev libssl-dev
curl -L get.rvm.io | sudo bash -s stable
sudo su -
[ -f /etc/profile.d/rvm.sh ] && . /etc/profile.d/rvm.sh
RUBY_VERSION=ruby-1.9.3-p194
rvm install $RUBY_VERSION
@oinume
oinume / parse_apache_log.py
Created October 11, 2012 11:26
Parsing apache log file and summarize request time.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Usage: tail -10000 <access_log> | ./parse_apache_log.py
import os
import re
import sys
class LogParser(object):
LOG_PATTERN = re.compile(r"""^(?P<remote_host>[0-9]{,3}\.[0-9]{,3}\.[0-9]{,3}\.[0-9]{,3}) (?P<ident>[^ ]{1,}) (?P<remote_user>[^ ]{1,}|\-) \[(?P<datetime>[0-9]{2}\/[A-Za-z]{3}\/[0-9]{1,4}:[0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2} [+\-][0-9]{4})\] "(?P<method>[A-Z ]+) (?P<uri>[^"]*) (?P<protocol>[^"]*)" (?P<status>[0-9]{3}) (?P<bytes>[0-9]{1,}|\-) "(?P<referer>[^"]*|\-)" "(?P<user_agent>[^"]+)" (?P<elapsed>[\d]+)$""")
@oinume
oinume / User.java
Created November 13, 2012 16:02
FreeMarkerで余計な改行が入ってしまう例
package jp.ameba.picnic.orm.microbookmark.entity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.metamodel.StaticMetamodel;
@oinume
oinume / entity.ftl
Created November 13, 2012 16:19
FreeMarkerで余計な改行が入ってしまうftl例(最初の段階)
package ${packageName};
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity