Use Space As Both Space & Control - Avoid Emacs Pinky!


Most of the  commands  in  Emacs start with  'Control'  &  'Meta'. Control key is present at the corners of the keyboard and its very uncomfortable to press it every-time to invoke a command. Most popular solution to this is to swap CAPS lock & CTRL key. But you have to press the key with Pinky which might cause Emacs Pinky.

A much better solution is to use space bar as control key. When you press the space bar, it will function as a normal space key. If you press it with any other key. it will function as control key. So, to run any commands, you can hold space with one thumb and press other key(s) with another hand which will be handy.

In Linux, you can achieve this with Space2Ctrl.

Install the dependencies, clone the repo, make and start the script.

sudo apt-get install libx11-dev libxtst-dev

git clone https://github.com/r0adrunner/Space2Ctrl

cd Space2Ctrl

make

./s2cctl start
Now you can use your space as space and control key.

If you are using Mac checkout KeyRemap4Macbook & for windows users there is Dual.

Comments

Automatically Remove Unused Imports & Variables From Python


Unused code will distract you(and other people) while reading code. Also, a single unused import can cause out of memory error. So, it is considered as a bad practice. Lets try to get rid of unused imports & variables from Python code.

Autoflake removes unused imports and unused variables as reported by pyflakes. Install it
pip install --upgrade autoflake    

Now select a file which you want to clean and run this in terminal
autoflake --in-place --remove-unused-variables example.py
It removes all unused imports & variables from the file.

Instead of running this command every time, I wrote a simple elisp function and assigned a F8 key to that function. So while writing the code itself it can clean it & it's much efficient.

;; Py-rm - Remove unused variables & imports from python

