2008年9月30日火曜日

GNUStep building with python.

i sometimes forget how to build GNUStep code.
following is code.


#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
import os
import re

if __name__ == '__main__':
if len(sys.argv) != 3:
print 'invalid arguments'
sys.exit(1)
print 'compiling starts'

opt_array = ['-fconstant-string-class=NSConstantString',
'-IC:\GNUstep\GNUstep\System\Library\Headers',
'-LC:\GNUstep\GNUstep\System\Library\Libraries',
'-lgnustep-base',
'-lobjc'
]

base_dir = os.getcwd()
filter = re.compile('\.m$')
linker = []
input = sys.argv[1]
output = sys.argv[2]

for dirpath, dirnames, filenames in os.walk(base_dir):
for filename in filenames:
if filter.search(filename):
if filename == input:
continue
filename, ext = filename.split('.')
filename = os.path.join(dirpath, filename)
action = 'gcc -O %s -c %s.%s -o %s.o' %\
((' ').join(opt_array), filename, ext, filename)
print action
linker.append("%s.o" % filename)
os.system(action)

break
action = "gcc -O %s %s %s -o %s" %\
((' ').join(linker), input, (' ').join(opt_array),output)
print action
os.system(action)
print 'compiling ends'


2008年9月28日日曜日

xcode compiling option

at this time, i talk about C++ Tool of Command Line Utility.

1)expand Targets. after that expand your project.

2)you can see Compile Sources. expand it and click a right mouse button and select Get Info.

3)Select a tab "Build". You can see "Additional Compiler Flags". input compiler options that text area.

this is how to set compiling options. as for the rest, just push the Build button.

check this too.

2008年9月18日木曜日

As a programmer...

Assure codes. Make evidences to say "it's safe" for it.

Read documents.

Never forget data from outside is not secure.

These are principles for me.

2008年9月17日水曜日

handling pgm data with c++

i m trying to get raw data from pgm file. if you calculate file size from width and height, if you like 16bit data, the file size will be double, you can find the header size. but how do we get heaer info without calculating?

following is a part of the code.



int width, height, brightness, counter;
std::ifstream ifs;
//initialize
width = height = brightness = counter = 0;
ifs.open(input_file_name, std::ios::in);

std::string filetype;
std::string filetype_str;
std::getline(ifs, filetype);

std::string size_str;
std::getline(ifs, size_str);
std::istringstream size_stream(size_str);
size_stream >> width >> height;

std::string brightness_str;
std::getline(ifs, brightness_str);
std::istringstream brightness_stream(brightness_str);
brightness_stream >> brightness;

std::string header_needless;
std::getline(ifs, header_needless);

std::cout << filetype << std::endl;
std::cout << width << std::endl;
std::cout << height << std::endl;
std::cout << brightness << std::endl;

this means there are 4 lines for a header.

bayer data with dcraw

if you want to get bayer data from raw data, dcraw may be good. if you type like

dcraw -d -4 rawdata

you can get 16bit pgm data. the order is bayer structure. if you like 8 bit, you don't need to add "-4" option.

i will distribute a software to get bayer image with opencv someday.

2008年9月16日火曜日

iPod music backup script


#!/usr/bin/env python
# -*- coding: utf-8 -*-

### globals
import os
import shutil

def swapextensions(copy_from, copy_to):
count = 0
for path, subdirs, files in os.walk(copy_from):
for file in files:
if file[:1] != '.':
count += 1
shutil.copy('%s/%s'%(path,file), '%s/%s'%(copy_to,file))

if __name__ == '__main__':
import sys
if len(sys.argv) != 3:
print 'Usage: swapext rootdir before after'
sys.exit(100)
swapextensions(sys.argv[1], sys.argv[2])



how to use?

python copy_files.py /Volumes/xxx/iPod_Control/Music destination_path

change encoding with python


#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import re

