Skip to content

Instantly share code, notes, and snippets.

@tomotaka
tomotaka / json_matcher.rb
Created August 14, 2012 16:00
recursive regexp pattern for JSON
# coding: utf-8
# only works on 1.9+
# base idea is from:
# - http://stackoverflow.com/questions/2583472/regex-to-validate-json
# - http://www.slideshare.net/takesako/shibuyapm16-regexpjsonvalidator
module JsonMatcher
NUMBER = /-? (?= [1-9]|0(?!\d) ) \d+ (\.\d+)? ([eE] [+-]? \d+)?/x
BOOLEAN = /true | false | null/x
# This command helps you to create pyenv virtualenv and activate that after creation.
# NOTE: I checked this works on zsh
vec() {
PWD=`pwd`
DNAME=`basename $PWD`
pyenv virtualenv 3.7.3 $DNAME
pyenv local $DNAME
}
@tomotaka
tomotaka / seitekidouteki.md
Last active June 4, 2018 08:02
静的型言語 vs 動的型言語

静的型 vs 動的型

※個人の見解です!!

静的片付け言語のいいところ

  • コード自体の情報量が多い
    • ドキュメントの自動生成が楽(少ないドキュメンテーション作業で質の高いドキュメントが作れる)
    • エディタ/IDEの自動補完をより強力にすることができる
  • 実行するまでもなく様々なことがコンパイル時に検査される
  • 実行速度が速い(言語が多い)
@tomotaka
tomotaka / bottleurl.py
Created June 4, 2016 01:51
get url, query string, path in bottle
import bottle
from wsgiref import simple_server
b = bottle.Bottle()
def test():
path = bottle.request.path
urlargs = bottle.request.url_args
query_string = bottle.request.query_string
url = bottle.request.url
return 'your path = %s, urlargs=%s, qs=%s, url=%s' % (path, urlargs, query_string, url)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#!/bin/sh
curl https://bootstrap.pypa.io/ez_setup.py -o /tmp/ez_setup.py
# install easy_install
python /tmp/ez_setup.py
# install pip
easy_install pip
@tomotaka
tomotaka / orelang.py
Last active October 6, 2016 06:13
orelang python impl
# -*- coding: utf-8 -*-
# orelang: http://qiita.com/shuetsu@github/items/ac21e597265d6bb906dc
# dependency: click
import os
import os.path
import sys
import json
import click
@tomotaka
tomotaka / urlshortener.py
Created December 16, 2013 10:18
mongo-based url shorten service engine
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# requirements: pip install mongoengine simplejson bottle
import mongoengine
import string
from bottle import (
route, run, HTTPResponse, request
)
import simplejson
@tomotaka
tomotaka / cssdatauriexpander.py
Last active December 31, 2015 05:29
expanding url(./img/hoge.png) => url(data:image/png;....) with filesystem-based caching
import re
import base64
import hashlib
import os.path
import gevent.fileobject as gfo
def _read_file(filepath):
fh = open(filepath, 'rb')
gfh = gfo.FileObject(fh, 'rb')
ret = gfh.read()
@tomotaka
tomotaka / mongocounter.py
Created October 3, 2013 10:17
cache-enabled counter using MongoDB's '$inc' operator
#!/usr/bin/python
# -*- coding: utf-8 -*-
import time
import math
__all__ = ('MongoCounterError', 'MongoCounter')
class MongoCounterError(Exception):
pass