Skip to content

Instantly share code, notes, and snippets.

@jbking
jbking / gist:5010252
Last active May 13, 2023 11:11
How to get engine specific creating table DDL in SQLAlchemy.
In [1]: from sqlalchemy import create_engine
In [2]: postgresql_engine = create_engine('postgresql://')
In [3]: mysql_engine = create_engine('mysql://')
In [4]: from myapp.resources import Event
In [5]: from sqlalchemy.schema import CreateTable

MacBook Pro Retina Mid 2012にPyTorchをGPU付きでセットアップするまで

これは

以前のMBPではNVIDIAのGPUが搭載されていました。 そのうちの一つがMBP Retina Mid 2012です。この機種にはNVIDIAのGeForce GT 650Mが搭載されており、CUDA Capability3.0と今となっては古いながらもCUDAが動作するようでした。 昨今GPUといえばGPGPU、とにもかくにも機械学習ということでPyTorchをGPUで動かせるか?ということを調べました。

結果

@jbking
jbking / aquaskk.json
Last active July 24, 2018 06:29
my configuration of Karabiner-Elements for AquaSKK(refs: https://pqrs.org/osx/karabiner/json.html)
{
"title": "AquaSKK",
"rules": [
{
"description": "Ctrl-J to Kana on Apple Terminal/iTerm2",
"manipulators": [
{
"type": "basic",
"from": {
"key_code": "j",
@jbking
jbking / tiny virtualenvwrapper vim plug-in
Created February 1, 2011 10:16
add your virtualenv's site-packages to vim python. then you can use vim python with modules of the site-packages.
function! Workon(name)
" Get virtualenv's site-packages directory.
let b:virtualenv_sitepackages_dir = system('workon ' . a:name . '; cdsitepackages; echo -n $PWD')
python << EOM
import vim
import sys
virtualenv_sitepackages_dir = vim.eval('b:virtualenv_sitepackages_dir')
if virtualenv_sitepackages_dir not in sys.path:
@jbking
jbking / passing_queue_like_go.py
Last active January 4, 2016 04:39
The object for IPC couldn't be passed to another process which is able to pass to another goroutine in golang. Interchanging such object in golang is not actual IPC, but its design could be similar, for similar usage.
% python passing_queue_like_go.py
Traceback (most recent call last):
File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/queues.py", line 266
, in _feed
send(obj)
File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/queues.py", line 77,
in __getstate__
assert_spawning(self)
File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/forking.py", line 52
, in assert_spawning
@jbking
jbking / missing_appear.py
Created November 29, 2012 13:50
find coverage missing appeared in latest commit.
from __future__ import print_function
import os
import sys
import pygit2
import coverage
def collect_addition(hunk):
result = []
@jbking
jbking / kill_children_process.py
Created November 13, 2011 07:32
kill children process recursively.
import os
import subprocess
def kill_children_process(pid, force=False):
pid = int(pid)
for line in subprocess.check_output(
'/bin/ps -eo "ppid pid"',
shell=True).split('\n')[1:]:
line = line.strip()
@jbking
jbking / setup_virtualenv.sh
Created October 28, 2011 11:27
Setup a virtalenv for Google Appengine.
#!/bin/sh # -x
function usage {
echo "Usage: $0 python_path virtualenv_path"
echo "Setup a virtalenv for Google Appengine."
echo ""
echo "python_path Path to the Python interpreter used to the virtualenv."
echo "virtualenv_path Path to the target virtualenv."
exit
}
nnoremap <expr> / ':<C-u>Unite -start-insert -buffer-name="search-' . buffer_number('%') . '" line<CR>'
nnoremap <expr> * ':<C-u>UniteWithCursorWord -buffer-name="search-' . buffer_number('%') . '" line<CR>'
nnoremap <expr> n ':<C-u>UniteResume -no-start-insert -buffer-name="search-' . buffer_number('%') . '"<CR>'
@jbking
jbking / gist:998517
Created May 30, 2011 06:28
Generate simple year month list
# -*- coding:utf-8 -*-
from datetime import date
class YearMonth(object):
""" List year/month from specified to today """
def __init__(self, year, month, format='%Y/%m'):
self.year = year
self.month = month
self.format = format