Skip to content

Instantly share code, notes, and snippets.

@yatt
yatt / appengine_sql.py
Created June 23, 2011 12:52
update/delete google appengine entity by sql like syntax
#! /usr/bin/env python
# coding: utf-8
#
# update/delete google appengine entity by sql like syntax...
#
# sample:
# - update
# noresult('update MyModel set name = \'hoge\', age = 10') # update all entities
# noresult('update MyModel set name = \'fuga\' where id = 10') # update entities which is specified in where clause
# * unavailable - multiple inequality filter property
@yatt
yatt / favstar_for_garapagos_phone.py
Created June 25, 2011 17:48
ガラケーでfavstar.fmのrecentを見る
#!/usr/bin/python2.6
# coding: utf-8
import cgi
import re
import urllib
from BeautifulSoup import BeautifulSoup as bs
def conv(txt):
lst = []
@yatt
yatt / Bezier.vb
Created October 21, 2011 10:33
IronPython - VB.NET Interoperation
Imports Microsoft.Scripting
Imports Microsoft.Scripting.Hosting
Imports IronPython.Hosting
Public Class Form1
Dim beziers As New List(Of Object)
Dim working As ArrayList = Nothing
Dim ctrls As New List(Of Point)
Dim index() As Integer = {-1, -1}
Dim focuses() As Integer = {-1, -1}
@yatt
yatt / toy.py
Created October 25, 2011 15:55
toy
# https://twitter.com/#!/mnzktw/status/128811724907360256
def to26(n): return n and (to26(n / 26) if n / 26 > 0 else []) + [n % 26] or [0]
def toA1(n): return ''.join(['ABCDEFGHIJKLMNOPQRSTUVWXYZ'[d if i == len(to26(n - 1)) - 1 else d-1] for i,d in enumerate(to26(n - 1))])
print map(toA1, [1, 10, 2000, 30000, 500000, 1000000]) # => ['A', 'J', 'BXX', 'ARIV', 'ABKPT', 'BDWGN']
@yatt
yatt / pypyStringComp.py
Created November 8, 2011 15:18
PyPy String Processing Comparison
#!/usr/bin/env pypy
from random import choice
from string import ascii_letters as ls
import time
import StringIO
try:
import __pypy__
except:
pass
@yatt
yatt / producer-consumer-problem.py
Created November 17, 2011 16:42
producer consumer problem
from multiprocessing import Queue as mQueue, Process
from multiprocessing.sharedctypes import Value
import ctypes
import time
import random
def consumer(i, q):
while True:
item = q.get()
if item is None:
@yatt
yatt / ftpd.py
Created December 10, 2011 03:58
simple ftp server
# ref: http://d.hatena.ne.jp/tasukuchan/20100420/how_to_use_pyftpdlib
from pyftpdlib import ftpserver
authorizer = ftpserver.DummyAuthorizer()
authorizer.add_user('user', 'password', './user', perm='elradfmw')
ftp_handler = ftpserver.FTPHandler
ftp_handler.authorizer = authorizer
address = ('localhost', 21)
ftpd = ftpserver.FTPServer(address, ftp_handler)
ftpd.serve_forever()
@yatt
yatt / deny.sh
Created January 15, 2012 14:26
lazy script for blocking against ssh attack
#!/bin/sh
tbl=deny.sqlite3
log=/var/log/auth.log
sqlite3 $tbl 'create table if not exists hosts (ipaddr varchar(255) primary key);'
for addr in $(grep Invalid $log | awk '{print $10}' | sort | uniq)
do
sqlite3 deny.sqlite3 "insert or ignore into hosts values ('$addr')"
done
@yatt
yatt / seq.sh
Created January 19, 2012 16:16
sort filenames with number (not aligned)
#!/bin/sh
# 桁揃えされていないファイル(ex. 1.jpg,...,10.jpg,...etc)
# を数値順に表示する。
#
/bin/ls -1 $1 \
| tee /tmp/ls.txt \
| egrep -o '[0-9]+' \
| awk '{printf("%010d\n",$_)}' \
| paste - /tmp/ls.txt \
| sort -k1 \
@yatt
yatt / dbjoin.py
Created January 22, 2012 11:15
練習:データベースのテーブル結合アルゴリズムのモデル実装。 inner loop/sort merge/semi join
job = set([
# id name
(1, 'animator'),
(2, 'blacksmith'),
(3, 'cook'),
(4, 'doctor'),
(5, 'engineer'),
(6, 'founder'),
(7, 'guitarist'),
])