2013-01-01から1年間の記事一覧

今自分が行きたくない会社No.1はグのつく会社

誘われないけれど誘われても行きたくない会社、今個人ランキング一位のはグのつく会社。後々評価は変わるのかもしれないけれども、今この瞬間の気持ちを記録しておかないと。この気持ちをどの方向への活力に転換するのか悩むところ、、、でもかなりの推進力…

One liner for quick sort in Python

print (lambda a:len(a)>1 and sum([(type(lambda: 0)(__import__('sys')._getframe().f_code, globals()))(filter(lambda x:x<a[0], a[1:])), [a[0]], (type(lambda: 0)(__import__('sys')._getframe().f_code, globals()))(filter(lambda x:x>a[0], a[1:]))], []) or a)([2,4,1,5,631,74,96,47,63,44,21,14,5,70,7,9,7,44…</a[0],>

Pythonでワンライナー再帰できたー!! (Recursive as one liner in Python)

(lambda x: x==1 and 1 or x + type(lambda: 0)(__import__('sys')._getframe(0).f_code, globals())(x-1))(10) めっさ大変だったー。。。

iOSの(多分)NativeなAPIを自由自在に叩く

https://itunes.apple.com/jp/app/python-2.7-for-ios/id485729872?l=en&mt=8昔_ctypes止まりで使えなかったctypesが、今使えるようになってて、 import ctypes libc = ctypes.CDLL('libc.dylib') print libc.printf('ok') # 2 will be printed as outputed …

FizzBuzzその3

[b==c=='' and a or b+c for a, b, c in reduce(lambda x, i: x+zip(range(1+15*i, 16+15*i), (['']*2+['Fizz'])*5, (['']*4+['Buzz'])*3), range(999), [])][:100]

PythonからWindows Spoolerをctypesで叩く

#!/usr/bin/env python # -*- coding:utf-8 -*- """\ Utility class for wrapping Winspool.drv with ctypes. GetPrinter function http://msdn.microsoft.com/en-us/library/windows/desktop/dd144911(v=vs.85).aspx PRINTER_INFO_1 structure http://msdn.…

HTAをデスクトップ中央にちらつきなくいい感じに起動する

WSH

これをコマンドラインから1行で入力、もしくはショートカットを作成する。起動するHTAはこの場合「C:\test.hta」でウィンドウサイズは300x200。 mshta.exe "javascript:var path='C:/test.hta';var w=300;var h=200;var wmi=GetObject('winmgmts://./root/ci…

Get download URL of released files on Codeplex.

# Here is respective base code written in Ruby: # https://github.com/opscode-cookbooks/wix/blob/master/libraries/codeplex.rb] # # I added __RequestVerificationToken2 handling to above code for the future. # This code is working properly in…

[Debian]Debian with ext4 でファイル復活 # To avoid losing data, needs read only remount sudo mount -o remount,ro /home # Or "sudo mount -f -o remount,ro /home" if "Device is busy" is returned # Build extundelete cd /tmp wget http://downloa…

tempfile.mkdtemp()へfuseマウントした後のゴミ掃除

プログラムがAbortした時とか mount | grep fuse | awk 'BEGIN{FS="on "}{print $2}' | awk 'BEGIN{FS=" "}{print $1}' | grep tmp |xargs -n1 fusermount -u

あえてPythonの弱点をあげてみる

変数に型がないということの利点について考えるを読んで。 class A(object): def __init__(self): self.length = 0 def get_length(self): return self.length a=A() if something==wrong: logger.error('Length: %s'%a.get_lenght()) 要するにエラー処理の…

Windows 7でhostsの内容が反映されない

hostsに「ip_address fqdn」みたいに設定したけどping, IE, Firefoxへ反映されず、ただしChromeは名前解決にWinSockを使ってないっぽくてちゃんと反映される。もちろん「ipconfig /displaydns」でhostsの内容が認識されていることは確認済み。おそらくDNSサ…

ExcelでVBAを書かずにJSON形式で返却されるはてブ数を取得

知り合いから「Excel 2013で追加された「WEBSERVICE」関数を使って、マクロを使わずWeb APIを利用する。」を教えて頂いたのでそれを応用。また「はてブAPIはJSON形式で値を返却*1」と「ExcelでJSONを扱おうとするとVBAが必要っぽい」という条件があわさった…

Pythonを使ってFizzBuzz、乗算(*)除算(/)余算(%)なしの一行で

mapとかreduceを覚えたので前回の書き直し 今回 [(s[0]!='F' and s.find('B')+1) and s[-4:] or s for s in reduce(lambda x,y: x+[(x[-3][0]=='F' and 'Fizz' or str(y+6))+(x[-5].find('B')+1 and 'Buzz' or ''),], xrange(100), ['1', '2', 'Fizz', '4', …

「フィボナッチで各種言語をベンチマーク」をPythonでちょっと掘り下げる。

「フィボナッチで各種言語をベンチマーク」を読んで、予想外にPythonの順位が低かったので。手元の環境はWindows XP SP3/Celeron 1200MHz/512MB RAMのPython 2.7.3、実行2回目以降の時間を以下のコマンドで計測。 rem 「cmd /V:ON」で遅延評価を有効化した状…