IdeaMonk

thoughts, ideas, code and other things...

Friday, July 31, 2009

PyPaste - pastebins at your terminal

This weekend was quite eventful. It started with, unsuccessful trials in creating a GNOME applet in PyGTK and coming to a conclusion after consulting kr0y that, I should practice some glade+PyGTK before trying an applet. Well, that's for the time to come... for right now, I've got a useful tool made in Python for developers out there. I call it PyPaste.
Okay, one question, how many steps do you take to paste your code at a pastebin ? must be something like this -
  1. open a new tab in your browser
  2. copy-paste / browse for your file
  3. select a syntax highlighting mode
  4. copy-paste the url to irc/twitter/mail/wherever you wish
Hmm, so I wondered... could this process be made even shorter and more hacker friendly ?
And hence I came up with PyPaste this weekend which is a python script that helps you in paste-binning your code right from the terminal you're working on. No need to fire-up your browsers or switch windows. No need to drop a list box and select syntax highlighting mode for your code or even to see some ugly ads till it gets done. PyPaste is there to take care of all these thing. All you need to do is -

$ pypaste myfoobar.rb
http://paste.ubuntu.com/######
$

have a look -

there you go, it recognised that we are pasting a shell script, and it highlighted a shell script's syntax :) effortlessness at 2 steps right :) !?

You can also select different pastebin services. Right now it supports paste.ubuntu.com , paste.pocoo.org, dpaste.com and nopaste.com. Well, the list can be extended pretty easily if you study the source. All you need to do is figure out the right POST data for your pastebin and write a module for it. Put it in the modules directory and import it in pypaste_includes.py, and also increment MAX and add an elif branch for your pastebin's prepare() function.
Well, all that might seem complicated right now, but I've tried my best to make it more hackable and extensible.

Now thats what a terminator or GNU screen user's screen looks like :) Geeky isn't it. You've got one irc opened up on top-right, manpage on left, one of the tabs can also open up a vim editor! In such a scenario, PyPaste comes handy and you really don't have to shift to other apps, all you need to do is issue a command and copy-paste to the irc channel where you wish to share your code.

I've put PyPaste on github - Get it here.
Direct link to the tarball -> here.

Right now it works well on linux. Haven't tested on a mac or windows. It might work on a mac after minor hacks, but for making it work on windows you'll have to do some more study of the code.

Happy pasting till then :)

DAMN! I just learnt that there is something called pastebinit, which already does the same thing. +1 for pastebinit for it supports many urls, +1 for PyPaste for it chooses syntax automatically. So, automatic syntax detection still remains a good advantage for PyPaste users.

Labels: , ,

Friday, June 12, 2009

SPOJ Rank Tracker 1.0

Recently, while I was doing a lot of SPOJ in free time, I noticed that ranks and points do vary a lot when you solve more and more problems. Sometimes it drops within 5 minutes and sometimes 5 days, it all depends on what others are upto and how easy the problem was.

And then, when summer break is over people really don't find time to have a look at their status on SPOJ. When one returns after 6 months in a winter break, one finds it discouraging to see the rank drop of hundreds or thousands in some cases. Naturally you would feel "Oh, its gonna take another 40 problems to get ahead!".

But what if you had been a little more updated about whats happening to your rank, won't you have done some more problems, maybe 1 or 2 a day even if you were busy with college or something else. Wondering how bothersome it would be to check SPOJ profile once everyday... well, don't bother anymore for we have an extension for firefox now - SPOJ Rank Tracker, that helps you do the same.
All you need to do is put up a username and it would show you the status of the person. It's as live as you set it to be in the refresh interval, say you ask it to re-check your rank every 2 minutes, it would do so, and would silently sit in a corner in the status bar and let you know what your rank is. All you need to do is turn your eyes a little lower.... .. now don't start thinking that I'm too lazy, so I wrote this thing to save me from some keytaps :-)

Anyways, here is what it looks like in Linux and Windows -


You can find a mention of it on http://www.spoj.pl/ to feel safe about this addon.
You can download it from addons.mozilla.org here - https://addons.mozilla.org/en-US/firefox/addon/12336/

You would probably see it as an experimental addon as, its not yet tested and verified by the addon moderators at Mozilla. For any verification you want to see head on to http://www.spoj.pl/ and checkout the news dated 2009-06-11 16:20:01 for a clarification.

What else? well if you have any performance issues with this addon, or maybe some annoyances that it is creating, do let me know soon. I would try my best to fix the bug as much as I can with as much I know about XUL and extension development stuff.

Well, I don't feel like writing much about this one. But, as far as the experience goes, it was fun indeed, for I always thought writing addons for firefox would be one hell of a hick-up (learning things you don't know... bumping at pebbles on the path). And, guess what, it wasn't at all! In fact XUL and stuff (js, css, ...) that you use to make an addon fit perfectly into my dream of "What if a day would come andd we would be designing UIs for anything on xhtml+css, and giving functionality in the way we do in jQuery?" and the packaging was nothing more than zipping your workspace and changing the extension into a ".xpi". Firefox is a great browser indeed and if you too are looking to play around with addons have a look at these -

Labels: , , , , , ,