• 06Jan

    Hi everyone.

    Every now and then I get somewhat annoyed by the fact that I add temporary or “unwanted” files to a subversion repository. These files may be just temporary files, like *.tmp, which has no value of being kept in a repository, or compiled python files *.pyc, etc.

    The common characteristics is that they are generally unwanted, and that they can easily be removed from the SVN repository. A common approach towards this issue is to set a property named “svn:ignore” on a directory, or the whole directory structure. This can be achieved with this command:

    $# svn propset svn:ignore "*.tmp" .

    where the single-dot at the end signalize the standing directory. However, this must be performed for each subversion project, which can get annoying in time. I’ve recently discovered the possibility of setting global subversion settings for my own user. The per-user subversion settings file is located on $HOME/.subversion/config. In that file there is a section named “[miscellany]“, which holds a variable named “global-ignores”. This variable can hold multiple ignore statements which will apply for all the svn checkouts you may work on (given you are using this user).

    This subversion setting file also contains many more exciting options, such as automatic properties which apply to certain files. Have a look at the end for the $HOME/.subversion/config file and notice some of the predefined settings.

    A tip based on personal experience is to hook the current files to the global-ignores variable:

    *.pyc # python byte compiled code
    *.swp # vim swap file
    *.tmp # general temp files

  • 29Dec
    Categories: general IT Comments: 0

    Every year I make myself some “abstract” goals regarding some achievements I should manage to reach. However, each year there are always one or two goals which is left behind. What I would especially highlight this year is to finish some of my software projects which has just been left in the mid-air.

    • A simple webpage for my topdomain (fellinghaug.com)
    • My very simple, yet (hopefully) powerfull Python search engine (codename “Wallace”)
    • Contribute more to the open-source community (register myself as a python developer, solve bugs and translate projects on launchpad.net)

    Let’s now get ahead of ourselves here, and just stop the list there. Adding more would simply make it overwhelming and unrealistic. If I surprise myself in terms of the timeframe (a year) for these goals, then I would allow myself to add more stuff on this list.

    I would point to fellow developers out there to also make yourselves goal lists, as these lists tend to improve the developers efficiency. It certainly feels so in my case.

  • 04Dec

    Hi everyone!

    Today I have a pleasant surprise! “Python v3.0″ has reached its final milestone, and has therefore been released into the wild. This is very interesting, as this new version facilitates some neat features. Instead of listing them here, I would recommend you read the “What’s In Python 3.0“.

    Python Logo

    Python Logo

    One issue they haven’t been able to solve is the GIL (Global Interpreter Lock). I sincerly hope this will be solved in time, as it somewhat constraints the usage of Python in high performance computing with threads.

  • 18Nov

    Hi everyone.

    A couple of times now I’ve been amazed over how many people who is still unaware of the IPython. From the IPython webpage, a very short summary of what IPython is “Enhanced interactive Python shell”. The python programming language is surrounded its interpreter, which facilitates dynamic typing and execution. This feature sufficiently increases productivity as there is no problem to test and try code snippets on-the-fly.

    The IPython is a further extension of the standard python interpreter, as IPython provides more features in the python shell, such as auto-completion of imported modules, syntax highlightning, colors, and a variouse other usefull commands and features.

    IPython is highly flexible in terms of providing the user with the possibility to extend the python shell even further with custom commands (called magic commands). There is also an even tigther integration between the python interpreter and the underlying shell, such as bash,csh, etc. It is for instance much simpler to list files and folders, by just typing “ls” directly into the shell. Even commands such as “mkdir”, “mv”, “rm” is builtin, and its trivial to further extend the shell command vocabulary with more complex commands. We’ll show an example for howto extend with custom commands below.

    As every flexible software, IPython comes with a main configuration file ($HOME/.ipython/ipythonrc). If we wanted a custom command, such as “chmod <mod> <file>” (chmod 755 myfile.py), we could add this to the “ipythonrc” file:


    # my custom chmod alias. By typing '>>> chmod 755 myprog.py' or
    # '>>> chmod a+rx myprog.py' IPython will execute this
    # statement as a shell command.
    alias chmod chmod %s %s

    Also, debugging lists (tuples, dictionaries, etc) is more readable within the IPython, as it wraps all such print statements inside the “pprint” (pretty-print) module, and therefore a comprehensible representation will find place.

    So, if you often find yourself in the python interpreter, I would highly recommend you spending a half an hour to get to known IPython. I promise you - it will save you a lot of headaches in the future.

  • 27Oct
    Categories: python Comments: 0

    Finally!

    Its time for the monthly edition of the Python Magazine, which is a highly interesting and technial magazine regarding the python programming language.

    python magazine

    python magazine

    Everyone who is in to Python should subscribe to this magazine, as it covers many “hot” topics, as well as presenting many howto tutorials for everyday challenges. From cutting edge web applications and frameworks, to desktop applications and backbone server implementations.

  • 17Oct

    Hepp hepp!

    VIM (Vi IMproved) er en tekst editor som bygger på den svært gamle og anerkjente editoren VI. VIM (heretter kalt Vim) er en svært avansert teksteditor som har fra første stund lagt til rette for å være svært konfigurerbar. Tekst editoren har sitt eget “skript” språk der enkle trivielle operasjoner er representert ved små kommandoer, som i sammenheng kan utføre mange spesialiserte operasjoner (alt etter hva ønsket er).

    Vim har hatt et rykte på seg for å være en vanskelig editor, da den krever en litt spesiell tankegang i begynnelsen. Dog, etter å ha kommet over den første milepælen på læringskurven, så er verden forståelig igjen. Vim har forskjellige “modus” der man kan gjøre forskjellige ting. For eksempel har man skrivemodus som tilrettelegger for at det man skriver på tastaturet blir skrevet til dokumentet. Man har også et kommandomodus, der man skriver kommandoer som Vim skal utføre på dokumentet. Typiske kommandoer kan være “slett linjen, slett tegn, finn tekst, finn og erstatt tekst, flytt tekst, kopier, klipp ut, lim inn, etc..”.

    Nå detter jeg litt ut her, men kan tipse om dette dokumentet (på norsk) som beskriver Vim på en mye bedre måte. Siden Vim er så fleksibel og modulær som den er, så har mange aktive brukere skrevet “plugins” som er små spesialiserte programsnutter til Vim. Disse programsnuttene er gjerne direktet myntet mot en spesifikk oppgave; fargelegge spesielle ord, tegn, sørge for korrekt formatering gitt en spesiell filtype, etc. For de av dere som kjenner programmeringsspråket Python, så trenger jeg sikkert ikke å si at det kreves litt av din IDE (Integrated Development Environment) for å sørge for riktig indent for blokker med kode, samt korrekt syntax, etc. Med andre ord vil en bra IDE hindre unødvendige og slurvete feil i Python kode, derfor kreves det en bra IDE for å effektivt skrive rask og bra kode.

    Nå kommer det som sikkert ingen overraskelse at Vim fungerer utmerket som en IDE, selv om den aldri var ment for å fungere som det. Dette er en av de flotte egenskapene til Vim: den er skrevet såpass modulært at man faktisk kan sette på byggeklosser for å spesialisere den innenfor et felt. Det finnes mange python “plugins” til Vim, slik som fargelegging av Python kode (se bilde under/til siden). Andre automatiske oppgaver man gjerne vil delegere til “plugins” er at når man trykker “enter” for linjeskift så skal man holde seg på samme innrykksnivå. Dette fordi at Python ikke benytter slike klammeparanteres {} som f.eks C++ og Java.

    Automatisk feilkorrigering er også ting man gjerne vil ta høyde for i en IDE, og det finnes det gode løsninger for i Vim. Deriblant finnes det “plugins” som forsikrer seg om at det er riktig syntaks på slike logiske uttrykk som if-elif-else krever, samt at det bestandig er en kolon helt til høyre for slike uttrykk, og at alle strenger startes og avsluttes av fnutter, slikt som ’streng1′, “streng2″, “”"streng3″”". En annen faktor som har i større grad uttrykket styrken til en IDE er dens muligheter til å tilby auto-completion av kode. Ta for eksempel følgende lille kodesnutt:

    import sys
    if sys.platform == 'linux2':
        print "you'r surely using Linux, right?"

    så, når jeg så skriver ’sys.’ og vil gjerne ha opp hvilke funksjoner/klasser/variabler som kan aksesseres fra modulen ’sys’, så vil jeg gjerne at IDE’en skal presentere en liste over disse alternativene.

    Vim har innebygd en auto-completion feature, men denne baserer seg på alle enkeltord som allerede er skrevet i dokumentet. Så, gitt kodesnutten ovenfor så kan man taste “CTRL+n” for å få opp en liste med alternativer. Men, denne vil ikke funke for vårt problem, da vi gjerne vil ha alle funksjoner/klasser/variabler som ligger under modulen “sys”. Frykt ikke - det fins råd. I denne blogposten er det beskrevet hvordan man med enkle funksjoner kan muliggjøre en mer avansert auto-completion for Python. Merk at denne featuren krever at Vim er kompilert med Python støtte (de fleste Linux distroer har dette). Så, dersom du tar å editerer din $HOME/.vimrc fil, og legger til følgende:


    " enables python completion
    autocmd FileType python set omnifunc=pythoncomplete#Complete
    " maps CTRL+SPACE to autocompletion function
    inoremap <Nul> <C-x><C-o>

    Nå kan man enkelt få til den ønskede funksjonaliteten ved å skrive “sys.” også taste CTRL+SPACE. Da vil Vim editoren legge til et ekstra vindu helt øverst med forklarende tekst for den aktuelle funksjonene/klassen/variabelen, samt at man ved hjelp av piltastene kan bevege seg nedover i listen.

    Merk at dette er bare en av flere nyttige funksjoner for Vim som en IDE for Python. Vil på det sterkeste anbefale deg å lese hele denne blogposten* dersom du befinner deg i en situasjon der du gjerne vil benytte Vim til å kode Python. Legg også merke til at Vim kjører på mange plattformer: Linux, Mac, Windows. Og, den trenger ikke å kjøre i et terminalvindu, som man ofte ser på skjermbildene. Det finnes en GUI versjon (kalt gVim).

    * http://blog.sontek.net/2008/05/11/python-with-a-modular-ide-vim/

  • 13Oct

    Woho!

    ACDC Black Ice Tour Oslo

    ACDC Black Ice Tour Oslo

    Gjett hvem som sitter med billetter til AC/DC sin Black Ice Tour til Oslo 18.Februar? (retorical question). Det var gledens øyeblikk som tok meg idet den jævla nettsiden til Billettservice endelig responerte å tilbudte meg billetter. Billettene ble lagt ut kl.09:00, og kl.09:00:17 var nettsiden så å si nede..

    Der skal Billettservice tas litt! Ingen webside som, i aller høyeste grad burde forvente en slik pågang, skal gå ned slik. Syns det er veldig useriøst av Billettservice, og håper at de tar noen skikkelige grep til neste gang en slik lansering står for tur. Når f.eks VG klarer flere hundretusen samtidige requests, og Google en quadrillion requests, så burde Billettservice klare ~50 000 requests.

    AC/DC

    AC/DC

    Til tross for disse vanskelighetene med å anskaffe billettene, så blir det nå altså konsert 18.Februar! Om det blir 2009’s råeste konsert vil bli å finne ut, men det tviles ikke.. :)

  • 09Oct

    Hei.

    Jeg tenkte å ta for meg et voksende problem innen utveksling av dokumenter rundt omkring i Norge (og resten av verdenen). Etter at MS Office 2007 kom ut, og med det innførte et nytt filformat (docx, pptx, xlsx, ..), så har folk som tidligere har benyttet MS Office 2003/XP (og eldre) ikke vært istand til å lese dokumentene lagret i disse formatene. Enda verre er det for de som benytter OpenOffice (et gratis verktøy av tilsvarende funksjonalitet som MS Office).

    Så, problemet ligger i at MS Office 2007 lagrer som default alle dokumenter i disse nye formatene. Og som kjent så tenker ikke folk flest over dette, og derfor vil mesteparten av produserte dokumenter bli lagret i slike obskure formater. Det skal nevnes at formatet er svært lik OOXML (dog oppfyller den ikke helt spesifikasjonene). Uansett, dette innebærer problemer for folk som benytter andre tilsvarende programmer.

    Jeg har selv erfart å få e-post med slike dokumenter, da jeg konsekvent svarer at formatet er ukjent for meg og at de enten skal lagre i det (gamle) “doc” formatet eller ODT (OpenDocument format for tekstbehandling), eventuelt PDF. Sistnevnte byr på problemer dersom du er avhengig av å redigere dokumentet dog.

    Hovedpoenget er at folk må slutte å benytte formater som er svært dårlig utbredt, da de innsnevrer mulighetene for andre å lese dokumentene. Inntil det faktisk er mulig for andre enn MS Office å lese og skrive i de respektive formatene, så anbefales det sterkt å unngå dem.

    Tags: , ,
  • 03Oct
    Categories: python Comments: 0

    Hi everyone!

    2. October the python developmeant team released the Python v2.6. At http://planet.python.org there is a whole lot of other blogs listing all the new cool features, so I won’t use any space outlining them here.

    However, I will encourage everyone to have a look at the documentation, as there is some valuable key features in this release which will in the long run revolutionize the way we program in Python.

    In time I will cover some of these features.

  • 08Sep

    Hi.

    There has been some delay since the last time I’ve presented some stuff in this blog - sorry about that. I guess I can somewhat blame it on my work which is requiring a whole lot of my time nowadays. However, today I have an interesting concept to discuss. Namely the concept of applications and cache.

    Nowadays, delays in software is a factor which could mean the difference between failure and success. So, how does most applications cope with this challenge? Well, some does a significant amount of work in regards to create more efficient algorithms, others focus primarily on the overall design of the application in order to reduce time delays, and also the widespread usage of compression of the data flow between systems. Not that these things is not worth thinking of, but an often forgot concept is the usage of a caching system.

    A caching system would in this context mean a system specifically designed to hold “fresh data”, in a much similar way as a standard database. Now you may think, “why not just use the database?”. Well, we will in most cases use a database. However, when your web page (or application) has a wide range of users, and a large set of those users request the same set of data, then your database would be overwhelmed by the amount of incoming requests. A database has a large overhead as a result of all the features which it needs to support (think of JOIN operations, RELATIONS, CONSTRAINTS, etc), and therefore there would be a need to have a much faster retrieval of “fresh data” which is frequently requested.

    How do you think Digg, Reddit or Slashdot handles its requests? 1. Route HTTP request to web application. 2. Execute a SQL SELECT statement to retrieve the articles 3. Render and return the HTML ? That would not scale very well for such large web sites. Instead, they take advantage of a caching system to hold the result of a SQL SELECT statement for a defined amount of time, and then re-initiate the SQL SELECT statement. With such an approach the database server would be much less overwhelmed by the frequent requests, and the caching system, which just holds the data, would take over the load. Since the caching system is built to hold data in memory, and to make it easy and fast retrievable, the data would be much faster loaded into the application, thus reducing the time delay previously involved.

    Enough “mombo-jombo”, lets talk technical. The Danga Interactive memcached is a “high-performance, distributed memory object caching system”. Its main purpose is to hold objects in a distributed manner, and to provide fast retrieval of those objects. This is done with the help of a distributed hash table across the nodes running memcached. Setting up and running a memcached server on Ubuntu and Debian is trivial:


    #$ aptitude install memcached
    #$ memcached -d -m 2048 -l 192.168.0.10 -p 12345

    This would fire up a memcached server with 2GB of memory on IP 192.168.0.10:12345. Now, given the usage of python and the python memcached client library (libmcache):

    1
    2
    3
    4
    5
    6
    7
    8
    
    import sys
    try:
       import memcache
    except ImportError:
       sys.exit(0)
    mc = memcache.Client( ['192.168.0.10:12345'] )
    mc.set("fellinghaug", "rocks")
    assert mc.get("fellinghaug") == "rocks"

    This may not be the best example of the usage of memcached, but the basic principle is shown. I would highly recommend reading the FAQ/Wiki at Danga’s homepage, and further these articles:

    As a final note: if your application shares the characteristics described in this article, then you should consider using a caching system.