Begining Python workshop

January 27th, 2010 / No Comments » / by Ankur Shrivastava

LUG Manipal python workshop

LUG Manipal python workshop poster

LUG Manipal is organising a workshop on python, Workshop is aimed at people interested in beginning programming with python.No programming experience required.

Details are ->
Time: 5:30 pm
Place: NLH 103
Date: 29th JAN to 3rd FEB

PS :- Slides for the workshop are available Begining Python Slides

Tags:

Mobi Vision 2.0 Slides

October 15th, 2009 / No Comments » / by Ankur Shrivastava

First and Second Phase for MobiVision 2.0 is long over, and we can call it a workshop well done, the slides are here

Getting started with pthread

September 25th, 2009 / No Comments » / by Ankur Shrivastava

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 ….

Tags: , , , ,

A simple python socket chat example

July 30th, 2009 / No Comments » / by Ankur Shrivastava

i was trying to explain sockets to one of my friend and this is what i used, the code should be self explanatory, this is a very simple application of sockets…

download here

Tags: , ,

How Manipal got its first Linux (fedora) server

June 25th, 2009 / 6 Comments » / by Ankur Shrivastava

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

Fedora 10 server in Manipal

Fedora 10 server in Manipal


Fedora 10 server in Manipal

Fedora 10 server in Manipal

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??

Tags: , , , , ,

Removing windows viruses from pen drives/HDD

June 15th, 2009 / 2 Comments » / by Ankur Shrivastava

last week i gave my 250GB HDD to one of my friend and when i got it back it was filled with viruses, it was that virus which creates .exe inside every , since there were a lot of folders in the HDD ( it was 200GB full ) it was practically impossible for me to go and delete every virus in there, so i decided to make a simple script to remove these viruses here it is

Download here

PS – please be careful if you have windows programs they can also get deleted

Tags: , , ,

Creating your own service like tinyurl

May 24th, 2009 / 5 Comments » / by Ankur Shrivastava

Few weeks ago i came across this article on Techcrunch which says tinyurl is worth $46Million (of course before twitter started using bit.ly as default) which made me think how hard is it to make a simple service like tinyurl and i figured out its not hard. so i used apache’s mod_rewrite to rewrite the url and forward the code to a php script ( url.php ) which will then search for the url in database and take the use to the original url and for shorting, url it is inserted into a table with a auto increment primary key and the key is converted to base36 which contains [a-z] and [0-9], making the short code…

First create a database say ’shorturl’
CREATE TABLE IF NOT EXISTS `shorturl` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`url` varchar(300) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

then create file .htaccess where you want your url to be and write
RewriteEngine On
RewriteCond %{REQUEST_URI} \/([0-9a-z]*)$ [NC]
RewriteRule ^(.*) url.php?url=%1 [L]

and to create the url we will use a simple file say create.php

<html>
<head>
<title>Url Shortner</title>
</head>
<body>
<?php
ob_start();
$host=""; //host
$dbuser=""; // database username
$dbpass=""; // database password
$db=""; //database name
$con = mysql_connect($host,$dbuser,$dbpass);
mysql_select_db("url",$con);
if (!isset($_POST['shorten']))
{
echo "<center><h3>Enter the url to shorten</h3><form method='POST'><input type='text' name='url' />
<input type='submit' name='shorten' value='Shorten' /></form></center>";
}
else
{
if (isset($_POST['url']))
{
$url=" ".mysql_real_escape_string($_POST['url']);
if (strpos($url,"http://") or strpos($url,"https://") or strpos($url,"ftp://"))
{
$url=mysql_real_escape_string($_POST['url']);
}
else
{
$url="http://".mysql_real_escape_string($_POST['url']);
}
$q="select * from url where url='{$url}'";
$res = mysql_query($q,$con);
$row=mysql_fetch_row($res);
if (!$row)
{
$query="insert into url set url='{$url}'";
$res = mysql_query($query,$con);
}
$query1="select id from url where url='{$url}' limit 1";
$res=mysql_query($query1,$con);
$row=mysql_fetch_row($res);
echo "shortened url is http://yoursite.com/".base_convert($row[0],10,36);
}
}
ob_end_flush();
?>
</body>
</html>

then our url.php file

<?php
ob_start();
$host=""; //host
$dbuser=""; // database username
$dbpass=""; // database password
$db=""; //database name
$con = mysql_connect($host,$dbuser,$dbpass);
mysql_select_db($db,$con);
if (isset($_GET['url']))
{
$query="select * from url where id ='".base_convert(mysql_real_escape_string($_GET['url']),36,10)."'";
$res = mysql_query($query,$con);
$row=mysql_fetch_row($res);
header("Location: ".$row[1]);
}
ob_end_flush();
?>

Download here

Tags: , ,

Get updates of completed torrents via SMS

April 6th, 2009 / 4 Comments » / by Ankur Shrivastava

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

Tags: , , , , , ,

JavaFX and Pong

March 1st, 2009 / 1 Comment » / by Ankur Shrivastava

There was a workshop conducted by engineers form SUN in our college regarding JavaFX, which went quite well. I was planning to start with JavaFX but as there was no Official release of any Linux SDK, it kept me back but this semester i had to install Windows because of my University which wants me to use Visual Studio for my mini project this semester, so as i had Windows (unwillingly) on my system i planned to go and attend this JavaFX workshop.
From what i have learned in these two days, JavaFX looks promising for developing Rich Internet Applications, the language is somewhat a mixture of JavaScript and Java. With Type Inference , Audio/Video support etc making it very easy to use and create applications with.
In the workshop after every thing was over we were asked to make a simple application in JavaFX, so here is my code for a Simple pong game in JavaFX
the resolution is set to 1440×900 you can change it to your resolution in the code
Read more…

Tags: , , ,

Using Apple Keyboard in Linux (Fedora)

February 19th, 2009 / 6 Comments » / by Ankur Shrivastava

My Apple Keyboard

My Apple Keyboard


Few Days Ago i received my Apple Keyboard and i am enjoying typing on it, but having to hold down the Fn key then tap one of the F-keys to get F-keys working was irritating.
a simple solution to get it working just add this to your /etc/rc.local file
echo 2 > /sys/module/hid/parameters/pb_fnmode

and F-keys will start to work properly, enjoy

Tags: , , , , ,