users online counter
Interesting
O’Reilly competition

O’Reilly competition has chosen the answers for the Disposable Teleports mission and the Simplification mission. The community has spoken and narrowed our finalists down to three people for each mission. The winners of the Disposable Teleports challenge are:

First Place - PositronicLlama
http://www.checkio.org/mission/implementation/python-3/16613/01687c3395441a47a81abebc7cd505f8/

Second Place - macobo
http://www.checkio.org/mission/implementation/python-27/16750/c4aa1e0470ce738ff187ea9d7906a448/

Third Place - andy_s
http://www.checkio.org/mission/implementation/python-3/16972/00144054e5016f6b2d20ca52d4c5ab99/

For the Simplification mission we have:

First Place - Bibiche
http://www.checkio.org/mission/implementation/python-3/16650/55d2e8d3fa782cc780630cc6640320dd/

Second Place - Bilou06
http://www.checkio.org/mission/implementation/python-27/16664/7be6f8df5c6e87e17f5d0a8cb3c26a5d/

Third Place - hyry
http://www.checkio.org/mission/implementation/python-27/16726/8c043f8c65c8f489eeef61a91f874c53/

Task description:

The island has eight stations, which are connected by teleports. However, the teleports take a very long time to recharge so you can only use each one once. After you use a teleport, it will not work again. Begin at number 1 and try to get around to all the stations before returning to the starting point. The map of the teleports is presented as a string, in which the comma-separated list represents teleports. Each teleport is named by the two digits (ex. 12 or 21) of the stations that it connects. All tests require you to provide a route which passes through all stations. A route is presented as a string of the station numbers in the sequence in which they must be attended (ex. 123456781).

Input: A string containing a list of comma-separated numbers representing available teleports. Each teleport contains two digits (the numbers of the stations that it connects)

Output: A string containing a sequence of station numbers.


Solution:

rom collections import defaultdict

 
# While unneccesary for this task, if there would be more
# than 8 teleports, most time would be spent on recomputation
# of similar states. (There are many ways to arrive at a station
# by using the same teleports, just in different order).
# To avoid that, let's make a memory tradeoff and try to
# save already computed states and use those results when
# we arrive at the same state the second time.
#
# This techinque is called memoization in Dynamic Programming.
 
def memoize(f):
    """ This is a decorator, that saves each call to a function
        into a hash table. If the function is called a second time
        with the same arguments, the previous result is returned """
    cache = {}
    def g(*args):
        if args not in cache:
            cache[args] = f(*args)
        return cache[args]
    return g
     
def available_routes(frm, all_routes, used):
    is_used = lambda to: (frm, to) in used or (to, frm) in used
    return [to for to in all_routes[frm] if not is_used(to)]
 
def checkio(teleports_string):
    @memoize
    def recurse(at, visited, used_routes):
        routes = available_routes(at, all_routes, used_routes)
        if "1" in routes and len(visited) == 8:
            return "1"
        for to in routes:
            new_routes = used_routes | frozenset([(at, to)])
            solution = recurse(to, visited | frozenset([to]), new_routes)
            if solution:
                return to + solution
 
    all_routes = defaultdict(set)
    for pair in teleports_string.split(","):
        all_routes[pair[0]].add(pair[1])
        all_routes[pair[1]].add(pair[0])
    return "1" + recurse("1", frozenset("1"), frozenset())
     
if __name__ == "__main__":
    print(checkio("12,23,34,45,56,67,78,81")) #"123456781"
    print(checkio("12,28,87,71,13,14,34,35,45,46,63,65")) #"1365417821"
    print(checkio("12,15,16,23,24,28,83,85,86,87,71,74,56")) #"12382478561"
    print(checkio("13,14,23,25,34,35,47,56,58,76,68")) #"132586741"
Brython’s goal is to replace Javascript with Python, as the scripting language for web browsers.

Brython’s goal is to replace Javascript with Python, as the scripting language for web browsers.

Programmers waste enormous amounts of time thinking about, or worrying about, the speed of noncritical parts of their programs, and these attempts at efficiency actually have a strong negative impact when debugging and maintenance are considered. We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3%.
Donald Knuth (in StructuredProgrammingWithGoToStatements)

The following post by Lennart on LinkedIn produced a very interesting (and lively) discussion. Ron.

There is list of pretty useful python small command line one-liners available out of the box. That means if you already have installed python on your system (most Linux, *BSD, including OSX) then you can use it even if you are not python developer.

I love most way to create fake SMTP server:

$ python -m smtpd -n -c DebuggingServer localhost:25 

If you develop using something else, but need to send emails and want to debug or just need somethingyou can add to your Makefile this lines:

mail: python -m smtpd -n -c DebuggingServer localhost:20025 

