glogglog

Change process name in Python

Linux:

libc6's prctl function with option PR_SET_NAME
       PR_SET_NAME (since Linux 2.6.9)
              Set the process name for the calling process, using the value in
              the location pointed to by (char *) arg2.  The name can be up to
              16  bytes  long,  and  should  be null terminated if it contains
              fewer bytes.

code is

import ctypes
libc = ctypes.CDLL('libc.so.6')
libc.prctl(15, '%s\0' %procname, 0, 0, 0)

---------------------------------------------------------------------------------------

BSD:

import dl
libc = dl.open('/lib/libc.so.6')
libc.call('setproctitle', '%s\0' %procname)

---------------------------------------------------------------------------------------
a script to show value of MACRO

echo -e "#include <sys/prctl.h>\n#include <stdio.h>\nint main(){printf(\"%d\\\n\",PR_SET_NAME);return 0;}" |gcc -xc - -o /tmp/test && /tmp/test



Tags: python |

WOL script updated

I posted an article about WOL over Internet, it referred a python script which send UDP WOL Magic-package over UDP. Recent the script has been updated, the reason is my office firewall block any UDP package except for DNS query, even when an non-DNS UDP package was tried to send through port 53, the firewall block it.

what I need to do is encapsulate a Magic-package into a fake DNS query, indeed my strategy is pack it into query domain name part. The package head is easy to construct. So the problem is how to pack the 102(6+6*16) bytes Magic-package.

----------------------------------------------------------------------------------------

If you can't understand the paragraph below, it's my fault, I can't explain it well. So don't read it again, goto code, everything is in code, and the python code is easy to understand.

----------------------------------------------------------------------------------------

The max length of a label in domain name is 63, which can contain first 6 '0xff' and 8 mac, (here 6+6*8=54 bytes is done). Then the first byte of remaining 48(102-54) bytes (also the first byte of 9th mac) is the length of the second label of domain name, so this byte value must between 1 and 63. if it's in this range(let's say it's 10), the next 10 bytes is the second label in domain name, (here 6+6*8+1+10=65 bytes is done), and the first byte value of remain 37 bytes must between 1 and 63 ..., etc. We can call "the first byte of remaining bytes" "key bytes". Let's repeat this process until all 102 bytes are consumed, if all key bytes are between 1 and 63, we can pack the Magic-package into a domain name part. If we got a key bytes which is not in the range before consuming all 102 bytes, we fails.

Notice, we can start from not only the first byte of remaining 48 bytes in first iteration of process, actually we can regard any byte of the 9th mac as the length of the second label, bytes before that key byte can be pack into first label, that's is the first label has length of 54+(number of byte in 9th mac before key byte). So we have 6 chance.

----------------------------------------------------------------------------------------



Tags: python | wol |

Got Motorola E6 camera works in skype

What?

I made a uvcvideo patch to make Motorola E6 camera works in skype in 320x240 mode.

Why?

I have a Motorola E6 cellphone, which has a 2.0M pixel camera. If you set USB mode as "Webcamera", after connecting to PC, this cellphone can act as a webcamera. It works fine in 640x480 mode, but in lower resolutions like 320x240, the video overlaps. The problem is skype, which I used for video chatting with my gf, only send 320x240 resolution. So I cannot use cellphone as webcamera and have to carry an extra webcamera during every trip.

Somebody suggested that a hack to skype config.xml will make skype call with high resolution, but it seems only works in Windows, at least not worked in my Ubuntu9.04 Skype 2.1.0.47.

Indeed, Moto E6 camera(22b8:6006) is a USB video class device. The uvcvideo is in charge to drive this device. But because some issues, when uvcvideo changed the resolution to lower, the hardware didn't change, it send a whole 640x480 frame even when the driver expects a lower resolution

If Skype set resolution to 320x240, the driver malloc a shorter buffer, the length of which is 1/4 of the 640x480 buffer length. When hardware send data to driver, the driver keep complaining "Frame complete (overflow).", that's because the driver buffer is full but hardware keep sending the later 3/4 (640x480)frame. The video is overlapped that's because the driver treat the upper 1/4 of (640x480) frame data as one 320x240 frame data, the first row of 640x480 frame converted to the first and the second row in 320x240 frame. The left part converted to the first row, the right part converted to the second row. So the result is the left part and the right part of the upper 1/4 of (640x480) video, overlaped in 320x240 video, the lower 3/4 video just gone. Here is the snapshot of the videos.