(defun pyrm ()

  (interactive)

  (setq command (concatenate 'string "autoflake --in-place --remove-unused-variables " buffer-file-name))

  (shell-command command)

  ;; Reload the modified file

  (revert-buffer t t)

  )

;; set a custom key for pyrm

(global-set-key [f8] 'pyrm)

Put the above code in your emacs configuration file, restart it & press F8 whenever you want to clean the code.

However, if you just need to highlight but not delete them, you can install flymake and then enter this.
M-x flymake-mode RET 
It just highlights the other syntax errors and unused imports but won't delete them.

Screenshots:

Simple Python Code

Highlighted with flymake-mode

Cleaned with autoflake

Comments

Amazing Things To Do With Python In Everyday Life!


In Python, with a couple of imports and a few lines of code, we can do amazing things.


I am post here a list of amazing scripts/projects that I came across.


VLC With Subtitles:  Automatically download and load correct subtitles in VLC.

Youtube-dl: Small command-line program to download videos from YouTube.com and other sites.

20482048 Game with Kivy(Also available on Play StoreiTunes, and for terminal)

Rainbowstream
A smart and nice Twitter client on terminal wrote by Python. 

Send Personal Messages:  Thank all your friends who wished on your birthday on Facebook.

T A command-line todo list manager for people that want to finish tasks, not organize them.

qblog: Build & test a blog with Django 1.7 in less than 17 minutes.

coureseraScript for downloading Coursera.org videos and naming them.

sh: Call any shell program as if it were a function.

AutoFlakeRemove unused imports and unused variables as reported by pyflakes.

Django-Extensions: Collection of global custom management extensions for the Django Framework.

Pattern: Scrape & Process Web easily.

PDFMiner:  Exact a part(or entire) of text from pdf.
     
tqdmAdd a progress meter to your loops in a second

onionshareSecurely and anonymously share a file of any size.

q: - Run SQL directly on CSV or TSV files.

iPython Notebook: Combine code execution, text, mathematics, plots and rich media into a single web document & share with others.

Comments

How To Get Telugu Books If You Are Out Of Andhra!


If you are a (Telugu) book worm and you are living out of Andhra, then getting Telugu books is a huge problem. Thankfully a lot of online stores are coming forward to solve this problem. Lets look at a few sites where we can get Telugu print & e-books.

1. Digital Library of India: [Free]

Government of India is spending a crazy amounts of money to digitize public domain books. This is the best place to get telugu ebooks for free of cost. Currently there are 23,370 books in Telugu. Eventhough you won't new books there, you can find a lot of great classics.

2. Kinige:

This is the most popular site(Alexa Traffic Rank: 118,798) for buying Telugu books online. They supply both print books & e-books. The good thing about Kinige is they rent the for a period of 30 days at a reduced price. Most books are available here and is a good place to get started.

3. Logili

One more popular (Alexa Traffic Rank: 138,459) website to buy books online. It's also has great collection. However they sell only print books but no e-books. At times when there are no print books on Kinige, this is a great alternative.

4. Flipkart:

Most of you heard of Flipkart. You can't get all telugu books here but a few. If you are a regular shopper at flipkart, you might get available books at discount price.

5. Amazon:

It is struggling & competing with other online stores in India. Here also you can find a reasonable number of telugu books are great discounts.

You can also buy telugu books at Supatha, BooksForYou, InfiBeam, EveningHour.

In addition to these sites, authors or publication houses might be running their own sites ( for example Yandamoori sells his books from his site also ), you can buy from them also.


Update:

AVKF:
Recently I came across AVKF. It also has a great collection of telugu books.


Comments

Fixing Colors Issues In VLC Media Player on Ubuntu 14.04!


Have you ever played a video on VLC or any other media player and seen this type of washed out colors or distorted video like these??




To get rid of this problem, just open preferences from the Tools menu. Uncheck "Accelerated video output" from the video settings.



 If you are using and old version of VLC, you might have an option to "Skip frames", you can select that option. Save your preferences and restart the VLC player. Now you can enjoy your videos. If the problem still persists make sure you have installed all your video drivers.



Comments

Django Meetup In Bangalore


"Krace played a key role in bringing back the almost dead Bangalore Python Users Group into action."
- Shreyansh Singhal on YourStory.



Few weeks back, while I was searching for Python I came across Krace's blog. Then I checked his Github, Stackoverflow, Quora profiles and I was amazed.

Last week when I found there was a Django users workshop by him & his friends, without a second thought I decided to go.

Since the organizers marked the location (ThoughtWorks Technologies) on Google Maps, its quite easy to reach there w/o any trouble.

Workshop took place from 10 A.M. to 5 P.M. The goal was to build a simple phone book app to add/view/edit contacts with Django & SQLite.

Before starting of workshop, organizers helped with installation of requirements(Django & South).

Krace showed the agenda. At each & every step, he first explained what he is going to do. Then he would do it and gives us time to complete the task. All organizers patiently helped in troubleshooting the errors at each and every step. In the end we had little Q & A session.

Overall it was a great hands on experience with great content & crew! Looking forward for more meetups!! Thank You very much!!!

If you are form Bangalore & love Python, don't miss Django & BangPypers meetup.


P.S: A snap of workshop.. 




Comments

A Weather Widget For Your Terminal!


Getting weather info right on the terminal..?? Sounds cool.. Isn't it? With Python, it's even easier to make one! Lets get started.

First we need to determine the location of the user. So let's find out ip address. There are a lot of sites which gives the ip address but this site is the simplest & very easy to get.

Once we have the ip address, we can use it to determine the location and then use any weather api to get the info. However Worldweatheronline api gives weather info directly based on the api, which makes it easier to fetch data.

We can get the data in JSON format and by parsing it we can make the weather widget.

I wrote a simple script for that and here is the sample output of the script.

 
Comments

Auto Fill Dynamic(Ajax) Web Page & Scrape The Result!


Large scale web scraping is always a big deal. However a simple crawl or filling web form & scraping the result is much easier than you think. While scraping a static page is a cat walk, it is little tricky to scrape dynamic web pages!


I wrote a simple script to fill a dynamic page ( http://www.emirates.com/account/english/miles-calculator/miles-calculator.aspx ) & scrape the result  using Python, Mechanize & BeautifulSoup.


Check our the code on github. Its just a few lines of code and its self explanatory.

Clone the repo.
 git clone https://github.com/ChillarAnand/Emirates-Miles-Calculator.git

Lest calculate howmany miles will be rewarded for travelling from Delhi(DEL) to New York(JFK).
 python emirates.py DEL JFK

Here is the sample output of the script.



Comments

The Mexican Fisherman And Investment Banker - A Short Story!


An American investment banker was taking a much-needed vacation in a small coastal Mexican village when a small boat with just one fisherman docked. The boat had several large, fresh fish in it.

The investment banker was impressed by the quality of the fish and asked the Mexican how long it took to catch them. The Mexican replied, “Only a little while.” The banker then asked why he didn’t stay out longer and catch more fish?

The Mexican fisherman replied he had enough to support his family’s immediate needs.

The American then asked “But what do you do with the rest of your time?”
The Mexican fisherman replied, “I sleep late, fish a little, play with my children, take siesta with my wife, stroll into the village each evening where I sip wine and play guitar with my amigos: I have a full and busy life, senor.”
The investment banker scoffed, “I am an Ivy League MBA, and I could help you. You could spend more time fishing and with the proceeds buy a bigger boat, and with the proceeds from the bigger boat you could buy several boats until eventually you would have a whole fleet of fishing boats. Instead of selling your catch to the middleman you could sell directly to the processor, eventually opening your own cannery. You could control the product, processing and distribution.”

Then he added, “Of course, you would need to leave this small coastal fishing village and move to Mexico City where you would run your growing enterprise.”

The Mexican fisherman asked, “But senor, how long will this all take?”

To which the American replied, “15-20 years.”

“But what then?” asked the Mexican.

The American laughed and said, “That’s the best part. When the time is right you would announce an IPO and sell your company stock to the public and become very rich. You could make millions.”

“Millions, senor? Then what?”

To which the investment banker replied, “Then you would retire. You could move to a small coastal fishing village where you would sleep late, fish a little, play with your kids, take siesta with your wife, stroll to the village in the evenings where you could sip wine and play your guitar with your amigos.”

Comments