And run make mail, voila you have running SMTP daemon on 20025 port. Easy!

Make JSON beautiful? Next oneliner:

$ echo '{"foo": "lorem", "bar": "ipsum"}' | python -mjson.tool 

You can only wish more if you like to see it in color. Hope you noticed pipe support.

Full set of available HTTP services.

$ python -m SimpleHTTPServer
$ python -m CGIHTTPServer

Wanna use different port?

$ python -m SimpleHTTPServer 8080
$ python -m CGIHTTPServer 9080

It serve all files from local folder and below.

XMLRPC is not very popular this days, but you still able to debug remote servers:

$ python -c 'import xmlrpclib; print xmlrpclib.Server("http://host:8080").methodName(param,param2)' 

Real life example? Search on PyPI:

$ python -c 'import xmlrpclib; print xmlrpclib.Server("http://pypi.python.org/pypi").package_releases("Flask")' ['0.9'] $ python -c 'import xmlrpclib; print xmlrpclib.Server("http://pypi.python.org/pypi").search({"name":"hopak"})' [{'_pypi_ordering': 12, 'version': '0.1.0', 'name': 'Flask-Hopak', 'summary': 'Admin interface for Flask that uses Hopak models'}, {'_pypi_ordering': 12, 'version': '0.4.2', 'name': 'hopak', 'summary': 'hopak framework base package'}] 

More python specific timeit module, it allows to measure speed of small code snippets:

$ python -m timeit '"-".join(str(n) for n in range(100))' 10000 loops, best of 3: 33.2 usec per loop $ python -m timeit '"-".join([str(n) for n in range(100)])' 10000 loops, best of 3: 28.2 usec per loop 

Even is possible to make a little setup using -s parameter:

$ python -m timeit -s "import json" "json.dumps({'a':'a'})" 100000 loops, best of 3: 5.98 usec per loop 

More

Probably listed here is more common for me. But if you like to discover more, then simple scan standard python library for if __name__ == '__main__' substring and check results:

$ grep -r "if __name__ == '__main__'" /path/to/python/libaray/

For a French translation of this post, click here.


For anyone who works in a company that has an office in a EU Community member state, we need your help.

There is a company in the UK that is trying to trademark the use of the term “Python” for all software, services, servers… pretty much anything having to do with a computer. Specifically, it is the company that got a hold on the python.co.uk domain 13 years ago. At that time we weren’t looking a lot at trademark issues, and so we didn’t get that domain.

This hasn’t been an issue since then because the python.co.uk domain has, for most of its life, just forwarded its traffic on to the parent companies, veber.co.uk and pobox.co.uk. Unfortunately, Veber has decided that they want to start using the name “Python” for their server products.

We contacted the owners of python.co.uk repeatedly and tried to discuss the matter with them. They blew us off and responded by filing the community trademark application claiming the exclusive right to use “Python” for software, servers, and web services - everywhere in Europe. 

We got legal counsel in the UK and we (the PSF) are opposing the community trademark application, but our own trademark application hasn’t yet matured. Accordingly, we are going with the trademark rights we have developed through using “Python” consistently over the past 20 years. 

According to our London counsel, some of the best pieces of evidence we can submit to the European trademark office are official letters from well-known companies “using PYTHON branded software in various member states of the EU” so that we can “obtain independent witness statements from them attesting to the trade origin significance of the PYTHON mark in connection with the software and related goods/services.” We also need evidence of use throughout the EU.

What can you do?
1. Do you work for a company that uses Python? Are in the EU, do you hire in the EU, or do you have an office in the EU? Could you write a letter on company letterhead that we can forward to our EU counsel? 

We would want: 

  1. just a brief description of how Python is used at your company, 
  2. how your company looks for and recognizes “Python” as only coming from the PSF, and 
  3. your view that another company using term Python to refer to services, software, and servers would be confusing
This doesn’t need to be long - just a couple of paragraphs, but we would want any description of how you use Python for software, web hosting, Internet servers, VPNs, design and development of computer hardware or software, hosting websites, renting servers (like Openstack), or backup services. For those who are interested the specific class descriptions are at the bottom of this message. [1][2]

You can send a PDF copy of the letter to psf-trademarks@python.org

2. Do you have, or know of, anything that was published in the EU and uses “Python” to refer to Python-the-language? Can we get copies, pictures, or scans? This includes:

  • Books
  • Pamphlets
  • Conference programs or talks
  • Job listings
  • Magazines or other publications
  • Prospectuses
can send a PDF scan of the materials to psf-trademarks@python.org

3. You can also help protect the Python intellectual property with financial support.

Since the costs of a trademark opposition are in the range of tens of thousands of dollars, we will need to find a way to refinance the legal costs of the opposition.

Please consider donating to the Python Software Foundation at:

    http://www.python.org/psf/donations/

