Skip to content

Instantly share code, notes, and snippets.

View tokibito's full-sized avatar

Shinya Okano tokibito

View GitHub Profile
>>> from django.utils import translation
>>> ja = translation._trans.translation('ja')
>>> print ja.ugettext('Yes')
はい
@tokibito
tokibito / a.py
Last active August 29, 2015 13:56
from sqlalchemy import Table, Column, Integer, String, MetaData, ForeignKey
from sqlalchemy.orm import sessionmaker
Session = sessionmaker()
session = Session()
metadata = MetaData()
table1 = Table('table1', metadata,
Column('id', Integer, primary_key=True),
Column('name', String),
C:\Users\tokibito>tracert cloud-images.ubuntu.com
cloud-images.ubuntu.com [91.189.88.141] へのルートをトレースしています
経由するホップ数は最大 30 です:
1 <1 ms <1 ms <1 ms 192.168.100.1
2 2 ms 3 ms 2 ms nas82b.p-tokyo.nttpc.ne.jp [210.153.249.79]
3 2 ms 2 ms 2 ms 210.153.249.121
4 3 ms 3 ms 3 ms 210.153.249.161
5 3 ms 2 ms 2 ms 210.165.252.245
@tokibito
tokibito / Unit1.pas
Created October 12, 2013 04:56
WebView使いたい
unit Unit1;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Rtti, System.Classes,
System.Variants, FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs,
FMX.StdCtrls, Macapi.CocoaTypes, Macapi.Foundation, Macapi.AppKit,
Macapi.ObjectiveC, FMX.Platform.Mac;
@tokibito
tokibito / gist:6446643
Created September 5, 2013 06:18
sqlite3 group_concat
sqlite> select k,v from test;
a|10
a|20
b|5
b|15
sqlite> select k,group_concat(v) from test group by(k);
a|10,20
b|5,15
@tokibito
tokibito / gist:6386611
Created August 30, 2013 05:38
pprint and vars
>>> class MyClass(object):
... def __init__(self, x, y):
... self.x = x
... self.y = y
... self.foo = {'foo': {'bar': 'hoge'}}
... self.ref = self
...
>>> obj = MyClass(10, 20)
>>> vars(obj)
{'y': 20, 'x': 10, 'foo': {'foo': {'bar': 'hoge'}}, 'ref': <__main__.MyClass object at 0x025E46D0>}
DATA = [
{'number': 2, 'name': 'b'},
{'number': 1, 'name': 'a'},
{'number': 4, 'name': 'd'},
]
def make_table(lst, key_func=lambda v: v):
table = {}
for value in lst:
DATA = [
{'number': 2, 'name': 'b'},
{'number': 1, 'name': 'a'},
{'number': 4, 'name': 'd'},
]
class Picker(object):
def __init__(self, lst, key_func=lambda v: v):
self.lst = lst
@tokibito
tokibito / json_to_object.py
Last active December 15, 2015 21:19
object_hook parameter for json module.
# coding: utf-8
import json
DATA = """
{
"attr1": "foo",
"attr2": "bar",
"_class": "Foo",
"attr3": {
"attr3_1": "spam",
"set guifont=MS_ゴシック:h10
set guifont=VL_ゴシック:h10
set lines=40
set columns=140
set guioptions-=T
set guioptions-=m