From uvc

And this script verified my guess.

How?

But it seems no solution for this problem. Windows driver maybe works fine, but I have no Windows system at hand. And this thread gave me an idea. It's pretty simple: it store the (640x480) frame data to somewhere and convert them to (320x240) frame data when the last piece of package arrived.

At first, I treat the frame data as bitmap, two bytes is a pixel, and compress it to 1/4. The result looks ugly.

From uvc

Then I found the frame data is in YUYV format, in which 2 pixels will be defined in each macropixel (four bytes). I realized that my previous method make video lost some components. The second solution is: only keep the even(th) rows pixels of the original frame, in each row only keep the 2*even(th) cols pixels. That's is, in one row, copy 2 pixel(4byte), and skip 2 pixel(4byte), copy 2 pixel, skip 2 pixel....etc. This method have an advantage of avoiding compute YUV components of each pixel, disadvantage is obvious: heavy sawtooth

From uvc

So the anti-aliasing is needed, the final solution is to compute the nearby 4 pixel to get the result 1 pixel.

From uvc

Usage

1. Get the source from uvcvideo(install mercurial if needed):

 

hg clone http://linuxtv.org/hg/~pinchartl/uvcvideo/

 

2. Download this patch file to uvcvideo directory and apply the patch. (Warning this path is based on 12393:756ad91a832e)

cd uvcvideo && wget http://sevenever.googlecode.com/svn/trunk/misc/patch_MOTO_E6_to320.patch && patch < patch_MOTO_E6_to320.patch 

3. Make

make

4. Test

 

sudo rmmod uvcvideo ;sudo rmmod videodev;sudo rmmod v4l1_compat 

sudo insmod v4l1-compat.ko; sudo insmod videodev.ko; sudo insmod uvcvideo.ko to320=1

I have add a module parameter "to320" to uvcvideo.ko, if this parameter is 0, the patch will not work. Command to change this parameter is "echo 1 | sudo tee /sys/module/uvcvideo/parameters/to320".

now plugin cellphone and launch skype.

5. if everything is OK, you can install this module.

mv v4l/v4l1-compat.ko /lib/modules/`uname -r`/kernel/drivers/media/video/.

mv v4l/videodev.ko /lib/modules/`uname -r`/kernel/drivers/media/video/.

mv v4l/uvcvideo.ko /lib/modules/`uname -r`/kernel/drivers/media/video/uvc/.

run modconf to reload uvcvideo and append parameter "to320=1"

Better solution

If this camera works fine in Windows, probably there some issues about the uvc driver. Later after I come back to Shanghai, a USB traffic dump is scheduled. If I can confirm that hardware has no problem, this dirty hack is not needed.

End

Thank you for reading up this post and be patient to my poor English, here is my little gift:

From uvc



Tags: uvcvideo | E6 | camera | linux |

Cann't catch gae updating~~~

Added an issue.

And tinyMCE dose not work now in this Edit post page, why? my problem or tinyMCE's?

gae has changed a lot since last study last September, there are 5 item in "main" group in the gae admin page, but 2 of them (Cron jobs and Task Queues) never used. Beside this, the memcache api, XMPP api is the same status. It seems that a new study of gae is necessary.

in Hitachi, Ibaraki, Japan 2009/09/05

 

 


View Larger Map



Tags: python | gae | glog |

Remote awake over Internet

You need a file which has only one copy on your home PC's harddisk, but you are in office or another city even another country! What would you do? Call your neighbor to ask him break into your house and power on your PC, then you can fetch file by sftp?

Here is the solution to avoid breaking your door. Remote Power On

Thanks for WOL tech and Python, It's so easy!

What We need:

1. A WOL(wake on lan) supported NIC

    My Asus K8N integrated NIC

2. A tool to send Magic Package

    A Python script no more than 40 lines

3. An ADLS router supporting DDNS, ARP binding and NAT port mapping

    TP-Link WR541G/542G

 

Here is steps:

1. Enable WOL in BIOS settings.

    There are a bunch of guides on google, find one for your motherboard and network card. Notice: ACPI 2.0 must be enabled, I wasted hours before success on this misconfig.

2. save script below as wol.py

#!/usr/bin/python
import sys
import struct
from socket import *


