Thursday, January 6, 2011

SVN

Create a repository -
$svnadmin create ~/repo

Copy existing project files to repository
$svn import ~/project file:///home/username/repo/project

Create a sandbox project directory under version control
$svn co file:///home/repo/project
This will create a directory project in the current directory.

Commit changes
$svn ci -m "...."

Go back to the 3rd commit
$svn revert -r 3

Update local sandbox
$svn update

Tuesday, January 4, 2011

SWIG ; Lets u call C++ functions from Python

SWIG simply put is a program that allows you to call C/C++ functions from Python. What that essentially means you get both the speed of C/C++ and the amazing scriptability of Python. Installing SWIG on debian systems is simple as

$ sudo apt-get install swig

Python.h which is required next can be got by

$ sudo apt-get install build-essential

Lets say you have a C++ file euler.cpp. In order to use SWIG include the following header file #include </usr/include/python2.6/Python.h> at the first line of euler.cpp. Now in order to call euler.cpp functions from Python, we first need to create a interface file called euler.i with the following lines

%module euler
%{
       #include "euler.cpp"
%}
%include "euler.cpp"

The next thing to do is to generate the Python module euler.py by the following commands

$ swig -c++ -python euler.i
$ g++ -c -O3 -fPIC euler_wrap.cxx -I /usr/include/python2.6/
$ g++ -shared -O3 euler_wrap.o -o _euler.so

If there are no errors in your code or what you typed you should see euler.py in the directory. Run python and call your required function by
>>> import euler
>>> euler.requiredfunction()

Glovepie Wiimote as controller for PC

// Type your program here, or click the GUI tab to autogenerate it!

key.X = Wiimote.One
key.C = Wiimote.Two
key.Down = Wiimote.Left
key.Up = Wiimote.Right
key.Right = Wiimote.Down
key.Left = Wiimote.Up
key.Space = Wiimote.A
key.Enter = Wiimote.Plus
var.zz = Wiimote.A

wait 100 ms

Glovepie Wiimote Nunchuk as mouse

if Wiimote.Nunchuk.JoyX<-0.21
Mouse.CursorPosX=Mouse.CursorPosX-9
end if

if Wiimote.Nunchuk.JoyX>0.21
Mouse.CursorPosX=Mouse.CursorPosX+9
end if

if Wiimote.Nunchuk.JoyY<-0.21
Mouse.CursorPosY=Mouse.CursorPosY-9
end if

if Wiimote.Nunchuk.JoyY>0.21
Mouse.CursorPosY=Mouse.CursorPosY+9
end if

if Wiimote.Nunchuk.ZButton=1
Mouse.LeftButton=1
wait 250 ms
Mouse.LeftButton=0
end if

if Wiimote.Nunchuk.CButton=1
Mouse.RightButton=1
wait 250 ms
Mouse.RightButton=0
end if

Glovepie Mouse click

// Type your program here, or click the GUI tab to autogenerate it!
x=1
if x
   Mouse.CursorPosX=1021
   Mouse.CursorPosY=684
   Mouse.LeftButton=1
   wait 200 ms
   Mouse.LeftButton=0
   Mouse.LeftButton=1
   wait 200 ms
   Mouse.LeftButton=0
end if

How to make 1080p Blu Ray movies work

Note - VLC may not work for such high quality mkv files 
# Hehe this is circa 2008. So now it should not be a issue.

1.Install coreavc codec
2.Install gom player
3.gom player settings
Preferences -> Filter -> Use Windows Media source filter
Under Disable Filters -> Enable Quick play
4.Install Audio codec

Recording audio ; windows

from Tkinter import *
root = Tk()

import tkSnack
tkSnack.initializeSnack(root)
import time
f=open("E:\\record.wav","wb")
f.close()

r=tkSnack.Sound(file='e:/record.wav',frequency=11025,channels=1)
r.record(fileformat="WAV")

import threading

def pause():
    r.stop()
    print "Recording over"
   
t=threading.Timer(120.0,pause)
t.start()