Archive

Archive for the ‘fun’ Category

[NSFW] Jennifer Lawrence enjoys Python too

February 8, 2015 Leave a comment

I just found this image. It seems Jennifer Lawrence is also a huge Python fan.

gDrfkvFClick to enlarge.

Categories: fun, python Tags: , ,

How automation works in reality

January 20, 2014 Leave a comment

Python is an excellent choice if you want to automate a task. But how does automation actually work?


http://xkcd.com/1319/

Categories: fun Tags:

import this

December 9, 2013 Leave a comment

The easter egg “import this” is well-known. However, what is “this.s“?

>>> import this
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
>>>
>>> print this.s
Gur Mra bs Clguba, ol Gvz Crgref

Ornhgvshy vf orggre guna htyl.
Rkcyvpvg vf orggre guna vzcyvpvg.
Fvzcyr vf orggre guna pbzcyrk.
Pbzcyrk vf orggre guna pbzcyvpngrq.
Syng vf orggre guna arfgrq.
Fcnefr vf orggre guna qrafr.
Ernqnovyvgl pbhagf.
Fcrpvny pnfrf nera'g fcrpvny rabhtu gb oernx gur ehyrf.
Nygubhtu cenpgvpnyvgl orngf chevgl.
Reebef fubhyq arire cnff fvyragyl.
Hayrff rkcyvpvgyl fvyraprq.
Va gur snpr bs nzovthvgl, ershfr gur grzcgngvba gb thrff.
Gurer fubhyq or bar-- naq cersrenoyl bayl bar --boivbhf jnl gb qb vg.
Nygubhtu gung jnl znl abg or boivbhf ng svefg hayrff lbh'er Qhgpu.
Abj vf orggre guna arire.
Nygubhtu arire vf bsgra orggre guna *evtug* abj.
Vs gur vzcyrzragngvba vf uneq gb rkcynva, vg'f n onq vqrn.
Vs gur vzcyrzragngvba vf rnfl gb rkcynva, vg znl or n tbbq vqrn.
Anzrfcnprf ner bar ubaxvat terng vqrn -- yrg'f qb zber bs gubfr!
>>>

Well, this.s is the rot13 encoded version of the original text. Here is how to decode it:

# Python 2
>>> print this.s.decode("rot13")

# Python 3
>>> import codecs
>>> print(codecs.decode(this.s, 'rot-13'))

Found @reddit.

Categories: fun Tags: , , ,

funny Python snippet

November 5, 2013 Leave a comment

Found here.

>>> {}['no lock']
Categories: fun, python

Get yourself analyzed on GitHub

If you have a GitHub account, you can get yourself analyzed with The Open Source Report Card.

Here is my report for instance. Scroll down to the bottom and try it with your username.

It will also list users whose activity is similar to yours.

Categories: fun, python Tags: ,

The webbrowser module uses xdg-open

January 1, 2013 Leave a comment

With the webbrowser module you can open webpages in your browser. But how does it work?

Well, under Linux it uses xdg-open. I figured it out accidentally. Start the python shell and try this:

>>> import webbrowser
>>> webbrowser.open_new_tab('')

You will get the usage message of xdg-open :)

Categories: fun, python Tags: ,

Write Python inside Bash

November 24, 2012 2 comments

Problem
You want to embed Python code inside a Bash script.

Solution
Here is a possible solution:

#!/usr/bin/bash

# name.sh

# Example:
# Write a bash script that has one parameter: your name.
# It prints every second character of your name.

TFILE="`basename $0`.$$.py"

cat <<END >$TFILE
#!/usr/bin/env python

import re
import sys

bash_name = re.sub(r'\.\d+\.py', '', sys.argv[0])

def process(s):
    print s[::2]

def main():
    if len(sys.argv) > 1:
        process(sys.argv[1])
    else:
        print "Usage: {0} <parameter>".format(bash_name)

if __name__ == "__main__":
    main()
END

chmod u+x $TFILE
./$TFILE "$@"
/bin/rm $TFILE

Usage:

./name.sh Your_Name
Yu_ae    # output
Categories: fun, python Tags: ,

@grammer_man is the best troll

January 11, 2012 Leave a comment

…decided to write a little twitter bot. There he is above. His name is Grammer_Man and he corrects other twitter users’ misspellings, using data scraped from these Wikipedia pages. … You can see who’s responding at the moment by searching for @grammer_man.” (aengus)

It is worth checking out the reactions of the victims. Most of them have no idea that they reply to a bot :))))

Categories: fun, python Tags: , ,

Antigravity DOES work!

May 9, 2011 1 comment

Today I came across the funny antigravity cartoon at xkcd again. I said to myself: “Well, let’s give it a try.” I was amazed to see that it really works! Try it yourself:

$ python
Python 2.7.1+ (r271:86832, Apr 11 2011, 18:05:24)
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import antigravity
>>>

These guys were able to put it in the standard library :) Python is really fun, I discover that every day.

I won’t link the image, you must try it yourself.

Categories: fun, python Tags: , ,
Design a site like this with WordPress.com
Get started