or get in touch with me directly.

This is the first time the PSF has to take legal action to protect Python’s intellectual property. Please do consider helping the PSF in any way you can. The threat is real and can potentially harm your business in Europe, especially if you are in the web hosting business and provide Python as part of your hosting plans.



Please let me know if there are any questions that I can answer. If you know someone who might have this information, please feel free to forward this. 

Thanks, 

Van Lindberg, 
Chairman
van@python.org
Python Software Foundation


[1] Class 9 - Computer software; Servers for web hosting; VPN [virtual private network] hardware; Internet servers; Internet servers.

[2] Class 42 - Design and development of computer hardware and software; Website hosting services; Hosting computer sites [websites]; Hosting the websites of others; Hosting of websites; Hosting the web sites of others on a computer server for a global computer network; Hosting websites on the Internet; Hosting the web sites of others; Web hosting services; Hosting of digital content, namely, on-line journals and blogs; Application service provider [ASP], namely, hosting computer software applications of others; Website hosting services; Hosting of digital content on the internet; Hosting of web sites; Hosting web sites; Hosting web sites for others; Hosting websites of others; Hosting of internet sites; Hosting the computer sites (web sites) of others; Web site hosting services; Hosting computer sites [web sites]; Hosting web sites of others; Rental of web servers; Servers (rental of web-); Servers (Rental of Web -).

Python Gets a Big Data Boost From DARPA

Posted by Soulskill
itwbennett writes “DARPA (the U.S. Defense Advanced Research Projects Agency) has awarded $3 million to software provider Continuum Analytics to help fund the development of Python’s data processing and visualization capabilities for big data jobs. The money will go toward developing new techniques for data analysis and for visually portraying large, multi-dimensional data sets. The work aims to extend beyond the capabilities offered by the NumPy and SciPy Python libraries, which are widely used by programmers for mathematical and scientific calculations, respectively. The work is part of DARPA’s XData research program, a four-year, $100 million effort to give the Defense Department and other U.S. government agencies tools to work with large amounts of sensor data and other forms of big data.”

How one Tumblr post got propagated. By Ron Barak
Update: a week ago I posted a George Carlin quote that became quite popular (391 notes at last count).
The directed graph above is answering the (interesting) question of how that post was propagated: one apparent thing is that the main drivers of the post’s popularity are very few: only one on the 3rd level and one on the 6th level.
The graph was created with Python 2.6 and graphviz (altgraph.Dot library).

How one Tumblr post got propagated. By Ron Barak

Update: a week ago I posted a George Carlin quote that became quite popular (391 notes at last count).

The directed graph above is answering the (interesting) question of how that post was propagated: one apparent thing is that the main drivers of the post’s popularity are very few: only one on the 3rd level and one on the 6th level.

The graph was created with Python 2.6 and graphviz (altgraph.Dot library).

220px-PythonProgLogoPython is only one of many important open-source programs that are more than 20-years old.

Today, open-source software is everywhere but many peple still think of it as being relatively new. It’s not. Open-source software actually goes back decades.

Before beginning our journey in the way-back machine though we should go over our terminology. “Open source,” the phrase, only goes back to February 3, 1998. The phrase was deliberately chosen to separate the more pragmatic open-source supporters from the more idealistic “free software” community members. Gallons of ink and gigabytes of pixels has been spilled on debating the differences between these two, but for my purposes I’m talking about programs that qualify by either definition.

Both concepts were actually used long before proprietary software showed up. As Richard M. Stallman, (rms) free software’s founder noted, “When I started working at the MIT Artificial Intelligence Lab in 1971, I became part of a software-sharing community that had existed for many years. Sharing of software was not limited to our particular community; it is as old as computers, just as sharing of recipes is as old as cooking.”

For my list, I also decided to skip numerous small programs, such as those in the NASA COSMIC software collection. Some of these date back to the 1960s. Instead, I’ve focused on major programs, which are still being used today. I also owe a debt of gratitude to Black Duck Software’s story, “Oldies but Goodies: Seven Projects still working Open Source.”

So, with no further adieu, from the most recent to the oldest, here’s my list of older significant open-source projects.

1) Linux: August 25, 1991

There were thousands of open-source programs before Linus Torvalds wrote “I’m doing a (free) operating system (just a hobby, won’t be big and professional like gnu) for 386(486) AT clones.” to the Minix Usenet group and unknowingly started the operating system juggernaut that became Linux. That said, Linux has also become the most successful of open-source programs.

Gallery: The 20 most significant events in Linux’s 20-year history

Linux has become the foundation for the Internet; the operating system for super-computers; and, thanks to Android, it’s becoming the most popular end-user operating system of all. There were indeed other free software programs being released in 1991 and earlier, but none would be more important.

