Skip to content

Instantly share code, notes, and snippets.

7つの言語 7つの世界 のセルフスタディで書いたコード。
@inoshiro
inoshiro / create_list.py
Created January 21, 2012 08:11
create twitter list from connpass event
>>> import from_connpass
>>> content = from_connpass.getContent("http://connpass.com/event/213/")
>>> users = from_connpass.getidlist(content)
OUT: get id: tmae
OUT: get id: noguchi616
OUT: get id: th0x0472
# 長いので省略
OUT: get id: utsuidai
OUT: get id: n0ts
OUT: get id: matetsu
@inoshiro
inoshiro / detect_face.py
Created June 24, 2012 10:30
OpenCVのチュートリアルをPythonでやってみた http://gihyo.jp/dev/feature/01/opencv
import cv
imgfile = '../data/members.jpeg'
im = cv.LoadImage(imgfile, 1)
cascade = cv.Load('../data/haarcascade_frontalface_default.xml')
faces = cv.HaarDetectObjects(im, cascade, cv.CreateMemStorage())
for f in faces:
cv.Rectangle(im,
(f[0][0], f[0][1]),
(f[0][0]+f[0][2], f[0][1]+f[0][3]),
cv.CV_RGB(255, 0, 0),
@inoshiro
inoshiro / git-push.py
Created February 9, 2013 08:01
git pushにhookを提供する。リポジトリの .git/hooks に pre-push か post-push が実行ファイルとして置いてあれば実行する
#!/usr/bin/env python
#coding: utf-8
import os
import subprocess
import sys
PRE_PUSH_SCRIPT = 'pre-push'
POST_PUSH_SCRIPT = 'post-push'
@inoshiro
inoshiro / djanto-factory_boy.py
Created February 22, 2013 09:01
factory_boyどうやって使うのかいまいち分からない
from django.test import TestCase
from . import models
import factory
class PollFactory(factory.Factory):
FACTORY_FOR = models.Poll
question = "What's up?"
pub_date = '2013-02-22'
@inoshiro
inoshiro / admin.py
Last active January 17, 2017 12:08
Djangoのadminのカスタマイズ例(search/sort/pagination)
from django.contrib import admin
from .models import Memo
class MemoAdmin(admin.ModelAdmin):
list_per_page = 5
list_display = ['username', 'title']
search_fields = ['user__username']
def queryset(self, request):
qs = super(MemoAdmin, self).queryset(request)
>>> from django import forms
>>> class CommentForm(forms.Form):
... name = forms.CharField(initial='class')
...
>>> f = CommentForm()
>>> print(f)
<tr><th><label for="id_name">Name:</label></th><td><input type="text" name="name" value="class" id="id_name" /></td></tr>
>>> f.fields['name'].initial
'class'
@inoshiro
inoshiro / deco.py
Last active December 18, 2015 11:59
In [1]: def deco(arg):
...: def wrapper(func):
...: def _wrapper():
...: return func(arg)
...: return _wrapper
...: return wrapper
...:
In [2]: @deco("ham")
...: def spam(egg):
@inoshiro
inoshiro / dec_hirokiky.py
Created April 1, 2014 02:28
hirokiky-- script
import requests
payload = {'stuff': 'hirokiky', 'action': 'dec'}
url = 'http://karmaid.org/api/karma'
while True:
requests.post(url, params=payload)
@inoshiro
inoshiro / dev_machine_task.yml
Last active August 29, 2015 14:05
PyCharmのプロジェクトをこんな感じで作りたい
- name : 'setup pycharm project'
pycharm_project : project_dir={{item.project_dir}} venv={{item.venv}} additional_dir={{item.additional_dir}}
with_items:
- { project_dir='~/projects/openstack_havana_nova' venv='~/.virtualenv/openstack_havana_nova' additional_dir='~/repos/openstack_havana/nova' }
- { project_dir='~/projects/openstack_havana_neutron' venv='~/.virtualenv/openstack_havana_neutron' additional_dir='~/repos/openstack_havana/neutron' }