Skip to content

Instantly share code, notes, and snippets.

View norioxkimura's full-sized avatar

Norio Kimura norioxkimura

View GitHub Profile
import sys
def e(a, b, px, py, d=0):
print(" " * d, f"e({a}, {b}, {px[1]}, {py[1]})")
if b == 0:
px[0] = 1
py[0] = 0
print(" " * d, f"{px[1]} <- 1, {py[1]} <- 0")
import colorsys
print "<style>"
for i in xrange(30):
h = 1.0 / 10 * (i % 10)
if i / 10 == 0:
s = 0.12
v = 1.0
elif i / 10 == 1:
import logging
def main():
class Filter(object):
def filter(self, record):
msg = record.getMessage()
a = msg.startswith("Calling ") and msg.endswith(':Basic.GetEmpty"')
b = msg.startswith("Processing ") and msg.endswith(":Basic.GetEmpty")
return not (a or b)
logging.basicConfig(level= logging.DEBUG)
@norioxkimura
norioxkimura / EvernoteOAuthHandler.scala
Last active December 14, 2015 23:48
Evernote OAuth using Play2 OAuth library
object EvernoteOAuthHandler extends Controller {
val KEY = ConsumerKey("xxx", "yyyzzz")
val EVERNOTE = OAuth(ServiceInfo(
"https://sandbox.evernote.com/oauth",
"https://sandbox.evernote.com/oauth",
"https://sandbox.evernote.com/OAuth.action",
KEY))
def authenticate(callbackUrl: String) = Action { implicit request =>
@norioxkimura
norioxkimura / rdate.min.py
Created February 1, 2013 01:56
最新順でソートされる年月日(日付)表現を生成するPythonワンライナー
from datetime import datetime; (lambda dt: (lambda y, m, d, *_: "%2d%s%2d" % (2099 - y, "ABCDEFGHIJKL"[12 - m], 99 - d))(*dt.timetuple()))(datetime.today())
@norioxkimura
norioxkimura / myapp.py
Last active December 11, 2015 11:38
Bottle 利用時のテスト
from bottle import route, run, default_app
@route("/")
def index():
return "Hello"
if __name__ == "main":
run()
@norioxkimura
norioxkimura / gist:3878008
Created October 12, 2012 08:24
Scala casbah mongoDB
val mongo_article = mongo_articles.findOne(MongoDBObject("_id" -> new ObjectId(vector(i)._1))).getOrElse(null)
println(mongo_article.getAs[String]("title").getOrElse(null))
@norioxkimura
norioxkimura / authhacks.models.py
Created June 15, 2012 05:48
Django の auth の User モデルの username の最大長を変更するハック
from django.conf import settings
from authhacks import username_length
USERNAME_MAXLENGTH = getattr(settings, 'USERNAME_MAXLENGTH', 75)
username_length.hack_models(USERNAME_MAXLENGTH)
username_length.hack_forms(USERNAME_MAXLENGTH)
@norioxkimura
norioxkimura / gist:2716249
Created May 17, 2012 04:10
libvirt config xml for --network='bridge=br0'
<interface type='bridge'>
<mac address='52:54:00:39:0e:db'/>
<source bridge='br0'/>
<model type='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>
@norioxkimura
norioxkimura / arg.py
Created April 30, 2012 14:54
argparse: exclusive options and variable number of arguments
import argparse
import sys
parser = argparse.ArgumentParser()
g = parser.add_mutually_exclusive_group(required= True)
g.add_argument('--a', action= 'store_const', const='a', dest= 'subcommand')
g.add_argument('--b', action= 'store_const', const='b', dest= 'subcommand')
parser.add_argument('bar', nargs= '*')
print parser.parse_args(sys.argv[1:])