<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-7949101630202648210</id><updated>2024-09-05T08:13:53.063+02:00</updated><category term="programming"/><category term="python"/><category term="snippets"/><category term="matrix"/><category term="music"/><category term="pad"/><category term="rename"/><category term="subjective"/><category term="vim"/><title type='text'>Code is Music</title><subtitle type='html'>Code can be music. Programming can be fun. Read about the experiences of a novice computer scientist and programmer.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://codeismusic.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7949101630202648210/posts/default'/><link rel='alternate' type='text/html' href='http://codeismusic.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Gonzalo Quero</name><uri>http://www.blogger.com/profile/07447335155416902229</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>4</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-7949101630202648210.post-810073793988125529</id><published>2009-02-02T00:26:00.004+01:00</published><updated>2009-02-02T00:34:34.777+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="pad"/><category scheme="http://www.blogger.com/atom/ns#" term="programming"/><category scheme="http://www.blogger.com/atom/ns#" term="python"/><category scheme="http://www.blogger.com/atom/ns#" term="rename"/><category scheme="http://www.blogger.com/atom/ns#" term="snippets"/><title type='text'>Snippets: Filename padder [Python]</title><content type='html'>I recently downloaded nearly 1400 pictures (a complete webcomic). The problem came with the naming. The files were named from 1.png to 1400.png, making CDisplay and other programs display them in ASCII sort (1.png, 10.png, 100.png, 1000.png, 2.png...). Maybe there is a better solution but what I did was pad the filenames with zeros, so they became 0001.png, 0010.png and so.&lt;br /&gt;&lt;br /&gt;This is what I did:&lt;br /&gt;&lt;pre name=&quot;code&quot; class=&quot;python&quot;&gt;&lt;br /&gt;import os&lt;br /&gt;&lt;br /&gt;dir = &quot;D:\\Directory\\&quot;&lt;br /&gt;for file in os.listdir(dir):&lt;br /&gt; splitfilename = file.split(&quot;.&quot;)&lt;br /&gt; name = splitfilename[0]&lt;br /&gt; extension = splitfilename[1]&lt;br /&gt;&lt;br /&gt; newname = &quot;0&quot; * (4 - len(name)) + name&lt;br /&gt; print file + &quot; =&gt; &quot; + newname + &quot;.&quot; + extension&lt;br /&gt; os.rename(dir + file, dir + newname + &quot;.&quot; + extension&lt;br /&gt;&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://codeismusic.blogspot.com/feeds/810073793988125529/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://codeismusic.blogspot.com/2009/02/snippets-filename-padder-python.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7949101630202648210/posts/default/810073793988125529'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7949101630202648210/posts/default/810073793988125529'/><link rel='alternate' type='text/html' href='http://codeismusic.blogspot.com/2009/02/snippets-filename-padder-python.html' title='Snippets: Filename padder [Python]'/><author><name>Gonzalo Quero</name><uri>http://www.blogger.com/profile/07447335155416902229</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7949101630202648210.post-1967545351247131948</id><published>2009-01-29T13:22:00.001+01:00</published><updated>2009-02-02T00:37:50.728+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="programming"/><category scheme="http://www.blogger.com/atom/ns#" term="vim"/><title type='text'>VIM</title><content type='html'>&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg1LmYBJpjqCUPk3yXsw2XqPuy8ZHuvIS_8Rh64d-EKKewHiAC5Lc9-gSdyQyjkAuX3_C6SlWpcLcGAgNv4vkeeSSBDb2mlpMTkE3mhT5_Ud5JngV46qq7f5f2Gupm7SFajEdBb-ec6/s1600-h/20040510-vim_colorscheme_nightwish.png&quot;&gt;&lt;img style=&quot;margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 192px; height: 114px;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg1LmYBJpjqCUPk3yXsw2XqPuy8ZHuvIS_8Rh64d-EKKewHiAC5Lc9-gSdyQyjkAuX3_C6SlWpcLcGAgNv4vkeeSSBDb2mlpMTkE3mhT5_Ud5JngV46qq7f5f2Gupm7SFajEdBb-ec6/s200/20040510-vim_colorscheme_nightwish.png&quot; alt=&quot;&quot; id=&quot;BLOGGER_PHOTO_ID_5296371136988713618&quot; border=&quot;0&quot; /&gt;&lt;/a&gt;&lt;br /&gt;Let me start saying something: The mouse ISN&#39;T evil. Things like &quot;everything is faster using the keyboard&quot; are not only zealotism, but also false. If you don&#39;t believe me, try moving all the pictures of your family folder where your dog is jumping or something like that using the command line and then using your favourite file explorer.&lt;br /&gt;&lt;br /&gt;But then, there are things that are truly faster when you can avoid using the mouse and focus only on the keyboard. I&#39;m talking, of course, about programming. Programming is all about focus. You need to be 100% focused on what you&#39;re doing, or else it won&#39;t be good, and, for me, having to take my hands off the keyboard, reach for the mouse and follow the movement for whatever the task I must do is a great drawback. That&#39;s why I love &lt;a href=&quot;http://www.vim.org/&quot;&gt;Vim&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Little disclaimer: VIM is hard to learn. This remembers me of a quote I once read on &lt;a href=&quot;http://bash.org/&quot;&gt;bash.org&lt;/a&gt;: &quot;Everyone&#39;s first vi session. ^C^C^X^X^X^XquitqQ!qdammit[esc]qwertyuiopasdfghjkl;:xwhat&quot;. What I am saying here is that VIM&#39;s intuitiveness is counter-intuitive. It doesn&#39;t make any sense until you finally start using the correct mindset. These are the rules I am using to learn it:&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;Hands on the home row.&lt;br /&gt;This is precisely VIM&#39;s philosohpy. Everything should be doable without having to leave the writing position on the keyboard.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Insert mode should be only used on short bursts.&lt;br /&gt;You don&#39;t move in insert mode. You only write on it. If you have to do any other task, press ESC and do it in normal mode.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;There&#39;s always an easier way to do it.&lt;br /&gt;For example, changing a simple character. You&#39;ve written &quot;clash&quot;, but you wanted &quot;class&quot;. The cursor is located just before the h you want to change and you have several ways:&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;dlis (delete, right, insert, s). You delete one character right of the cursor, enter insert mode and then write &quot;s&quot;.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;xis (delete character, insert, s). Same as before, but x does &quot;dl&quot; with one less keypress.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;cls (change, right, s). &quot;Change&quot; deletes the designed text and enters insert mode automatically.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;s. That&#39;s right. VIM uses 48 keys of the keyboard, and everyone has at least two functions: One when you press the key and another when you press shift + key. In this case, &quot;s&quot; is the key for &quot;substitute character&quot;.&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;But that&#39;s not the only thing I like about VIM. I&#39;m actually using it a lot for my PFC (I don&#39;t know how it&#39;s called in English. It&#39;s a project we, Spanish students must do before the end of our degree), which is a &lt;a href=&quot;http://www.djangoproject.com/&quot;&gt;Django&lt;/a&gt; application. As I often work from several locations (the university, my house, my office...) it&#39;s easier for me to log in to the server that runs it and program there. That leaves me without some possibilities, like using Eclipse + PyDev, but thanks to VIM, it&#39;s not much of a problem. My usual session goes like this:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;cd /var/project&lt;br /&gt;vim&lt;br /&gt;:e code/app/views.py (open file /var/project/code/app/views.py)&lt;br /&gt;:sp templates/app/template.html (open file /var/templates/app/template.html in an horizontal separator)&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This way, I can write the template and alter the view at the same time if I need it. To move between the two horizontal windows, I press Ctrl + W and then the direction. For example, to move to the upper window from below: Ctrl + W k. But that&#39;s not all.&lt;br /&gt;&lt;br /&gt;VIM is very customizable. That means you can alter it&#39;s behavior in almost any way you can imagine, like mapping keys to commands. I have four mappings in my .vimrc file:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;nmap &amp;lt;F1&amp;gt; :!invoke-rc.d apache2 restart&amp;lt;Enter&amp;gt;&lt;/pre&gt;Issue a restart without leaving the editor, pressing just one key.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;nmap &amp;lt;F2&amp;gt; :!svn commit -m &quot;&quot;&amp;lt;Left&amp;gt;&lt;/pre&gt;I just love this one. It writes the commit command and then the &lt;left&gt; moves the cursor one charater to the left, effectively leaving me between the double quotes to write the commit message.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;nmap &amp;lt;F3&amp;gt; :!svn update&amp;lt;Enter&amp;gt;&lt;/pre&gt;I&#39;m not alone in this project, and sometimes my partner does some important modifications that I must load from the version control system.&lt;br /&gt;&lt;br /&gt;And the strangest one:&lt;br /&gt;&lt;pre&gt;imap ñ ;&lt;/pre&gt;&lt;/left&gt;As I said before, I&#39;m a Spaniard, which means my keyboard has a different layout, with &quot;ñ&quot; and &quot;ç&quot;, and &quot;ñ&quot; is located where the semicolon is in an English keyboard. My semicolon is actually shift + comma, making it harder to write, and it being a usual programming character, it&#39;s just not acceptable. That&#39;s why I remap it in the configuration so &quot;ñ&quot; writes a semicolon. Code doesn&#39;t use &quot;ñ&quot; ever, and the html templates have it as &quot;&amp;amp;ntilde;&quot;, so I just don&#39;t need it.&lt;br /&gt;&lt;br /&gt;So this is it, an editor that let&#39;s you do any task without breaking your focus on the text, all configured to your liking, with more than seventeen years of experience on his back (and that&#39;s if you only take vim into account, and not vi), and, best of all, open-source. That&#39;s free and mantained by a big community for you, folks, a very good thing. Love it or hate it, but try it first.&lt;br /&gt;&lt;br /&gt;Links:&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;&lt;a href=&quot;http://www.viemu.com/vi-vim-cheat-sheet.gif&quot;&gt;Vim cheatsheet&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;a href=&quot;http://www.vi-improved.org/tutorial.php&quot;&gt;Vim IRC tutorial&lt;/a&gt; Strange as it sounds, I used this one to learn the basic usage&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Book: &lt;a href=&quot;http://www.amazon.com/gp/product/059652983X?ie=UTF8&amp;tag=codismus-20&amp;linkCode=xm2&amp;camp=1789&amp;creativeASIN=059652983X&quot;&gt;Learning the vi and Vim Editors [ILLUSTRATED] (Paperback)&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Book: &lt;a href=&quot;http://www.amazon.com/gp/product/1847190936?ie=UTF8&amp;tag=codismus-20&amp;linkCode=xm2&amp;camp=1789&amp;creativeASIN=1847190936&quot;&gt;Hacking Vim: A Cookbook to get the Most out of the Latest Vim Editor&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;</content><link rel='replies' type='application/atom+xml' href='http://codeismusic.blogspot.com/feeds/1967545351247131948/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://codeismusic.blogspot.com/2009/01/vim.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7949101630202648210/posts/default/1967545351247131948'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7949101630202648210/posts/default/1967545351247131948'/><link rel='alternate' type='text/html' href='http://codeismusic.blogspot.com/2009/01/vim.html' title='VIM'/><author><name>Gonzalo Quero</name><uri>http://www.blogger.com/profile/07447335155416902229</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg1LmYBJpjqCUPk3yXsw2XqPuy8ZHuvIS_8Rh64d-EKKewHiAC5Lc9-gSdyQyjkAuX3_C6SlWpcLcGAgNv4vkeeSSBDb2mlpMTkE3mhT5_Ud5JngV46qq7f5f2Gupm7SFajEdBb-ec6/s72-c/20040510-vim_colorscheme_nightwish.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7949101630202648210.post-7895064146989607354</id><published>2009-01-27T10:32:00.009+01:00</published><updated>2009-01-27T12:23:11.084+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="matrix"/><category scheme="http://www.blogger.com/atom/ns#" term="programming"/><category scheme="http://www.blogger.com/atom/ns#" term="python"/><category scheme="http://www.blogger.com/atom/ns#" term="snippets"/><title type='text'>Snippets: Creating a matrix in python</title><content type='html'>There&#39;s two easy ways to do this:&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Looping:&lt;/span&gt;&lt;br /&gt;&lt;pre name=&quot;code&quot; class=&quot;python&quot;&gt;&lt;br /&gt;def matrix(rownumber,columnumber):&lt;br /&gt;   matrix = []&lt;br /&gt;   for i in range(rownumber):&lt;br /&gt;       a = [0]*columnumber&lt;br /&gt;       matrix.append(a)&lt;br /&gt;   return matrix&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;List comprehensions:&lt;/span&gt;&lt;br /&gt;&lt;pre name=&quot;code&quot; class=&quot;python&quot;&gt;&lt;br /&gt;def matrix(rownumber, columnumber):&lt;br /&gt;    return [[0]*columnumber for x in range(rownumber)]&lt;br /&gt;&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://codeismusic.blogspot.com/feeds/7895064146989607354/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://codeismusic.blogspot.com/2009/01/snippets-creating-matrix-in-python.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7949101630202648210/posts/default/7895064146989607354'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7949101630202648210/posts/default/7895064146989607354'/><link rel='alternate' type='text/html' href='http://codeismusic.blogspot.com/2009/01/snippets-creating-matrix-in-python.html' title='Snippets: Creating a matrix in python'/><author><name>Gonzalo Quero</name><uri>http://www.blogger.com/profile/07447335155416902229</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7949101630202648210.post-6450299159854708919</id><published>2009-01-26T19:10:00.008+01:00</published><updated>2009-01-27T00:35:20.101+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="music"/><category scheme="http://www.blogger.com/atom/ns#" term="programming"/><category scheme="http://www.blogger.com/atom/ns#" term="subjective"/><title type='text'>Code is Music</title><content type='html'>&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhaoKlpDKH83nl0hlk-KGClqGit0ZmJ8F_L1KpA8pkWfPpEznYYVfl3i_-ivLhi9k75_E9t2Y069XQV4I-GsgXEurEA1j7qpCpBlp0Xva-og9WXIA680o62PoyKyQhfqVXuF6rKGSjc/s1600-h/sheet+music.jpg&quot;&gt;&lt;img style=&quot;margin: 0pt 0pt 10px 10px; float: right; cursor: pointer; width: 184px; height: 144px;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhaoKlpDKH83nl0hlk-KGClqGit0ZmJ8F_L1KpA8pkWfPpEznYYVfl3i_-ivLhi9k75_E9t2Y069XQV4I-GsgXEurEA1j7qpCpBlp0Xva-og9WXIA680o62PoyKyQhfqVXuF6rKGSjc/s200/sheet+music.jpg&quot; alt=&quot;&quot; id=&quot;BLOGGER_PHOTO_ID_5295743555435563538&quot; border=&quot;0&quot; /&gt;&lt;/a&gt;&lt;br /&gt;Coding is an art. It may look boring, like an indecipherable wall of strangely coloured text, but, like one of those cubist paintings it&#39;s not the look but the message what matters in the end. You can look at it and think &quot;It&#39;s just garbled characters. I will never get it&quot; and you will never get it, but, try thinking about it, talking to the computer, giving it instructions in a manner not only understood by it, but also by the programmer, and then it makes sense.&lt;br /&gt;&lt;br /&gt;Like music, code is an universal language. Sure, there is actually a lot of programming languages, but that doesn&#39;t matter. You hear Johann Sebastian Bach and think &quot;It&#39;s music&quot;, and then some Metallica and also recognize it as music. That&#39;s the beauty of coding. That&#39;s why code is music.&lt;br /&gt;&lt;br /&gt;Think of it, you, the programmer, the composer, sit in front of an empty sheet. You are thinking of a message, something you want to convey to your audience. The melody is already on your head. It&#39;s the basic structure of the program. Then, you start giving shape to your creation, adding layers, making them work in harmony until it&#39;s done. Your first creations, as in music, don&#39;t make sense to anybody. You think you&#39;re saying A and they hear B, just like the computer keeps doing anything else but what you want, but it&#39;s ok, it&#39;s a learning process. Failure teaches a lot more than boring success.&lt;br /&gt;&lt;br /&gt;I&#39;m in no way an expert. My &quot;songs&quot; are still punk-rock simple, noisy and fun, but pretty limited. Still, it&#39;s a fun road to walk and I want to share my experiences, so welcome to &quot;Code is Music&quot;, and now... Start playing!</content><link rel='replies' type='application/atom+xml' href='http://codeismusic.blogspot.com/feeds/6450299159854708919/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://codeismusic.blogspot.com/2009/01/code-is-music.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7949101630202648210/posts/default/6450299159854708919'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7949101630202648210/posts/default/6450299159854708919'/><link rel='alternate' type='text/html' href='http://codeismusic.blogspot.com/2009/01/code-is-music.html' title='Code is Music'/><author><name>Gonzalo Quero</name><uri>http://www.blogger.com/profile/07447335155416902229</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhaoKlpDKH83nl0hlk-KGClqGit0ZmJ8F_L1KpA8pkWfPpEznYYVfl3i_-ivLhi9k75_E9t2Y069XQV4I-GsgXEurEA1j7qpCpBlp0Xva-og9WXIA680o62PoyKyQhfqVXuF6rKGSjc/s72-c/sheet+music.jpg" height="72" width="72"/><thr:total>0</thr:total></entry></feed>