Posts

Showing posts from 2011

part of .vimrc not activated.

Finally, I fixed some of settings (nnoremaps) of .vimrc have not been activated. It was over written by an other plugin which I believe having uninstalled. Be aware of ~/.vim/after/plugin/*.vim !

start-emulator or start-device fails for missing "dx.jar"

If you try to "start-emulator" or "start-device", but fails on dx error, and if you found "cannot find dx.jar", you can fix it by putting symbolic like ln -s $ANDROID_SDK_HOME/platform-tools $ANDROID_SDK_HOME/platforms/android-7/platform-tools It seems this happens when using old android-7 project with new SDKs like r14.

Installing old formula on Homebrew(Homebrewで古いFormulaをインスール)

Since sbt is very diffrernt between 0.7.7 to 1.x, I needed to install old sbt(0.7.7), but it was not obvious how. However, it turns out to be very easy. To do that, simply put file sbt77.rb to /usr/local/Library/Formula as following content. require 'formula' class Sbt77 < Formula JAR = 'sbt-launch-0.7.7.jar' url "http://simple-build-tool.googlecode.com/files/#{JAR}" homepage 'http://code.google.com/p/simple-build-tool/' md5 '0cce0d5ade30a41b91e05705a9346b71' def install (bin+'sbt77').write <<-EOS.undent #!/bin/sh if test -f ~/.sbtconfig; then . ~/.sbtconfig fi exec java -Xmx512M ${SBT_OPTS} -jar #{libexec}/#{JAR} "$@" EOS libexec.install Dir['*'] end def caveats <<-EOS.undent You can use $SBT_OPTS to pass additional JVM options to SBT. For convenience, this can specified in `~/.sbtconfig`. For example: SBT_

Calendar Maker Script (for Python) Pythonでカレンダーを作る

Image
My wife pushed me to create a calendar of her design, but I couldn't find a good image, so I decided to make one as a programmer! Here is the image. And this is a code. #Attention! Holidays are Japanese ones. To know which day is holiday, I got "jholiday.py" from here . Thank you "AddingBox"!! Also you need to install PIL(Python Image Library). """ CREATE LARGE CALENDER IMAGE This code is created by tiid (http://makerwannabe.blogspot.com/) This work is licensed under the Creative Commons Attribution 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by/3.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA. """ import Image from PIL import ImageFont, ImageDraw from jholiday import holiday_name from datetime import timedelta import datetime class CalenderImage() : def __init__(self, width, height): self.image

Source code for slide puzzles of DevQuiz 2011(Google Developer Day)

Is it too late to public source code for DevQuiz? First purpose is to solve over 1000 puzzles in a day and this code got 1130 correct answers which was good enough for me. If anybody has a comment, please feel free to do so! (もちろん日本語でも) from heapq import heappush, heappop, heapreplace from copy import copy from random import seed class Board: def __init__(self, w, h, situation): self.w = w self.h = h self.length = len(situation) self.firstSituation = situation self.goal_str = self.createGoalMap() self.scoremap = self.createScoreMap() print "Board:",w,h,self.scoremap def move(self, situation, pos, i): assert(situation[pos]=="0") i = {0:0, 1:1, 2:2, 3:3, 'U':0, 'D':1, 'L':2, 'R':3}[i] def switch(i,j): if(i&ltj): left,right=i,j else: left,right = j, i s = situation return s[:left] + s[right] + s[left

[Android]onDraw not called (onDrawが呼ばれない)

I've been wondering onDraw(...) method of SurfaceView's child class is not called. I figured out it can be avoided setting its background color as android:background="@color/..." in layout xml file. If you having same problem, try to set background color.

Using bulkload cause UnicodeDecodeError (Google App Engine) GAEのbulkloadでUnicode Decode Error

I've been wondering a following loader.py causes unicode decode error when uploading utf-8 csv file by bulkloader to Google App Engine. class A(bulkloader.Loader): def __init__(self): bulkloader.Loader.__init__(self, 'TEST', [("__key", dummy), ("prop", lambda x: x.decode('utf-8'))]) def generate_key(self, i, values): return values[0] I tried to avoid UnicodeDecodeError by x.decode('utf-8') but it didn't work. After seeing around datastore.py of Google App Engine code, it turns out (of course) the key also should be unicoded. So correct code is class A(bulkloader.Loader): def __init__(self): bulkloader.Loader.__init__(self, 'TEST', [("__key", dummy), ("prop", lambda x: x.decode('utf-8'))]) def generate_key(self, i, values): return values[0].decode('utf-8') It took a few hours ...

Showing CPU/Memory usage on tmux status bar(tmuxのステータスバーにCPUとMemoryの使用状況を表示する)

Image
On OSX, to show CPU usage, script is like this. #!/bin/bash top -l 1 | head -n 4 | tail -n 1|awk '{printf "%3d%%\n", $3}' to get Memory Usage, script is like this. #!/bin/bash vm_stat | awk 'BEGIN{FS="[:]+"}{if(NR<7&&NR>1)sum+=$2; if(NR==2||NR==4||NR==5)free+=$2} END{printf "%3d%%\n",100*((sum - free)/sum)}' Name thsese scripts like getCpuUsage.sh/getMemUsage.sh and put them in folder where the $PATH is set. Change their mode to u+x. To show them on tmux status line, .tmux.conf is like set -g status-right '#[fg=blue,bold]#H#[default] #[fg=blue,bold][CPU=#(getCpuUsage.sh) MEM=#(getMemUsage.sh)]#[default]'

Broken border of tmux on iTerm can be caused by some setting.(tmux+iTerm2での表示の乱れについて)

Image
I've been annoyed by broken border lines of tmux on iTerm2, but finally I figured out what causes this. To fix it, turn off the chechk box of "Treat ambiguous-width characters as double width" in Terminal tab of "Edit profile".

404 on homebrew

When i try to install pyqt with brew install pyqt I got 404 error on patch install. It's solved by brew update as you might expect... 3 hours gone for this. orz

Installing wxPython on MacOS(SnowLeopard)

memo for myself. It's not very simple to install wxPython on MacOSX, because it's been using Carbon and Cocoa version is released only as unstable version. install wxPython2.9 downloaded from here install python framework-build with homebrew. brew install python --framework set PYTHONPATH PYTHONPATH=$PYTHONPATH:/usr/local/lib/wxPython/lib/python2.7/site-packages/wx-2.9.1-osx_cocoa

[iPhone]UIButton does not respond when layouted.(layoutSubviewでUIButtonを動かすと、反応しなくなる)

I have been in stuck for days that UIButton does not respond to touch. I finally figured out that because overridden "layoutSubviews" function did not call it's super's "layoutSubviews" on the top. If you want to move UIButtons along layout, you should write something like, -(void) layoutSubviews { [super layoutSubviews];

文字コード一括変換のワンライナー(One Liner for changing text files' encodings)

Change all *.txt files to UTF-8 and UNIX LF. すべての*.txtのファイルをutf-8とunix-lfに変えたファイルにする for f in *.txt; do nkf -Lu -w "$f" > "${f%.txt}utf8.txt"; done -Lu unix lf -w utf-8 元データが必要なければ for f in *.txt; do nkf -Lu -w --overwrite "$f"; done

bashワンライナーで関数宣言

bashワンライナーで関数を書こうとしてつまずいた。 二つ下のディレクトリをなんどもgrepする必要があるので書いたのだが search_proj() { grep -i $1 */*.scala; } のセミコロンを忘れてて、「あれ? 定義できない」の繰り返し。