To create a device node use mknod
mknod /dev/mem c 1 1
here the device name is /dev/mem
c represents character device this can be block device also
the first 1 represents the major number
the second 1 represents the minor number
Monday, September 14, 2009
Sunday, September 13, 2009
Little Sugar: FreeBSD total RAM
to find out the total RAM installed on your FreeBSD box use something like this
sysctl hw.physmem
sysctl hw.physmem
Thursday, September 10, 2009
Little Sugar: insmod
Linux kernel extensions have a .ko extension are inserted directly into the kernel
using insmod command.
The kernel modules are removed using rmmod.
Kernel modules are generally placed at /lib/modules.
To update kernel dependencies run depmod
using insmod command.
The kernel modules are removed using rmmod.
Kernel modules are generally placed at /lib/modules.
To update kernel dependencies run depmod
Wednesday, September 09, 2009
Finding Document Similarity
If you need to find how similar a document is we can use vector algebra to our advantage. If we have 2 document d1 and d2 then
Let D1 be a vector of the word-frequency of the document d1
Let D2 be a vector of the word-frequency of the document d2
then the deviation of the 2 documents can be calculated by
using the fact that
cos(theta) = (D1 * D2)/(N(D1) * N(D2))
where N(D) is the normalized vector represented by
N(D) = sqrt(D * D)
Let D1 be a vector of the word-frequency of the document d1
Let D2 be a vector of the word-frequency of the document d2
then the deviation of the 2 documents can be calculated by
using the fact that
cos(theta) = (D1 * D2)/(N(D1) * N(D2))
where N(D) is the normalized vector represented by
N(D) = sqrt(D * D)
Wednesday, September 02, 2009
OpenGL: Diffuse, Specular, Ambient, Emissive lights
In the OpenGL world there are different types of light types
Diffuse
--------
These type come from one direction bu are scattered equally in all directions.
Specular
--------
This type of light comes in one directions and is also bounced off in one direction
Ambient
--------
This type of light source comes from different light sources and is also scattered in different directions
Emissive
---------
This represents light originating from the object
So in general A light source has two types of properties associated with it
LR,LG,LB => the RGB components that make up the light and
MR,MG,MB => the RGB components that are reflected away
Hence the net effect of the RGB is given by a vector
(LR.MR, LG.MG, LB.MB)
if light is coming from two or more sources the light is added and next effect is
of the form
(R1 + R2, G1 + G2, B1 + B2)
Diffuse
--------
These type come from one direction bu are scattered equally in all directions.
Specular
--------
This type of light comes in one directions and is also bounced off in one direction
Ambient
--------
This type of light source comes from different light sources and is also scattered in different directions
Emissive
---------
This represents light originating from the object
So in general A light source has two types of properties associated with it
LR,LG,LB => the RGB components that make up the light and
MR,MG,MB => the RGB components that are reflected away
Hence the net effect of the RGB is given by a vector
(LR.MR, LG.MG, LB.MB)
if light is coming from two or more sources the light is added and next effect is
of the form
(R1 + R2, G1 + G2, B1 + B2)
Tuesday, September 01, 2009
Opengl : Hidden Surface Removal and LIghting
Hidden surface removal is a common technique in the graphics world. The technique says
we should draw only parts of objects that are visible to the user.
What support does OpenGL have for hidden surface removal.OpenGL supports hidden surface removal through a combination of DEPTH BUFFER and COLOR BUFFER.
Depth Buffer and Color Buffer
------------------------------
Our screen is flat basically we see a flat 2D rectangular screen made up of pixels. Associated with these pixels we have a corresponding value in the Depth Buffer and
Color Buffer. So what pixel appears forward or backward depends on its value in the depth buffer. The color value it shows depends on its value in the color buffer.
to enable the depth buffer we need use something like the following:
glClear(GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT);
Material And Ambient Light
---------------------------
OpenGL understands RGB. A material quality decides the amount of RGB that is reflected or absorbed. An area can be lit by many light sources.Say in a room the bulb can the primary source of light.But there might be light reflected from walls which can be called secondory sources, the light contributed by such sources is called ambient light.
we should draw only parts of objects that are visible to the user.
What support does OpenGL have for hidden surface removal.OpenGL supports hidden surface removal through a combination of DEPTH BUFFER and COLOR BUFFER.
Depth Buffer and Color Buffer
------------------------------
Our screen is flat basically we see a flat 2D rectangular screen made up of pixels. Associated with these pixels we have a corresponding value in the Depth Buffer and
Color Buffer. So what pixel appears forward or backward depends on its value in the depth buffer. The color value it shows depends on its value in the color buffer.
to enable the depth buffer we need use something like the following:
glClear(GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT);
Material And Ambient Light
---------------------------
OpenGL understands RGB. A material quality decides the amount of RGB that is reflected or absorbed. An area can be lit by many light sources.Say in a room the bulb can the primary source of light.But there might be light reflected from walls which can be called secondory sources, the light contributed by such sources is called ambient light.
ps options
If you invoke the ps command like this
ps -C -o etime,pid,pri,cmd
this will show processes that match the command name and show output using the
fields followed after -o i.e
etime - how long the process is running
pid - the pid of the process
pri - priority of the process
cmd - the full command line of the command
ps -C
this will show processes that match the command name and show output using the
fields followed after -o i.e
etime - how long the process is running
pid - the pid of the process
pri - priority of the process
cmd - the full command line of the command
Sunday, August 30, 2009
Looking back at mergesort
For mergesort the recurrence relation is
T(N) = 1 if N == 1
T(N) = cn + 2T(N/2) if N != 1
so if we draw the recursion tree for such a recurrence relation we get
Height of tree = lg N
Number of leaves = N
--------------
Leaves at level 0 -> 1
Leaves at level 1 -> 2
Leaves at level 2 -> 4
Leaves at level 3 -> 8
...
Leaves at level lg N -> N
Total Work Done
----------------
Work done at level 0 -> cn
Work done at level 1 -> cn
Work done at level 2 -> cn
....
Work done at level lg N -> cn
So total work done => cn * lg N => O(n lg n)
T(N) = 1 if N == 1
T(N) = cn + 2T(N/2) if N != 1
so if we draw the recursion tree for such a recurrence relation we get
Height of tree = lg N
Number of leaves = N
--------------
Leaves at level 0 -> 1
Leaves at level 1 -> 2
Leaves at level 2 -> 4
Leaves at level 3 -> 8
...
Leaves at level lg N -> N
Total Work Done
----------------
Work done at level 0 -> cn
Work done at level 1 -> cn
Work done at level 2 -> cn
....
Work done at level lg N -> cn
So total work done => cn * lg N => O(n lg n)
Similarity between objects
Lets say we need to find the similarity between people based on how they rank different items. Based on the that collected data we need to recommend some new
items to the users.People who are similar to each other have a higher likelihood of
liking things that we recommend them.
Now lets consider a Set of Users.A Set of Items and a set of Rankings which users give to these Items.
Given this information how can we find the similarity between 2 Users.
Approach 1)
------------
Take user A and user B
Calculate union of items chosen by user A & B , call it A_UNION_B
Calculate the intersection of the items chosen between A & b, call it A_INT_B
then the value A_INT_B/A_UNION_B represents the similarity of the 2 users A and B
Approach 2)
------------
For every item that is common between A & B we can calculate the Euclidean distance between the rankings of the 2 items.
D = RA (ranking A gave to an item) - RB (ranking B gave to an item)
Sum = Sum + D^2
The once we have the sum we can call it Similarity Sum and use a formula
like
Similarity = 1/(1 + Sum)
The 1 is added to prevent the 1/0 off case, where our magic factor factor is 1
we can choose an arbitrary magic factor say N
Then Similarity = N/(N + Sum)
Approach 3)
-----------
Use the Sum that we got in Approach 2 above
Similarity = Sum / N where N is the number of items common between A and B that have the same rating
Similarity = Sqrt(Similarity)
then to make Similarity fall between the range 0 and 1
Similarity = 1 - tanh(Similarity)
Approach 4)
-----------
Use the Similarity that we calculated in Approach 3
NN = Number of items common between A and B
Similarity = Similarity * (N / NN)
items to the users.People who are similar to each other have a higher likelihood of
liking things that we recommend them.
Now lets consider a Set of Users.A Set of Items and a set of Rankings which users give to these Items.
Given this information how can we find the similarity between 2 Users.
Approach 1)
------------
Take user A and user B
Calculate union of items chosen by user A & B , call it A_UNION_B
Calculate the intersection of the items chosen between A & b, call it A_INT_B
then the value A_INT_B/A_UNION_B represents the similarity of the 2 users A and B
Approach 2)
------------
For every item that is common between A & B we can calculate the Euclidean distance between the rankings of the 2 items.
D = RA (ranking A gave to an item) - RB (ranking B gave to an item)
Sum = Sum + D^2
The once we have the sum we can call it Similarity Sum and use a formula
like
Similarity = 1/(1 + Sum)
The 1 is added to prevent the 1/0 off case, where our magic factor factor is 1
we can choose an arbitrary magic factor say N
Then Similarity = N/(N + Sum)
Approach 3)
-----------
Use the Sum that we got in Approach 2 above
Similarity = Sum / N where N is the number of items common between A and B that have the same rating
Similarity = Sqrt(Similarity)
then to make Similarity fall between the range 0 and 1
Similarity = 1 - tanh(Similarity)
Approach 4)
-----------
Use the Similarity that we calculated in Approach 3
NN = Number of items common between A and B
Similarity = Similarity * (N / NN)
Wednesday, June 17, 2009
Little Sugar: Writing an oscillator function
Say you need to transform values v1, v2 in such a way that they lie between lowerlimit L and upper limit U
then u can use an oscillator function
new value = U - (L + (U * (1 / (1 + value))))
this new value will be between L and U, if u omit L then new value
would be between 0 - U
then u can use an oscillator function
new value = U - (L + (U * (1 / (1 + value))))
this new value will be between L and U, if u omit L then new value
would be between 0 - U
Thursday, June 11, 2009
Little Sugar: Useful commands while programming on Unix Systems
Here are a list of commands that re use file while programming on unix systems
pid = process id
ps aux | grep process_name
- to search for a given process name , generally use this to fetch pid of process
lsof -p pid
- to get all the files or file descriptors being used by the process having pid
lsof | grep file_name
- to get the list processes using a given file
sockstat | grep process_name
- to see the socket connections between a host and desinations
strace -p pid
- to see what the process is doing in general
nc hostname port
- to see data flowing from the hostname at the given portu
pid = process id
ps aux | grep process_name
- to search for a given process name , generally use this to fetch pid of process
lsof -p pid
- to get all the files or file descriptors being used by the process having pid
lsof | grep file_name
- to get the list processes using a given file
sockstat | grep process_name
- to see the socket connections between a host and desinations
strace -p pid
- to see what the process is doing in general
nc hostname port
- to see data flowing from the hostname at the given portu
Tuesday, June 09, 2009
Little Sugar: Things to remember while creating a daemon
While writing a daemon on unix systems. The daemon should not be attached to any
terminals. So make sure the following things hold valid.
chdir '/'
umask 0
Map STDIN to /dev/null
Map STDOUT to your logging system
MAP STRERR to STDOUT
setsid # Make the daemon a session leader
terminals. So make sure the following things hold valid.
chdir '/'
umask 0
Map STDIN to /dev/null
Map STDOUT to your logging system
MAP STRERR to STDOUT
setsid # Make the daemon a session leader
Subscribe to:
Posts (Atom)
Labels
. linux
(1)
algorithm
(15)
analytics
(1)
bash
(2)
bigoh
(1)
bruteforce
(1)
c#
(1)
c++
(40)
collections
(1)
commands
(2)
const
(1)
cosine similarity
(1)
creating projects
(1)
daemon
(1)
device_drivers
(1)
eclipse
(6)
eclipse-plugin-development
(9)
equals
(1)
formatting
(1)
freebsd
(1)
game programming
(1)
hashcode
(1)
heap
(1)
heaps
(1)
immutable-objects
(1)
java
(19)
JDT
(1)
kernel
(1)
linux
(4)
little sugar
(23)
logging
(1)
machine learning
(1)
marker-resolution
(1)
markers
(1)
mergesort
(1)
mixins
(1)
numbers
(1)
opengl
(2)
patterns
(2)
priority-queue
(1)
programming
(51)
ps
(1)
ranking
(1)
refactoring
(3)
references
(1)
security
(1)
set
(1)
shell
(1)
similarity
(1)
statistics
(1)
stl
(1)
tetris
(1)
threads
(1)
trees
(2)
unicode
(1)
unix
(2)
views
(2)
windows programming
(2)
XNA
(1)