#include
#include
#include
char* getenv2(char * environment)
{
fprintf(stdout,"getenv2(%s)\n",environment);
fflush(0);
return getenv(environment);
}
int _init()
{
printf("%s\n","Loaded ctype shared library");
return 0;
}
#ctypedemo.py
from ctypes import *
from ctypes.util import find_library
import sys
ctype_sl = cdll.LoadLibrary('./libctypedemo.so.1') # load library
getenv_ = ctype_sl.getenv2(sys.argv[1]) # get 1st arg
ret = c_char_p(getenv_) # cast to char*
if ret:
print "\{0}={1}".format(sys.argv[1],ret.value)
#sharedlibcompile.sh
gcc -Wall -fPIC -c ctypedemo.c
gcc -shared -nostartfiles -Wl,-soname,libctypedemo.so.1 -o libctypedemo.so.1 -lc ctypedemo.o
export LD_PRELOAD=./libctypedemo.so.1
$ls
ctypedemo.c
ctypedemo.py
sharedlibcompile.sh
$./sharedlibcompile.sh
$ python ctypedemo.py PATH
Loaded ctype shared library
getenv2(PATH)
value for PATH=/usr/local/bin:/usr/local/sbin/:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/sbin:/bin:/usr/games
Hope you enjoyed the tiny intro. Feedbacks are welcome (constructive or destructive otherwise).
4. For FAN Control
You would need to compile a litle piece of software: dellfand
http://dellfand.dinglisch.net/
sudo apt-get install g++
wget http://dellfand.dinglisch.net/dellfand-0.9.tar.bz2
tar xvjf dellfand-0.9.tar.bz2
cd dellfand-0.9; make
For testing purposes:
root@vostro:/tmp/dellfand-0.9# ./dellfand
v0.9: Fan 0 Status 1 Speed 61980 CPU Temp 31C
For installing it and enabling for default
sudo cp etc.default.dellfand /etc/default/dellfand
sudo cp etc.init.d.dellfand /etc/init.d/dellfand
sudo update-rc.d dellfand defaults
sudo /etc/init.d/dellfand start
With dellfand the fan in your system would cool it when the temp is higher.
nepbabu said: coolguy: just call them up and ask yaar. maybe they'll do something about it?
coolguy said: nepbabu, they suck I have to listen jingles and wait in line to get support only to get some employee who's yawning and knows nothing and say he willl report to other senior
This sort of behaviour is all over Nepali Telecom sector and not only in ISP sector but all over other sectors as I have first-hand experience with it and I believe its this kind of behaviour has to change for goodness sake!
Back to Ubuntu-np. We are planning to host the website somewhere down the line and a big thanks to Gaurav and Himanshu for the head up! We'll probably use one of their hosting service and use Moinmoin, Just so that I do not forget, I need to do some reading for android and starting coding up apps for it. Its just an urge because Java is pretty cool language itself :-) and one can make a lot of productive apps using it very quickly.
$ lsusb | grep Log
Bus 004 Device 002: ID 046d:089d Logitech, Inc.
I sat down couple of hours ago to make it work on my Linux box;
Couple of head banging for not remembering the module parameters and it was finally done.
The following are the steps I took to make it work -
1) Downloaded gspca source
* wget http://mxhaard.free.fr/spca50x/Download/gspcav1-20071224.tar.gz
* tar -xvf gspcav1-20071224.tar.gz
2) Downloaded a patch specific to my webcam -
* wget http://forums.quickcamteam.net/attachment.php?aid=86 -O patch.tar.gz
* tar -xvf patch.tar.gz
* cd gspcav1-20071224
* patch -p1 < ../quickcamE2500.diff
3) Compiled and installed the patched kernel module -
* cd gspcav1-20071224;
* make;
* sudo cp gspca.ko /lib/modules/2.6.24-19-generic/ubuntu/media/gspcav1/
4) Reloaded the gspca module with additional parameters -
* sudo modprobe -r gspca;
* sudo modprobe gspca autoexpo=0 gamma=2
5) Installed gstfakevideo for skype since it used 90% of my CPU when video was enabled. More info is available here
* svn checkout http://gstfakevideo.googlecode.com/svn/trunk/ gstfakevideo ('subversion' package must be installed)
* cd gstfakevideo
* make
* sudo make install
* sudo mv /dev/video0 /dev/video1
* ./gstfakevideo v4lsrc device=/dev/video1 ! ffmpegcolorspace (this will fire off skype)
(Say cheese! :>)
5) Tried each of the following -
* xawtv (worked)
* mplayer tv:// -tv driver=v4l:width=352:height=288:outfmt=yv12:device=/dev/video0 (worked)
* skype (worked after I provided the module parameters "autoexpo=0 gamma=2")
* ekiga (worked)
* cheese ( this didn't work for me )
Note: It will take some time for skype and ekiga to load up the image from the webcam. Be patient :)
Have fun! :)
Basically, all one has to in ubuntu/debian is to install 'xbindkeys' package-
$ aptitude install xbindkeys
Check for the keycode-
$ xbindkeys -mk # -h for more info
Press combination of keys or/and click under the window.
You can use one of the two lines after "NoCommand"
in $HOME/.xbindkeysrc to bind a key.
--- Press "q" to stop. ---
"(Scheme function)"
m:0x8 + c:153
Alt + XF86AudioNext
(In the above instance, I've pressed Alt and Dell's Next button)
Then create ~/.xbindkeysrc and dump those lines from above-
$ vim ~/.xbindkeysrc
1 # forward 10 secs
2 "dcop amarok player seekRelative +10"
3 m:0x8 + c:153
4 Alt + XF86AudioNext
5
6 # rewind 10 secs
7 "dcop amarok player seekRelative -10"
8 m:0x8 + c:144
9 Alt + XF86AudioPrev
Then add it to autostart (when KDE session starts)-
$ vim ~/.kde/Autostart/xbindkeys
1 #!/bin/sh
2 /usr/bin/xbindkeys;
If one runs Gentoo, have a read through http://gentoo-wiki.com/HOWTO_Use_Multimedia_Keys
Enjoy!
On xterm:
bikal@zebra:[~] time cat /usr/share/dict/words
...(((snip)))...
real 0m11.080s
user 0m0.000s
sys 0m0.056s
bikal@zebra:[~] time find /usr/src/linux/
real 0m3.759s
user 0m0.064s
sys 0m0.092s
On konsole:
bikal@zebra:[~] time cat /usr/share/dict/words
...(((snip)))...
real 0m2.555s
user 0m0.004s
sys 0m0.056s
bikal@zebra:[~] time find /usr/src/linux/
...(((snip)))...
real 0m1.136s
user 0m0.072s
sys 0m0.064s
Haven't tried aterm or gnome-terminal :-))) The only reason I prefer Konsole over gnome-terminal and others is the facility it provides and useful features such as bookmarking, schema settings and loads of others..
- Absolutely no open hardware and software specification available to the public. - Costs sub US $100 dollars [thumbs up for that]. - Is hyped up as the next "big" cheap solution - Customer's data is stored on the server [yikes!] - Will be sold back to some tech giant/s some day. [Read: NOVA NETPC userbase could be screwed] - Has no documentations available to the public. - Anyone's got any clue how hackable* it is?Unlike the merits of LTSP-based system, novatium netpc is a full-fledged device in itself with on-board capability for networking, video, voice many more. The whole device is made to work on subscription model where you subscribe to the service provided by ISPs to get service for your internet, music, television etc. The netpc's website is abysmal [read: full of advertisements, SWFs and static contents], no documentations and thinks that public can get better idea of what this whole shebang is without reading the docos. You'll get better idea from other newspaper articles doing the adverts for Nova NETPC and since Google is a dictionary word, I'd love to say scroogle it. It might sound little stupid for me to say some really stupid things about such a wonderful little beastie but there are alternatives to Nova NetPC and NET PCs [Intel, HP, IBM and other major players have sub $1000 PCs in the US market] which may or may not be in-demand [according to who you ask]. Implementing LTSP with donated hardware could be the best possible low cost solution for now [until they figure out open systems that have proper system specs and documentations so that people could adapt it to suit their need] [Update: I remember one of my friend saying donated hardware is considered "harmful" electronic wastage. What a pity and a waste of wastage!] Finally, for US $110-120 range, in India, anyone will be able to buy second-hand machines that have full pirated software loaded with Microsoft Windows Vista. <grounded="nepbabu> Last update [hopefully]: An interesting read http://economist.com/specialreports/displaystory.cfm?story_id=10053304 </grounded="nepbabu>
#include "unistd.h"
int main()
{
int p = 0;
for (; p < 10; p++)
{
fork();
}
return 0;
}
$ cat /proc/cpuinfo (info deemed uncessary stripped out)
processor : 0
vendor_id : GenuineIntel
model name : Intel(R) Pentium(R) M processor 1.50GHz
cpu MHz : 600.000
cache size : 2048 KB
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat clflush dts acpi mmx fxsr sse sse2 ss tm pbe nx est tm2
bogomips : 1198.27
$ time perl memoizing.pl
Fibo of 30 => 832040
real 0m0.071s
user 0m0.048s
$ time perl unmemoizing.pl
Fibo of 30 => 832040
real 0m2.877s
user 0m2.832s
Woahhh!!!
However, this doesn't mean every subroutine/function in Perl has to be memoized. If you scroll down the CPAN page of Memoize.pm module, you'll be able to read some gotchas and above that you'll find other fancy pancy options that you can pass to memoize(). Have Phun!
#memoizing.pl
#!/usr/bin/perl -w
use Memoize; memoize('fib'); #comment this line and see the difference in `time` ;)
#$_=<stdin>; chomp;
print "Fibo of 30 => ",fib(30), "\n"; #fib function is already memoized
# Compute Fibonacci series
sub fib { my $n = shift;return $n if $n < 2; fib($n-1) + fib($n-2);
#unmemoizing.pl
#!/usr/bin/perl -w
#use Memoize; memoize('fib'); #comment this line and see the difference in `time` ;)
#$_=<stdin>; chomp;
print "Fibo of 30 => ",fib(30), "\n"; #fib function is already memoized
# Compute Fibonacci series
sub fib { my $n = shift;return $n if $n < 2; fib($n-1) + fib($n-2);

(In class, students listening, ohh.. thou dedicated students... ;-) Nepalinux thin clients in the background)
(Jwalanta told me that they are fully functional PC but without a hard-disk and are connected to a server but thin clients they are)
(Eager to learn! :-))
(Serious at work! DND them. :-) )
(On the way to Dhading :-) )
(Bus stuck in the river. :-( )
(Carefully listening to lecture given by Amit. :-) )
You can find Daya's blog here
Permanent link to this comic: http://xkcd.com/237/
// project created on 24/12/2007 at 5:55 AM
using System;
/*
* A minimal linked list implementation.
* Simple data model to aid understanding of singly-linked list: [node1:next==]==>[node2:next==]==>[....nodeN:next==]==>NULL
*
* The furthest this code can do I believe is help you understand singly-linked list. :-)
* It's krismas time and I am a little bit drunk so spare the bugs if any [given that
* it was coded in ~1 hour]
*
*/
namespace LinkedList
{
class Node {
public int data;
public Node next;
public Node(int d, Node n) {
this.data = d;
this.next = n;
}
}
class LL {
public Node firstnode;
public LL() {
firstnode = new Node(-1,null);
}
/*
* Insert a value at the end of the list.
*/
public void insertLast(int data) {
Node insertion_node = new Node(data,null); //the temporary object to be inserted in the end.
Node current_node = firstnode;
while (current_node.next != null) {
current_node = current_node.next;
}
current_node.next = insertion_node;
insertion_node.next = null; //nullify the last node's next pointer
}
/*
* return the size of the linked list
*/
public int size() {
Node thisnode = this.firstnode;
int counter = 0;
while (thisnode.next !=null) {
thisnode = thisnode.next;
counter++;
}
return counter;
}
/*
* return the 'data' (int32) at the given position
*/
public int at(int position) {
Node thisnode = this.firstnode;
int counter = 0;
while (thisnode.next != null) {
if (counter == position) {
return thisnode.next.data;
}
else {
thisnode = thisnode.next;
}
counter++;
}
if (thisnode.next == null) {
return thisnode.next.data;
}
return -1;
}
}
class MainClass
{
public static void Main(string[] args)
{
LL linkedlist = new LL();
Console.WriteLine("Inserting some dummy values.....");
for (int i = 0; i < 10; i++) {
linkedlist.insertLast(i);
}
//Debugging only.
//Console.WriteLine(linkedlist.size());
Console.WriteLine("Printing out the values....");
for (int i = 0; i < linkedlist.size(); i++) {
Console.WriteLine("At " + i + ": " + linkedlist.at(i));
}
}
}
}
#!/usr/bin/env python
# This one-liner code prints combination of (x,y) values such that (x%2==0 and y%2==1) from from 0..19 inclusive.
print [(x,y) for x in range(20) if x % 2 == 0 for y in range(20) if y % 2 == 1]
/* Check user entered password's strength based using
* cracklib (http://sourceforge.net/projects/cracklib/)
*/
#include "crack.h"
#include "stdlib.h"
#include "unistd.h"
#include "stdio.h"
#define OK 1
#define NOTOK 0
int main(int argc, char *argv[]) {
char* why;
char* passwd;
int status = NOTOK;
printf("\nPress Ctrl-D or enter an empty password to quit.\n");
while ((passwd = getpass("\nPassword: ")) != NULL && *passwd ) {
//check for user entered password with the dictionary.
if ((why = FascistCheck(passwd, CRACKLIB_DICTPATH)) != NULL) {
printf("Password is bad: %s.\n",why);
status = OK; //reset status
}
else {
printf("Nice password\n");
}
//spit out the passwd for debugging
//printf("\nYou entered: %s \n", passwd);
}
exit(status);
}
[1]man cracklib FascistCheck;