2) Python: February 20, 1991

Guido van Rossum, Python’s creator, began work on this important language in December 1989. It wasn’t until February 1991, that it was released. Since then, according to Black Duck Software’s Ohloh programming statistics, “Python is the fastest growing language in the open source world as measured by number of contributors.”

It’s not just open-source developers that support Python. Even Microsoft provides a Python IDE(integrated development environment ) for Visual Studio.

3) GNU C Library (glibc): February 1988

That said, C remains a vital language in open-source circles and to do much with C you need a good, general purpose library. Over the decades the most important of these libraries has beenglibc. Most of the credit for glibc’s early success goes to Roland McGrath. By early 1988, McGrath had given what would become glibc, “a nearly complete set of ANSI C library functions.” From this work would spring innumerable programs including Linux.

4) Perl: December 18, 1987

Is there any system or network administrator anywhere who hasn’t written at least one script in Perl? I doubt it. Larry Wall’s creation has become the go-to scripting language for all servers everywhere. Not bad for a language that was “kind of designed to make awk and sed semi-obsolete.”

5) GNU C compiler (gcc): March 22, 1987

If glibc is important then gcc is vital. At its start, gcc only supported C. Today, it supports, to name but a few, C, C++, Objective C, Fortran, and Java. Almost every free software software project owes a debt of gratitude, and a lot of its foundation programming, to gcc.

6) GNU Emacs: 1984

Before there was gcc, the first major GNU program was the GNU Emacs programming editor. While I was never crazy about it—I’m a vi guy—I couldn’t begin to count how many programs were written in GNU Emacs. Indeed some people assume that GNU Emacs was the first version of the editor. That isn’t so. Emacs actually dates all the way back to 1972.

You could argue that these early versions were also free software, and I wouldn’t fight with you about it. There’s no question that such early versions as Multic Emacs and Gosling Emacs shared both ideas and code. GNU Emacs, though, became the version that would change the development world.

7) X Window System: 1983

At the same time that Emacs and gcc were starting to roll, others at MIT were working on the X Window System, a TCP/IP-based networking windowing system. No one knew it at the time but X Window would eventually become the basis for all important Linux and Unix interfaces, and the foundation for the Mac OS X interface.

8) BRL-CAD: Dec 16, 1983

If you’re a developer, you’ve heard of all these programs so far, but I’m sure few of you have heard of Ballistic Research Laboratory-computer-aided design (BRL-CAD). This program, which is still being worked on today, is used by the U.S. military to model ballistic attacks on vehicles.

9) First Berkeley Software Distribution (1BSD) Unix: March 9, 1978

The first open-source operating system wasn’t Linux. That honor goes to, as Peter H. Salus wrote in A Quarter Century of UNIX, Bill Joy’s first version of BSD Unix. When Unix first showed up in 1969, it was open source. Later it was closed, but BSD, the first fork, kept the free software flag flying. While BSD Unix never grabbed the headlines that Linux has, it’s actually very important as well. Besides the BSD “distributions,” such as FreeBSDOpenBSD, and NetBSD, both Solaris and Mac OS X got their start from BSD Unix.

10) VistA: 1975

Finally, the oldest open-source program that I know of which is still commonly used is another one you probably haven’t heard of: VistA (Veterans Health Information System and Technology Architecture). VistA was the first electronics health record (EHR) system. Today, versions of VistA, such as WorldVistAMedsphere’s OpenVista, and DSS are being used to bring EHR to doctors and hospitals throughout the U.S.

So, as you can see, open-source programs not only has a long history, it’s also important in far more places than in software development. Since it’s very start, free software has helped us in ways we didn’t even know about.

So, the next time, someone says open-source software isn’t good or trustworthy, just remind them that not only is it great, it has a better and longer track record than almost any proprietary software.

Steven J. Vaughan-Nichols, aka sjvn, has been writing about technology and the business of technology since CP/M-80 was the cutting edge PC operating system. SJVN covers networking, Linux, open source, and operating systems.

Scala for the Python Geeks-Part 1


Scala is a JVM lan­guages de­signed by Mar­tin Oder­sky in early 2001 and it brings fea­tures of ob­ject-ori­ented pro­gram­ming and func­tional pro­gram­ming to­gether. Scala is com­pet­ing again sev­eral newJVM lan­guages in­clud­ing but not lim­ited to Groovy, Clo­jure, JRuby and Jython. Scala re­sem­bles Python (and Ruby) in many ways and as a Python­ist I found it real easy to switch on Scala. The pur­pose of this tu­to­r­ial se­ries is to give Python geeks an idea about the sim­i­lar­i­ties and dif­fer­ences be­tween Scala and Python world.

More

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!
The Zen of Python, by Tim Peters
free counters