Skip to content

Instantly share code, notes, and snippets.

View azami's full-sized avatar
🤢
お金がほしい!!!!!

az azami

🤢
お金がほしい!!!!!
  • japan
View GitHub Profile
@azami
azami / gist:6556281
Created September 13, 2013 21:24
SQLAlchemyのclassを動的に作成する。
classname = 'NewClass'
tablename = 'table'
session = scoped_session(sessionmaker(bind=engine))
classobj = Base._decl_class_registry.get(classname)
if classobj:
session.bind_table(classobj.__table__, engine)
return classobj
if tablename in Base.metadata.tables.keys():
Base.metadata.remove(Base.metadata.tables[tablename])
@azami
azami / gist:7174205
Created October 26, 2013 20:32
upstart php5-fpm
description "PHP FastCGI Process Manager"
kill signal INT
start on {net-device-up and local-filesystems}
stop on runlevel [016]
expect fork
respawn
exec /usr/sbin/php5-fpm
@azami
azami / gist:7174276
Created October 26, 2013 20:38
fizzbuzz
fizzbuzz = lambda num: ('fizz' if not num % 3 else '') + ('buzz' if not num % 5 else '')
@azami
azami / gist:7266061
Last active December 27, 2015 04:19
使えるかどうかわからないけどCtrl+Cで停止するmultiprocessing.Pool
import multiprocessing
import functools
def ignore_keyboard_interrupt(f):
@functools.wraps(f)
def wrapper(*args, **kwargs):
try:
return f(*args, **kwargs)
except KeyboardInterrupt:
@azami
azami / gist:9795349
Last active August 29, 2015 13:57
linux hhkb keyboard設定
# scancode
maki@marou:~> sudo showkey --scancodes
# key codes確認
maki@marou:~> xmodmap -pke
# USBのvendor id, product id検索
maki@marou:~> lsusb
Bus 002 Device 002: ID 05e3:0608 Genesys Logic, Inc. USB-2.0 4-Port HUB
maki@marou:/etc/fonts/conf.d> cat 40-nonlatin.conf
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<!--
Mark common families with their generics so we'll get
something reasonable
-->
<!--
@azami
azami / gist:b3940855a50366b095e6
Last active August 29, 2015 14:00
angularjs $httpProviderの設定
App.config(['$httpProvider',
function($httpProvider) {
$httpProvider.defaults.useXDomain = true;
$httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
$httpProvider.interceptors.push('myHttpResponseInterceptor');
$httpProvider.defaults.transformRequest = function(data) {
// $resourceを使用する場合はtypeを判定してfunction, objectを除く必要がある。
var params = {};
var i = 0;
if (data) {
@azami
azami / gist:3501bfaa3f579883edd1
Created May 15, 2014 07:08
ng-srcの値を取得したいときは、priorityを高くすると良い
app.directive('directiveName', function($location) {
return {
priority: 99,
link: function (scope, element, attrs) {
console.log(attrs);
}
};
});
@azami
azami / gist:050d4dc9e7e209208cb4
Last active August 29, 2015 14:01
angularjsのroute paramsにアクセスするときは$routeをつかう
when('/sample/:id', {
templateUrl: 'sample.html',
controller: 'sampleController',
resolve: {
media: function(resource, $route) {
return resource.get({id: $route.current.params.id});
}
}
}).
@azami
azami / gist:b63cd075850fabc0ca41
Last active August 29, 2015 14:01
jQueryでファイルのアップロード
var fd = new FormData();
fd.append('file', $('input[type=file]')[0].files[0]);
$.ajax({url: 'api/thread/' + thread + '/upload',
type: 'POST',
data: fd,
processData: false,
contentType: false
}).done(function() {
document.location.reload();
});