def usage():
    print """send UDP packet to broadcasting address to remote wakeup
UDP package format is FFFFFFFFFFFF0017314BACCB....................
                      (fixed 6 FF)(   mac    )(repeat mac 15 times)

usage: wol.py broadcasting_address udp_port target_host_mac

example: wol.py sevenever.vicp.net 4672 0017314BACCB
"""

def main():
    if len(sys.argv) != 4:
        usage()
        return 1
    bc_addr = sys.argv[1]
    udp_port = int(sys.argv[2])
    mac = sys.argv[3]
    hw_addr = struct.pack('BBBBBB', int(mac[0:2], 16),
                                    int(mac[2:4], 16),
                                    int(mac[4:6], 16),
                                    int(mac[6:8], 16),
                                    int(mac[8:10], 16),
                                    int(mac[10:12], 16))
   
    msg = '\xff' * 6 + hw_addr * 16
   
    sk = socket(AF_INET, SOCK_DGRAM)
    sk.setsockopt(SOL_SOCKET, SO_BROADCAST, 1)
   
    sk.sendto(msg, (bc_addr, udp_port))
    sk.close()
   
if __name__ == '__main__':
    sys.exit(main())

3. Setting on your router

    3.1 add an arp binding record

        [your PC IP address] ---- [your netcard MAC address]

        say:[192.168.1.7] ---- [00-11-D8-93-E9-08]

    3.2 add a NAT port mapping

        since the tool above send UDP package to your router, your router must know how to forward package to your PC, So

add a port mapping:

        Protocol: UDP

        Service Port: any (say 4672)

        LAN Host IP: The IP binded in step 3.1

        *may be you have had an UDP port mapping for edonkey or some application else, if so you can just reuse that setting and do nothing for this step 3.2.

    3.3 setup DDNS on router

        The last thing is you must know your router's Internet Address, if your ISP assign you a fixed pulic IP(lucky guy! that's impossible for China where I living), you just remember it, or you need setup DDNS( like oray.net or 3322.org ). Google it, you will find lots of guides. Here I asume you can access your router by name: somename.3322.org.

Now we have done all settings, The command for power on our home PC remotely in office or anywhere is:

./wol.py somename.3322.org 4672 0011D893E908

Enjoy!

 

 

 



Tags: python | WOL | DDNS |

download youtubu video using flashgot

urrent(2009-03-22) flashgot does not fake the User-Agent HTTP header as Firefox if downloading using wget, I dont know how other download manager is. This is not a big problem if you does not download videos(like flv) from a video site which deny wget according the User-Agent HTTP header.

But I found almost all video sites check this header for proventing thief, so the video detecter of flashgot become not so useful.

Actually, wget do have parameter "-U,  --user-agent=AGENT" to fake the HTTP header, so the solution is here:

This python script is a proxy when flashgot call wget to download, it add user-agent "Mozilla/5.0 (X11; U; Linux i686; zh-CN; rv:1.9.0.7) Gecko/2009030422 Ubuntu/8.10 (intrepid) Firefox/3.0.7 GTB5"(my firefox version) when invoke wget.

To use it,

1.save it as "dflv" to some directory like ~/bin

2.config flashgot, add a new download manager, name it "dflv", the executable path should be the file path you saved in [1], and arguments template *must* be "[FOLDER] [REFERER] [CFILE] [UFILE]"(with out the quote mark)

OK, now you can doanload vide by short-cut key Ctrl+F7

notice:

only OS with python and wget and xterm supported, I think most Linux and freebsd have them. Windows which installed python and wget should be supported, I'll give a try later cause no Windows at hand.

File:

-------------------------------------------------------------------------------

#!/usr/bin/python

import os
import sys
from datetime import datetime

log = False

logdir = os.path.expanduser("~/.dflv")
dfname = datetime.now().isoformat()

log and os.makedirs(os.path.sep.join([logdir,dfname]))
logfile = os.path.sep.join([logdir,dfname,'log'])
wgetlogfile = os.path.sep.join([logdir,dfname,'wgetlog'])

log = log and open(logfile,'w')

try:
    ua = "Mozilla/5.0 (X11; U; Linux i686; zh-CN; rv:1.9.0.7) Gecko/2009030422 Ubuntu/8.10 (intrepid) Firefox/3.0.7 GTB5"

    log and log.write(' '.join(sys.argv))
   
    _, folder, referer, cookiefile, urlfile = sys.argv

    cmd = '''xterm -e 'wget -c -P "%s" --content-disposition -U "%s" --referer="%s" --load-cookies="%s" -i "%s";read -n 1 -s' ''' % (folder, ua, referer, cookiefile, urlfile)

    log and log.write(cmd + '\n')

    os.system(cmd)
