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
@oinume
oinume / hello.ts
Last active August 29, 2015 13:56
A simple express application with TypeScript.
import express = require('express');
import http = require('http');
var app = express();
app.set('port', process.env.PORT || 3000);
app.get('/', function(req: express.Request, res: express.Response) {
res.send('Hello world!');
});
http.createServer(app).listen(app.get('port'), function() {
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Usage: tail -10000 <access_log> | ./parse-nginx-log.py
import os
import re
import sys
class LogParser(object):
@oinume
oinume / parse-apache-log.py
Last active December 24, 2015 17:39
Usage: tail -10000 <access_log> | ./parse-apache-log.py
#!/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]+)$""")

Untitled Slide

Welcome to Glide.

Glide is the easiest way to create useful slide for all of your Gists.

  • input key <- to go backward.
  • input key -> to go forward.

Publishing

#!/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 / web.xml
Created June 1, 2013 14:43
Jettyでシンボリックリンクを使えるようにする設定
<servlet>
<servlet-name>jetty</servlet-name>
<servlet-class>org.eclipse.jetty.servlet.DefaultServlet</servlet-class>
<init-param>
<param-name>aliases</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>
@oinume
oinume / capture.py
Created April 20, 2013 13:26
Capture stdout/stderr in Python
import cStringIO
import sys
class IOCapture(object):
def __init__(self, stdout = True, stderr = True):
self.captured_stdout = None
self.captured_stderr = None
if stdout:
self.captured_stdout = cStringIO.StringIO()
if stderr:
#!/bin/sh
set -x
export PYENV_ROOT=/usr/local/pyenv
cd /usr/local/
git clone https://github.com/yyuu/pyenv.git pyenv
cd pyenv/plugins
git clone https://github.com/yyuu/pyenv-virtualenv
_SHELL=$(basename $(echo $SHELL))
@oinume
oinume / pyenv.sh
Created April 10, 2013 05:10
/etc/profile.d/pyenv.sh $ . /etc/profile
#!/bin/sh
if [ -d /usr/local/pyenv/bin ]; then
pathmunge /usr/local/pyenv/bin
pathmunge /usr/local/pyenv/shims/
export PYENV_ROOT=/usr/local/pyenv
fi
@oinume
oinume / connect.rb
Created April 1, 2013 10:29
Connecting to MySQL with JRuby and JDBC.
require 'java'
require 'rubygems'
require 'dbi'
require 'dbd/Jdbc'
require 'jdbc/mysql'
Jdbc::MySQL.load_driver
DBI.connect(
'DBI:Jdbc:mysql://localhost/test',