2014 (old posts, page 6)

[Telugu] యండమూరి అంతర్ముఖం సినిమా !


తెలుగు పుస్తకాలు, నవలలు చదివేవారు యండమూరి రాసిన  " అంతర్ముఖం " నవల పేరు విని వుంటారు. కాని యండమూరి ఆ పుస్తకాన్ని సినిమా గా తీసినట్లు చాల మందికి తెలియదు. ఈ సినిమా  YouTube లో అప్లోడ్ చేసారు. IMHO, సినిమా క్వాలిటీ,  ఆక్టర్స్ వగైరా వగైరా ఏమి బాగలెవు.




[Linux] Splitting Required Portion Of Video In Ubuntu!


I was writing a post about You Dont Mess With Zohan movie and I had to split a 50 second video from it.

I have Vlc installed, so I enabled to view the advanced controls and recorded the required portion.


Once it is done, I played it back,  but the audio and video are not syncing. I tried again and the same thing happened again.

This is the video splitted with Vlc.


Next, I splitted video with ffmpeg using this command.
ffmpeg -i input.mp4 -vcodec copy -acodec copy -ss 01:20:12 -t 00:50:00 out.mp4
I splitted correctly and audio/video are synced perfectly well. 

This video is split with ffmpeg.


[Transcript] Movie: You Don't Mess With Zohan. Scene: What Is The Area Code Of Amman?


In the movie, You Don't Mess With Zohan, these guys sitting at a dining table, try to call Phantom. One of the guy asks other for area code of Amman where Phantom lives. Here is the scene.


Here is the transcript:

What is area code of Aman? 

sifr (0) wahid (1) wahid (1).
arba'a (4) khamsa (5) talaata (3).
khamsa (5) khamsa (5) sifr (0) sifr (0).
saba'a (7) saba'a (7).
sitta (6) talaata (3) arba'a (4) sitta (6).
wahid (1).
arba'a (4).
sifr (0).
saba'a (7).
talaata (3) arba'a (4) khamsa (5).

So the area code of amman is: 011453550077634561407345!

If you want to learn arabic numerals this will help.
sifr - 0
wahid- 1
itnayn - 2
talaata - 3
arba'a - 4
khamsa - 5
sitta - 6
saba'a - 7
tamaanya - 8
tisa'a - 9

Source: Yahoo Answers

Unix Timestamp, UTC And Their Conversions In Python


Coordinated Universal Time(UTC):

It is the primary time standard by which the world regulates clocks and time. To get current UTC time in Python, we can use datetime module.

In [5]: import datetime

In [6]: datetime.datetime.now(datetime.timezone.utc)
Out[6]: datetime.datetime(2014, 11, 22, 14, 42, 21, 34435, tzinfo=datetime.timezone.utc)

Unix time / POSIX time / Epoch time:

It is a system for describing instants in time, defined as the number of seconds that have elapsed since 00:00:00 Coordinated Universal Time (UTC), Thursday, 1 January 1970, not counting leap seconds. To get Unix timestamp, we can use time module.

In [8]: import time

In [9]: time.time()
Out[9]: 1416667432.5664258

In [10]: int(time.time())
Out[10]: 1416667766

With Pyhon 3.4, we can directly get timestamp from UTC.

In [13]: datetime.datetime.utcnow().timestamp()
Out[13]: 1416649608.58369

Conversions:

To convert Unix timestamp to UTC we can use utcfromtimestamp function.

In [21]: datetime.datetime.utcfromtimestamp(1416668401)
Out[21]: datetime.datetime(2014, 11, 22, 15, 0, 1)

To convert UTC time object to Unix time, we can use strftime function.

In [38]: dt = datetime.datetime.now()

In [39]: dt.strftime("%s")
Out[39]: '1416668938'

Alternatively, we can use calendar.timegen function.

In [46]: import calendar

In [47]: dt = datetime.datetime.utcnow()

In [48]: calendar.timegm(dt.utctimetuple())
Out[48]: 1416669150

[Git] Updating Cloned/Forked Repository On Local Machine and GitHub!


If You have forked a GitHub repo, after a few days/months later and the original master repo might change. So, it is essential to update your forked repo to reflect those changes. One simple solution is, you can delete it and fork again. But, if you have made any changes then you need some other solution.

Updating Cloned Repo On Local Machine:

If you have cloned the repo to your local machine, you can add the original GitHub repository as a "remote". Then you can fetch all the branches from that original repository, and rebase your work to continue working on the upstream version.

From command line you can do this

Add the remote, call it "original":
git remote add original https://github.com/whoever/whatever.git
Fetch all the branches of that remote into remote-tracking branches, such as original/master:
git fetch original
Make sure that you're on your master branch:
git checkout master
Rewrite your master branch so that any commits of yours that aren't already in upstream/master are replayed on top of that other branch:
git rebase original/master
If you don't want to rewrite the history of your master branch, (for example because other people may have cloned it) then you should merge it
git merge original/master
However, for making further pull requests that are as clean as possible, it's probably better to rebase.
 If you've rebased your branch onto upstream/master you may need to force the push in order to push it to your own forked repository on GitHub. You'd do that with:
git push -f origin master

Updating Forked Repo On GitHub:

If you have forked the repo on GitHub, then you can update it with web interface

Go to your fork and issue a Pull Request.
By default this will be your fork on the right (head repo) requesting to push its commits and changes to the original repo (base repo) on the left.
Click the drop down for both base repo and head repo and select each other's repos. You want yours listed on the left (accepting changes) while the original repository is on the right (the one with changes to push). As illustrated in this image:


Send the pull request. If your fork has not had any changes, you should be able to automatically accept the merge.

If your code somehow conflicts or is not quite clean enough, then this will not work to update via the GitHub web interface and you will need grab the code and resolve any conflicts on your machine before pushing back to your fork.

Sources: StackOverflow, WebApps

[Chrome] Clearly Makes Webpages Clean And Easy To Read!


I like the pages that are clean and easy to read. I have installed Adblock, so that it blocks all annoying ads. Few weeks back I came across Wikiwand. It optimizes Wikipedia's amazing content for a quicker and significantly improved reading experience! Today my friend Uday Bhaskar showed me Clearly.

Clearly is a chrome extension which makes blog posts, articles and webpages clean and easy to read. With one click, it eliminates all distractions. It is tightly integrated with Evernote. You can read, highlight and organize notes.

Here are a few screenshots of webpages with and without clearly.

1. Wikipedia:





2. Kracekumar:




3. Labnol:






4. Avil Page:







You may also like:

Automagically Reload Imports In iPython!


When using iPython, users can import required modules to test them. After importing them, if they get modified either by user or some other process, users have to reload it for futher usage.

Depending on the Python version, appropriate reload function can reload modules.

# Python 2.x
In [15]: imp.reload(module)

# Python 3.0–3.3
In [15]: imp.reload(module)

# Python 3.4+
In [15]: importlib.reload(module)

Instead of manually reloading, ipython has autoreload extention which can auto reload modules. For that, load the extention and activate it.

In [15]: %load_ext autoreload

In [16]: %autoreload 2

This can be added to ipython config file so that autoreload gets activated, whenver it starts.

$ ipython profile create

This creates a default config file. Open config file which is present at ~/.ipython/profile_default/ipython_config.py and add these two lines to it.

c.InteractiveShellApp.extensions = ['autoreload']
c.InteractiveShellApp.exec_lines = ['%autoreload 2']

Note that it won't reloads c extensions automatically.

[Python] Converting String Type Objects To Correct Types!


I was writing custom template tags for one of my Django package. I came across a situation where I had lists in string format. I need to convert them into lists.
temp_str = '[345, 3, 456, 45]'
required_obj = [345, 3, 456, 45]
There are two methods to get this job done.

1. ast.literal_eval:

This can be used to evaluate  strings containing Python values from untrusted sources without parsing values.
import ast
ast.literal_eval(temp_str)

2. json.loads:

This is used to deserialize a string to python object using a conversion table.
import json
json.loads(temp_str)
These two functions come in handy whenever you want to convert a list of python objects to their correct types. For example, if you have list of python objects like this
obj_list =  ['hello', '3', '3.64', '-1']
You can convert them to their corresponding types using these functions.
def converter(l):
for i in l:
try:
yield json.loads(i)
except ValueError:
yield i
def converter(l):
for i in l:
try:
yield ast.literal_eval(i)
except ValueError:
yield i
They yield a objects of corresponding types
new_obj_list = ['hello', 3, 3.64, -1]
References: Python Docs, Stackoverflow