except Exception,e:
    log and log.write(str(e) + '\n')



Tags: python | flashgot |

Rebuild index after deleting data for Sybase and Oracle

Hi, I'm doing a porting from sybase to Oracle. After deleting a bunch of data from a table, the original program use "update statistics" to update index in this table, then it call a store procedure named "sp_recompile", which appling to a table to rebuild all store procedure and trigger used this table.(for more infomation http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.help.ase_15.0.sprocs/html/sprocs/sprocs181.htm) Here is my question: In Oracle, after update index using "alter index indexname rebuild", do I need to something corresponding to the "sp_recompile" in sybase? If so, how to do it? somebody told me to use "execute DBMS_STATS.GATHER_DATABASE_STATS", is that correct?

no need to rebuild index, DBMS_STATS.GATHER_DATABASE_STATS maybe turn query faster in future. Suggest disabling index and trigger while deleting.



Tags: oracle |

python challenge(15-21)


level15:

pretty easy, 1\d{1,2}6 year jananry 26th is a Monday.

whom? use wikipedia

http://www.pythonchallenge.com/pc/return/mozart.html


level16:

shift each line to make the purple bars as one stick?

five 195

http://www.pythonchallenge.com/pc/return/romance.html


level17:

in level4, a cookie is set:

info=you+should+have+followed+busynothing...

start chain with busynothing=12345 and collect all cookies

BZh hint decompressing

'is it the 26th already? call his father and inform him that "the flowers are on their way". he\'ll understand.'

mozart's father is Leopold, use phonebook.phone('Leopold') in level13 I got

http://www.pythonchallenge.com/pc/return/violin.html

request http://www.pythonchallenge.com/pc/stuff/violin.php with cookie "info=the%20flowers%20are%20on%20their%20way"

oh well, don't you dare to forget the balloons.

http://www.pythonchallenge.com/pc/return/balloons.html


level18:

the difference is brightness.html

difflib.ndiff() lines in delta.txt, and write to each of '-', '+', ' ' to file. they are png image.

http://butter:fly@www.pythonchallenge.com/pc/hex/bin.html


level19:

computer is out of order, byteorder is reversed. So byteswap bytes in indian.wav's frames.

http://www.pythonchallenge.com/pc/hex/idiot.html

http://www.pythonchallenge.com/pc/hex/idiot2.html


level20:

Content-Range is:  bytes 0-30202/2123456789

add request header "range bytes=30202-30202", got:

---------------------------------------------------------------

Why don't you respect my privacy?
we can go on in this way for really long time.
stop this!
invader! invader!
ok, invader. you are inside now.
---------------------------------------------------------------

from back to front, add request header "range bytes=2123456789-2123456789", got:

esrever ni emankcin wen ruoy si drowssap eht

the password is your new nickname in reverse.

and it is hiding at 1152983631.

at 1152983631: got a zip file encrypted

the password is redavni

we are in level 21


level21:

file starts with 78 9c is zlib compressed file.

repeating decompress it with zlib or bz2 until get error, see the tail of decompressing result, it's 9c 78

"look at your logs"

log our action, mark zlib decompressing as "x", bz2 decompressing as "B", mark reverse as "\n"

http://www.pythonchallenge.com/pc/hex/copper.html



python challenge(8-14)

level8:

the un and pw startswith 'BZh', which is magic number of a bz2 file, so you use bz2 module:

bz2.decompress

http://www.pythonchallenge.com/pc/return/good.html


level9:

first and second is coordinations of pots.

use ImageDraw.polygon([first],fill=color)

I first tried gnu, then cow, at last bull

http://www.pythonchallenge.com/pc/return/bull.html


level10:

len(a[30]) = ?