if __name__ == "__main__":
base_dir = os.getcwd()
filter = re.compile('\.h$|\.m$|\.cpp$|\.c$')
for dirpath, dirnames, filenames in os.walk(base_dir):
for filename in filenames:
if filter.search(filename):
p = os.path.join(dirpath, filename)
action = 'nkf --utf8 %s > %s_' % (p, p)
os.system(action)
action = 'mv %s_ %s' % (p, p)
os.system(action)

2008年9月12日金曜日

terminal emacs does'nt allow me to undo with C-/!!

this entrysay the reason why we can't undo with C-/ is "/" is not an ascii code. terminal can only send ascii character maybe.

2008年9月11日木曜日

MoinX memo 2

if you wanna change the design of wiki, you just change theme directory. it's located on /Applications/MoinX.app/Contents/Resources/htdocs.

if you wanna change the parameter of the wiki, change wikiconfig.py on ~/Library/Application Support/MoinX/instance. you can use logo image if you use img tag for sitename.

2008年9月10日水曜日

MoinX memo

How can I start?

if you are a mac user, use Version 1.0.3. you can download from http://moinx.antbear.org/

Where is it located?

In ~/Library/Application Support/MoinX/Instance/data/pages


if you have any other problems, go to http://code.google.com/p/moinx/wiki/FrequentlyAskedQuestions

dcraw memo


gcc -o dcraw -O4 dcraw.c -lm -DNO_JPEG -DNO_LCMS

python-c api programming

i ve tried to copile python-c code a dozen times. but everytime, i failed.
i didn't know why it does'nt work. the code is very simple like just showing "Hello World!".
the problem was how to compile. a compiler always returned " undefined reference to `_imp__PyArg_ParseTuple'".
i though it's a liker problem.
today, i finally succeeded to do it!!! this is a memo for it.

at this time, i used following simple code from [2].

ext.c

#include

static PyObject *
fact(PyObject *self, PyObject *args)
{
int n;
int i;
int ret=1;

if (!PyArg_ParseTuple(args, "i", &n))
return NULL;

for (i=n; i>0; i--) ret *= i;

return Py_BuildValue("i", ret);
}

static PyObject *
hello(void)
{
printf("Hello World!!\n");
Py_RETURN_NONE;
}

static char ext_doc[] = "C extention module example\n";

static PyMethodDef methods[] = {
{"hello", hello, METH_VARARGS, "print hello world.\n"},
{"fact", fact, METH_VARARGS, "return factorial.\n"},
{NULL, NULL}
};

void initext(void)
{
Py_InitModule3("ext", methods, ext_doc);
}




gcc -IC:\Python25\include -LC:\Python25\libs ext.c -lpython25 -shared -o ext.pyd


that's it!!!you can import as "ext" on python command line!


reference:
[1] http://techtonik.rainforce.org/2008_01_01_archive.html
[2] http://f59.aaa.livedoor.jp/~ookini/pukiwiki.php?Python%A4%CEC%B8%C0%B8%EC%B3%C8%C4%A5%A5%E2%A5%B8%A5%E5%A1%BC%A5%EB%A4%F2%BB%C8%A4%C3%A4%C6%A4%DF%A4%EB

music memo

cool


my friend told me


2008年9月4日木曜日

CrashReporter of mac

Mac OS X has a system which send a bug report to apple. it's called CrashReporter.
Usually, developer can not get it because it's sent to apple directory.
thus, people implement that system by themself.

I, like all developers, want that system. We can get some entry to implement a hand-made CrashReporter. I got a sample code of Steve Gehrman. Previously, I wrote a flow of the code.
At this moment, I made a log for general knowledge of CrashReporter.

As a technical report say in http://developer.apple.com/jp/technotes/tn2004/tn2123.html, we can get hexadecimal addresses with exception tracebacks. a problem is how to change from hexadecimal to symbol. if you have a XCode, you can use "atos" but if a user doesn't, how do we get them?
to begin with, do we need symbols when a user have a crash?
generally speaking, hexadecimal address is enough because we can get symbol at local circumstance.
so, what we have to do is getting tracebacks of the crash.

i will write details later.