01110100110101010101011101100010
Linux
Getting started with pthread
Sep 25th
Recently i have started coding in C a lot and what i came across from a lot of people is that doing Threading in C is very hard, is it really like that? here is a simple Pthread program that should clear that up
get it here
in the above program i have just created 2 threads and passed thr1 ( = 1 ) and thr2 ( = 2 ) values as parameters the function void * thread ( void * ptr ) is executes as a separate thread, we create two thread objects thread1 and thread2, and start threads using pthread_create function passing thread object, function pointer and parameters as arguments, here NULL specifies default attributes for the thread, we can change this by passing pthread_attr_t structure instead of NULL.
we wait for the threads to finish using the pthread_join function
One major problem that is faced by most of the people is of using a library which is not a thread safe library, so you need to be careful about the libraries you use in your program, if not sure about a particular library being thread safe, just assume it not to be thread safe
PS – No updates from a long time as i dont have a proper net connection ….
How Manipal got its first Linux (fedora) server
Jun 25th
It all started with a failing Student’s Teacher Feedback System, designed by few fourth year students of my college, in oct-nov 2008 the system was not able to scale and everything was reverted back to paper, it was then when i was contacted by a teacher from my Department ( Information and Communication Technology ), regarding if i can improve it.
i asked DJ if he wants to join me and after few weeks of coding there it was Manipal university’s first (working) Feedback System, when the point of hosting it came, i was surprised to find Manipal University has no Linux servers, i mean come on no Linux what are you people click sys admins, then we decided to setup our own server in the department, thus giving Manipal university its first Linux ( fedora 10 ) server.
currently it just hosts the Feedback System, but we are planning to use it as local ( internal ) fedora repository mirror, we need permission from the WiFi provider ION because almost all the students use only WiFi and not LAN, last time we tried we were denied by saying ” You are a threat to our network “, lets see how it goes this time. we will also require people to manage it but i think this can be handled very well by LUG Manipal, some pics
PS – i am looking for a way to convince them that setting up a mirror will be helpful for them as well as students can anyone suggest me how to go about it??
Get updates of completed torrents via SMS
Apr 6th
This Sunday when i was giving DBUS a look and thinking about all the cool things possible with it, one of my friend came asking how can he control his torrents from anywhere and i thought controlling is ok, do you want SMS updates??, i fired up qdbusviewer and there it was a simple way to get sms notifications of finished torrents using well twitter and ktorrent, so here are the steps
1) setup your cell phone to recieve SMS updates in twitter,
2) get one more twitter account lets say ktorrent, follow ktorrent and turn device updates on,
3) now save the script below say as torrenttwit.py
4) now enter this ktorrent account username and password in the script below,
5) start ktorrent if not already started, now run the script by typing “python torrenttwit.py”
import dbus,base64,urllib2,urllib
from dbus.mainloop.glib import DBusGMainLoop
DBusGMainLoop(set_as_default=True)
username="username"
password="password"
def tweet(msg):
request = urllib2.Request('http://twitter.com/statuses/update.json')
request.add_header('Authorization', 'Basic %s' % base64.encodestring('%s:%s' % (username,password))[:-1])
request.add_data(urllib.urlencode({'status': msg.encode('utf-8')}))
opener = urllib2.build_opener()
req= opener.open(request)
s = dbus.SessionBus()
kt = s.get_object("org.ktorrent.ktorrent","/core")
def update(k):
torrent = s.get_object("org.ktorrent.ktorrent","/torrent/"+k)
name = torrent.get_dbus_method("name","org.ktorrent.torrent")
tweet("ktorrent: finished " +name())
kt.connect_to_signal("finished",update)
import gobject
loop = gobject.MainLoop()
loop.run()
you are done, now whenever a torrent finishes the script will twit and you will receive an SMS update
enjoy
ION proxy login problem
Feb 16th
a few days ago ION (WiFi provider in Manipal University) started an ISA based proxy using NTLM authentication, which according to them was a client install!!! some people were facing problem with it, like their browsers were asking for authentication (login) again and again, and repositories were not working on Linux.
So here is a simple screencast with solution for this problem it works great in Linux (esp. Fedora) i have also included configuring yum here, if someone wants to use apt-get (debian/ubuntu) they can do
export http_proxy=http://127.0.0.1:5865
Ok coming to the main point, go and download http://sourceforge.net/projects/ntlmaps/ and then watch the video here
People on windows can install python from here and then follow the steps
ION proxy problem solved
Note:- If You face any problem please post back here….
PS:- every thing in Text form coming soon… (i am lazy)
HowTo MPD with Pulse audio
Feb 13th
A Little background, i just shifted to mpd from Amarok 2.0 somewhy i dont seem to like Amarok 2 but thats a different story, For those who dont know MPD s a flexible, powerful, server-side application for playing music. which runs as a daemon and has a lot of front ends for it, Sonata being a popular one.
now coming to the point i use Fedora 10 and it has Pulseaudio by default, now the problem is i some time get “NO Read Permission” in Sonata and then mpd would stop working, in mpd.log file i will find “Error opening ALSA device “hw:0,0″: Device or resource busy” error, which means this is an pulseaudio permission issue, to solve it we need to change the mpd.conf (/etc/mpd.conf) to
audio_output {
type "pulse"
name "My Device"
device "hw:0,0" # optional
format "44100:16:2" # optional
}
then we need to add
load-module module-native-protocol-tcp auth-anonymous=1
to /etc/pulse/default.pa which gives everybody permission to use pulseaudio and thats it.
Ejecting non responding drives in Linux
Dec 10th
One of the biggest (not necessarily) problems that most (new) Linux users face is the problems of non responsive drives, espically when u insert a curropt CD / DVD which refuse to come out because something is trying to access it… or the extremely slow flash drives there are some software for it in windows like Unlocker ( dont remmember the correct name scine i dont use it ) but here we dont need any specific software we have had that feature from a long time and well its as simple as 2-3 lines on terminal and its name is ” fuser ” which is basicly used to displays the PIDs of processes using the specified files or file systems. and we can easily use it for our perpose, lets take an example suppose we need to remove the non responsing CD, for that you need to be root, do
su -
or
sudo -i
then type
fuser -k /dev/sr0
or
fuser -k /dev/cdrom0
which will kill all the process accessing that particular device, now you can easily eject the by doing
eject /dev/sr0
or
eject /dev/cdrom0
and you are done.
PS - " fuser " is useful in many more ways then just ejecting drives see " man fuser " for more info
My Conky config
Nov 26th
Conky as its description says ” It is a free, light-weight system monitor for X, that displays any information on your desktop. ” which well describes all that is there, and there are many different ways to configure it, well to be presise there are 250+ objects so the configuration options are limitless
above is the image of my Desktop running conky and i have 2 file one ” .conkyrc ” and other ” .conky/ammarok ” in my home folder (i.e /home/ankur/) the files are
” .conkyrc rename the file to .conkyrc ”
and ” .conky/amarok” which is a amaroK info display script by eirc
you need to place amarok in ~/.conky/amarok make a folder .conky if it does not exist, also make ~/.conky/amarok executable, simply type ” chmod +x ~/.conky/amarok ” enjoy!!!
PS – If you dont have conky simply do yum install conky or sudo apt-get install conky
Synaptics Touchpad in Fedora 9
May 30th
I have been using Fedora 9 from a long time and it really kick’s ass but i was facing the problem that my Touchpad was not working with it but the i found the solution here
Here is how to do it
The easiest was will be to install the package http://atrpms.net/dist/f9/synaptics/
or you can do it manually here
edited the /etc/X11/xorg.conf
gedit /etc/X11/xorg.conf
Added the following to the ServerLayout Section
InputDevice “TouchPad” “CorePointer”
add a new section:
Section “InputDevice”
Driver “synaptics”
Identifier “TouchPad”
Option “SendCoreEvents”
Option “Protocol” “auto-dev”
Option “SHMConfig” “on”
Option “TapButton1″ “1″
Option “TapButton2″ “2″
EndSection
all done logout and login again and everything should be working fine
Update: found the rpm package here
Creating a Simple Chat Application with Python
May 1st
Creating application with Python is very simple, here is a simple chat application made by using the socket module, it has 2 parts First Server and Second client, you run the server first and then connect the client to it, here is the code
Here is the Server Code
#!/usr/bin/env python
from socket import *
from time import time, ctime
IP = ''
PORT = 23456
ADS = (IP, PORT)
tcpsoc = socket(AF_INET, SOCK_STREAM)
tcpsoc.bind(ADS)
tcpsoc.listen(5)
while 1:
print "Waiting for connection"
tcpcli, addr = tcpsoc.accept()
print "connected from:", addr
while 1:
data = tcpcli.recv(1024)
if not data : break
print data
data1 = raw_input(">>")
if data1 == "q;t": break
tcpcli.send(data1)
tcpcli.close()
tcpsoc.close()
Here is the client code
#!/usr/bin/env python
from socket import *
IP = ''
PORT = 23456
ADS = (IP, PORT)
tcpsoc = socket(AF_INET, SOCK_STREAM)
tcpsoc.connect(ADS)
while 1:
data = raw_input("msg>>")
if not data : break
tcpsoc.send(data)
data = tcpsoc.recv(1024)
if not data: break
print data
tcpsoc.close()
the code above might not be properly intended so you can download the code from http://fb.ankurs.com/tcp_server.py and http://fb.ankurs.com/tcp_client.py
enjoy!!!
Making Xml dump of MySQL
Mar 18th
Yesterday when i was trying/searching for a way to generate XML file from PHP so as to use it in Project 11, i came across a way to make a direct database/table dump from mysql and its damn easy all you have to do is type
mysqldump -u username -p --xml databasename > data.xml
and it will dump whole database into the data.xml file enjoy!!!!
PS:- Info about Project 11 coming up…..