a = [1, 11, 21, 1211, 111221, 

the next item is the description of previous item
11 is one 1
21 is two 1
1211 is one two, one one
111221 is one one, one two, two one

http://www.pythonchallenge.com/pc/return/5808.html

level11:

http://bg5hfc.spaces.live.com/blog/cns!E67CCF4FFB0BE86!1147.entry

I still have no idea how they get the way.

http://www.pythonchallenge.com/pc/return/evil.html


level12:

evil2.jpg-->evil2.gfx

dispatch this file to five file, you'll get the word by "file" them.

http://www.pythonchallenge.com/pc/return/disproportional.html


level13:

xml-rpc phonebook.php listMethods

555-ITALY

try -- 555-48259 55548259 ITALY italy

http://www.pythonchallenge.com/pc/return/italy.html


level14:

wire.png is a 10000*1 image, convert to 100*100?

consider

remember: 100*100 = (100+99+99+98) + (...

and title of this level "walk around"

source below:

import Image

def turn():
global fl,fi,f
fi=(fi+1)%4
f=fl[fi]

src = Image.open('wire.png')
des = Image.new('RGB', (100,100))

# direction functions
r = lambda (x,y):(x+1,y)
d = lambda (x,y):(x,y+1)
l = lambda (x,y):(x-1,y)
u = lambda (x,y):(x,y-1)

# direction functions list
fl = [r,d,l,u]

# current direction function index
fi = 0

# current direction function
f=r

# current postion
pos = (-1,0)

index = -1
for i in range(100):
index += 1
pos = f(pos)
des.putpixel(pos,src.getpixel((index,0)))


for i in range(99,0,-1):
for m in range(2):
turn()
for k in range(i):
index += 1
pos = f(pos)
des.putpixel(pos,src.getpixel((index,0)))

des.save('cat.png')

http://www.pythonchallenge.com/pc/return/cat.html

 

 

 



convert ape to flac according cue

shntool split -f all.cue -t "%n.%t" -o flac all.ape



Tags: flac | ape |

duplicate symbol in dynamic library

(21时29分58秒) smellydog: Hi, I have a liba.so which has function libfuncA(), and libb.so which has function libfuncB(), libfuncB calls libfuncA(). In my main.c, I define another libfuncA(), it calls libfuncB(). All this is compiled smoothly, but when run, I got segment fault, what's wrong?

(21时31分24秒) smellydog: All commands to compile is below:
(21时31分24秒) smellydog: gcc --share -o liba.so liba.c
(21时31分24秒) smellydog: gcc --share -o libb.so libb.c
(21时31分24秒) smellydog: gcc -c -o test.o test.c
(21时31分24秒) smellydog: gcc -o test test.o -L. -lb
(21时32分18秒) smellydog: I'll give you source if you need. Thanks!
(21时33分20秒) davidr_: smellydog: have you localised where the segfault is? e.g. compile all your objects with -g and run via gdb?
(21时38分14秒) smellydog: davidr: It seems be the program call the libfuncA() defined in main.c instead of libfuncA() in liba.so, which make a infinite recursion.
(21时40分49秒) smellydog: I solved the segment fault by renaming libfuncA() in main.c to funcA(), as long as different from function name in liba.so.
(21时43分21秒) smellydog: But I don't know how to avoid such problem, because I link my program to some libxxx.so, I don't know whether libxxx.so refering some function with the same func name as my function in other library.
(21时44分32秒) davidr_: smellydog: ok; so the way symbol resolution in shared objects works by default is as follows: if the symbol is defined in the main executable; then then symbol takes prescidence
(21时45分28秒) davidr_: smellydog: you need to mark libfuncA() with __attribute__ ((visi-bility ("hidden")))

(21时45分44秒) davidr_: (drop that hypen in visibility; was a typo)

(22时18分06秒) smellydog: davidr_: I followed your instruction, add __attribute__ ((visibility ("hidden"))) to libfuncA() in test.c, but I got some error:"hidden symbol `libfuncA' in test.o is referenced by DSO" while linking.
(22时23分39秒) davidr_: smellydog: so I think you might have another problem - how as libbfunc() expecting to load liba? are you doing a dlopen() on it?
(22时26分10秒) smellydog: davidr_: I didnot call dlopen(), just include <liba.h> and compile it with -lb
(22时26分47秒) davidr_: smellydog: ok, so the problem you have is how does libb know to open liba? they have no defined relation ship at the moment
(22时27分01秒) smellydog: davidr_: sorry, the compile command line is :gcc --share -o libb.so libb.c
(22时27分20秒) davidr_: smellydog: sure, but there's no mention of liba there
(22时28分00秒) davidr_: so you have test.exe, which is explicityly linked to libb.so. but when you run text.exe, it doesn't know to load liba
(22时28分26秒) davidr_: if you run ldd <test> you'll see which libraries are linked in at compile time
(22时28分42秒) davidr_: to get access to any other libraries, you'll have to explicitiy load them at runtime
(22时28分59秒) smellydog: but I did not get test.exe, got error while link.
(22时30分26秒) davidr_: smellydog: sure, if you revert the visibility change you'll see what I mean. I didn't understand your full problem at the beginning, the visibility thing isn't the (full) solution
(22时33分50秒) smellydog: davidr_:yes, after revert the visibility change and link, I get test.exe, which links to libb.so, no liba.so

(22时40分20秒) smellydog: davidr_: how to aviod such problem? Do I must know every symbol the library used?
(22时40分44秒) davidr_: smellydog: ok you've got a couple of options; but you should probably go and read up on shared libraries
(22时41分05秒) davidr_: smellydog: why have liba and libb in seperate libraries for a start?

(22时49分34秒) smellydog: davidr_: It's just an example, Actually this problem is from my working, I write a program main.c which defined a connect() function, and I compile main.c and link it to Oracle oci library libclntsh.so.10 with -lclntsh. But I got segment fault while running, after debug, I found it is caused by a infinite recursion. I guess the connect() in main.c is called from other lib. So I do this test.

(22时50分53秒) noshadow: smellydog: connect is a standard library functions. of course things might segfault if you replace it with a function with other call semantics....
(22时51分19秒) davidr_: smellydog: ok. So in terms of what you are doing (in the test program); you need to explicity load liba from libb; so in libbfunc() have something like:- {handle = dlopen("liba); myfunc = dlsym(handle, libafunc); myfunc() }
(22时57分10秒) smellydog: davidr_: Thanks! Now I know connect() is a standard library functions, and I should not "rewrite" it ever, but what about other standard library functions I don't know and "rewrite" them by mistake. can gcc give me some waring? such problem is hard to debug.

(23时00分31秒) noshadow: smellydog: only way I see it could warn is when the appropiate header is installed. Then it will usually warn as the function will have different prototypes. But all the headers are quite big.
(23时01分04秒) noshadow: A way to avoid such problems is to make all functions static you do not need outside the file.
(23时02分02秒) noshadow: And to check names you use between files (under linux installing development manpages and looking there) or using names unlikely to be default (like modulename_function)...
(23时04分22秒) smellydog: noshadow: Thanks for reply! Is there some tools to check names between files?

(23时06分52秒) noshadow: smellydog: perhaps splint or co might do so..
(23时09分19秒) smellydog: noshadow: Thanks! I'm go for them. I learn much about shared library and its loading, and can you suggest some readings about it?

 


Test codes:

-----------------------------------------------------------

/*liba.h:*/

int libfuncA();

-----------------------------------------------------------

/*liba.c*/

#include <stdio.h>

int libfuncA()
{
    printf("from lib A\n");
    return 0;
}

-----------------------------------------------------------

/*libb.h*/

int libfuncB();

-----------------------------------------------------------

/*libb.c*/

#include <stdio.h>
#include "liba.h"

int libfuncB()
{
    printf("from lib B\n");
    libfuncA();
    return 0;
}

-----------------------------------------------------------

/*test.c*/

#include <stdio.h>
#include "libb.h"

int libfuncA(){
    printf("from funcA in main\n");
    libfuncB();
}
int main()
{
    libfuncA();
    return 0;
}


-----------------------------------------------------------

My solutions is:

-----------------------------------------------------------

in test.c


- int libfuncA(){
+ static int libfuncA(){

-----------------------------------------------------------

compile:
gcc --share -o liba.so liba.c
gcc --share -o libb.so -L. -la libb.c
gcc -c -o test.o test.c
gcc -o test test.o -L. -lb

-----------------------------------------------------------

 

 



Tags: gcc | linux |

Install ies4linux on debian

http://www.tatanka.com.br/ies4linux/page/Installation

1. 編輯「ies4linux-latest/lib/messages.txt」檔案,將 1x 行的「tw . zhtw TW」改成「zh tw zhtw TW」。

2. 編輯「ies4linux-latest/lib/functions.sh」,將 9x 行的「pid=(wget ...)」改成「pid=(LANG=C wget ...) 」。



Tags: debian | ies4linux |

start my python challenge(1-7)

 

Hi, I start to play www.pythonchallenge.com, I'll post answers here and source at my source repository.


level0:

2**38

http://www.pythonchallenge.com/pc/def/274877906944.html


level1:

string.translate('map',''.join(chr((i+2)%256) for i in range(256)))

http://www.pythonchallenge.com/pc/def/ocr.html


level2:

get the rare letters and rearrange to a word

http://www.pythonchallenge.com/pc/def/equality.html


level3:

[k[4] for k in re.findall('[a-z][A-Z]{3}[a-z][A-Z]{3}[a-z]',s,re.M)]

http://www.pythonchallenge.com/pc/def/linkedlist.html


level4:

12345

50010

53522

92118

46059

http://www.pythonchallenge.com/pc/def/peak.html


level5:

pickle banner.p

and print them

http://www.pythonchallenge.com/pc/def/channel.html


level6:

http://www.pythonchallenge.com/pc/def/channel.zip

zipfile.ZipFile.infolist comment

http://www.pythonchallenge.com/pc/def/hockey.html

http://www.pythonchallenge.com/pc/def/oxygen.html


level7:

use PIL to pick pixel from that image.

coordinate is (i*7, 42)

got RGB and chr() to:

smart guy, you made it. the next level is [105, 110, 116, 101, 103, 114, 105, 116, 121]

chr() again

http://www.pythonchallenge.com/pc/def/integrity.html


 

 



jsMsgBox, A js modal message box

I created a js lib--jsMsgBox, which you can display a modal alert dialog or confirm dialog without alert() and confirm() function. It enable you to set message box title, and not block browser when user browse your page in tab page. It now works in firefox3. You can download it from my opensource repository.

screen shot:



Tags: jsMsgBox | js |

login to sohu passport while firefox cookie disabled

If you disabled cookie in firefox3, you can not login to sohu passport include chinaren, even if you add chinaren.com and sohu.com to cookie-allow list.

Here is one walkaround:

run js below in firebug console:

function checkCookieEnabled(){return true}

then click "login" button.

Detail(you can skip):

sohu passport use a function like this to check if cookie is enabled in current browser:

function checkCookieEnabled(){try{if(navigator.cookieEnabled==false){return false}}catch(e){}return true}


But if you disable cookie in browser level, and white-list one site, the navigator.cookieEnabled still return false, which is reported as bug 230350 of firefox. This bug was reported first at 2004-01-07, and is still exists in recent version of 3.0.1.



Tags: cookie | firefox | sohu |

Use emacs23 and xft on debian

  1. add

    deb http://emacs.orebokech.com sid main

    to apt repository /etc/apt/sources.list

  2. install

    apt-get install emacs-snapshot

  3. edit ~/.Xresources
    Emacs.font: bitstream vera sans mono-12
    Emacs.FontBackend: xft
    Xft.dpi: 96
    Xft.hinting: None
    Xft.antialias: 1
    Xft.rgba: rgb
  4. edit ~/.emacs
    (set-fontset-font (frame-parameter nil 'font)
                       'han '("STHeiti" . "unicode-bmp"))

below is snapshot:



Tags: font | emacs | debian | xft |

Widget framework added

Hi, glog has been added a widget framework.

A theme can define widget groups as widgets container for show widgets on page. Template variable "wgroup1...n" which is list of widget string will be pass to template engine. Theme can fetch widget content from URL like "/blogId/widget/widgetid/widget_param" by ajax or something else.

User specify which widgets will be shown and group them by a simple rule.

Widget developer just need write a python module, import the widget module define a module function and register it. Of course, developer must write a templete file for this widget named "widgetid.widget".

I'll give some example later. But if you read the source you'll find that Tags cloud, Archives list, Blog infomation, RecentComment has implemented as widget.



Tags: widget | glog |

New unix site

Uinx-center's aim is to provide a hardware and software platform for teachers, students and enginners to research, study and use various edition of unix or unix-like OS.
sun.sevenever.com for t1000.unix-center.net
bsd.sevenever.com for freebsd.unix-center.net
I complied the "fuck" program on solaris and freebsd and it worked.I'll try it on Loongson debian System.



Tags: unix |

增加了三个feed

一个是整个glog的comments

一个是某个blog的comments

一个是某个post的comments



Tags: glog | rss |

增加了一个主题: Press.Anatomy

增加了一个主题,,就是现在用的这个,拷贝自WordPress的Press.Anatomy主题.



Tags: theme | glog |
sevenever@gmail.com
Copyright © 2008. All rights reserved.