vemod.net http://termos.vemod.net/ ... build_query http://termos.vemod.net/build_query <p>A simple helper function for preparing <span class="caps">SQL</span> queries with data from outside &#8211; say no to <a href="http://en.wikipedia.org/wiki/SQL_injection" class="external"><span class="caps">SQL</span> injections</a>.</p> <pre><code class="ultraviolet">&lt;? <span class="Storage">function</span> <span class="FunctionName">build_query</span>(<span class="Variable"><span class="Variable">$</span>query</span>, <span class="Variable"><span class="Variable">$</span>_query_args_</span>) { <span class="Variable"><span class="Variable">$</span>query_args</span> <span class="Operator">=</span> <span class="CommandMethod">array_slice</span>(<span class="CommandMethod">func_get_args</span>(), <span class="Number">1</span>)<span class="Operator">;</span> <span class="Variable"><span class="Variable">$</span>escaped_query_args</span> <span class="Operator">=</span> <span class="CommandMethod">array_map</span>(<span class="String"><span class="String">&quot;</span>mysql_real_escape_string<span class="String">&quot;</span></span>, <span class="Variable"><span class="Variable">$</span>query_args</span>)<span class="Operator">;</span> <span class="Variable"><span class="Variable">$</span>sprinf_args</span> <span class="Operator">=</span> <span class="CommandMethod">array_merge</span>(<span class="CommandMethod">array</span>(<span class="Variable"><span class="Variable">$</span>query</span>), <span class="Variable"><span class="Variable">$</span>escaped_query_args</span>)<span class="Operator">;</span> <span class="Variable"><span class="Variable">$</span>result</span> <span class="Operator">=</span> <span class="CommandMethod">call_user_func_array</span>(<span class="String"><span class="String">&quot;</span>sprintf<span class="String">&quot;</span></span>, <span class="Variable"><span class="Variable">$</span>sprintf_args</span>)<span class="Operator">;</span> <span class="Keyword">return</span> <span class="Variable"><span class="Variable">$</span>result</span><span class="Operator">;</span> } ?&gt; </code></pre> <h2>Example</h2> <pre><code class="ultraviolet">&lt;? build_query(<span class="String"><span class="String">&quot;</span><span class="Keyword">SELECT</span> * <span class="Keyword">FROM</span> users <span class="Keyword">WHERE</span> username = <span class="String"><span class="String">'</span>%s'</span> <span class="Keyword">AND</span> password = <span class="String"><span class="String">'</span>%s'</span><span class="String">&quot;</span></span>, <span class="String"><span class="String">&quot;</span>qerub<span class="String">&quot;</span></span>, <span class="String"><span class="String">&quot;</span>god' or ''='<span class="String">&quot;</span></span>) <span class="LineComment"><span class="LineComment">#</span> =&gt; &quot;SELECT * FROM users WHERE username = 'qerub' AND password = 'god\' or \'t\'=\'t'&quot; </span> ?&gt; </code></pre> <h2>A Note About Magic Quotes</h2> <p>If you have <a href="http://www.php.net/magic_quotes" class="external">magic quotes</a> enabled, please disable them before they make the world implode because of <a href="http://www.thefreedictionary.com/amentia" class="external">amentia</a>.</p><p><small>Tags: <a href="http://termos.vemod.net/php" class="tag" rel="tag">PHP</a></small></p> Tue, 30 Sep 2008 23:42:49 +0200 2008-09-30T23:42:49+02:00 iTunes Triggers in Adium http://termos.vemod.net/itunes-triggers-in-adium <p>Here&#8217;s a complete list of the triggers defined in <a href="http://trac.adiumx.com/browser/trunk/Source/ESiTunesPlugin.m" class="external"><code>ESiTunesPlugin.m</code> of Adium</a>:</p> <dl> <dt>%_album </dt><dd>Trigger for the album of the currently playing iTunes song </dd> <dt>%_artist </dt><dd>Trigger for the artist of the currently playing iTunes song </dd> <dt>%_composer</dt><dd>Trigger for the composer of the currently playing iTunes song </dd> <dt>%_genre </dt><dd>Trigger for the genre of the currently playing iTunes song </dd> <dt>%_status </dt><dd>Trigger for the genre of the currently playing iTunes song </dd> <dt>%_track </dt><dd>Trigger for the name of the currently playing iTunes song </dd> <dt>%_year </dt><dd>Trigger for the year of the currently playing iTunes song </dd> <dt>%_iTMS </dt><dd>Trigger for an iTunes Music Store link to the currently playing iTunes song</dd> <dt>%_music </dt><dd>Command which triggers *is listening to %_track by %_artist* </dd> <dt>%_iTunes </dt><dd>Trigger for the song - artist of the currently playing iTunes song </dd> </dl> <p>Please note that Adium localizes these strings so, for example, %_track becomes %_spår in Swedish.</p><p><small>Tags: <a href="http://termos.vemod.net/mac" class="tag" rel="tag">Mac</a></small></p> Sat, 13 Sep 2008 23:20:32 +0200 2008-09-13T23:20:32+02:00 C http://termos.vemod.net/c <blockquote> <p>C is a general-purpose, block structured, procedural, imperative computer programming language developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system.</p> </blockquote> <p><a href="http://en.wikipedia.org/wiki/C_(programming_language)">Wikipedia on C</a></p> <p>My personal favorite description of C is &#8220;portable assembler&#8221;. Please think of it that way. Think of the kittens.</p><p><small>Tags: </small></p> Thu, 04 Sep 2008 02:30:44 +0200 2008-09-04T02:30:44+02:00 assert for Ruby http://termos.vemod.net/assert-for-ruby <p>A little <code>assert</code> mechanism superficially similiar to that in <a href="http://termos.vemod.net/java" rel="tag">Java</a> and <a href="http://termos.vemod.net/c">C</a>.</p> <pre><code class="ultraviolet"><span class="Keyword">class</span> <span class="TypeName">AssertionFailure<span class="InheritedClass"> <span class="InheritedClass">&lt;</span> RuntimeError</span></span> <span class="Keyword">end</span> <span class="Keyword">def</span> <span class="FunctionName">assert</span>(<span class="FunctionArgument">condition<span class="FunctionArgument">,</span> message</span>) <span class="Keyword">unless</span> condition <span class="Keyword">raise</span> <span class="Variable">AssertionFailure</span>, <span class="String"><span class="String">&quot;</span>Assertion failed: <span class="String"><span class="String">#{</span>message<span class="String">}</span></span><span class="String">&quot;</span></span> <span class="Keyword">end</span> <span class="Keyword">end</span> </code></pre><p><small>Tags: <a href="http://termos.vemod.net/ruby" class="tag" rel="tag">Ruby</a></small></p> Thu, 04 Sep 2008 02:28:53 +0200 2008-09-04T02:28:53+02:00 HTML http://termos.vemod.net/HTML <blockquote> <p><strong><span class="caps">HTML</span></strong>, an initialism of <strong>HyperText Markup Language</strong>, is the predominant markup language for web pages. It provides a means to describe the structure of text-based information in a document — by denoting certain text as links, headings, paragraphs, lists, and so on — and to supplement that text with interactive forms, embedded images, and other objects.</p> </blockquote> <p><a href="http://en.wikipedia.org/wiki/HTML" class="external">Wikipedia on <span class="caps">HTML</span></a></p><p><small>Tags: </small></p> Mon, 25 Aug 2008 03:40:56 +0200 2008-08-25T03:40:56+02:00 rel Keyboard Navigation http://termos.vemod.net/rel-keyboard-navigation <p>Keyboard navigation is often missing on web sites. Its absence is especially frustrating on sites like <a href="http://www.flickr.com/" class="external">Flickr</a> where you simply want to move from photo to photo with a minimum of fuss. By providing a very simple way to add keyboard navigation I&#8217;m hoping to make it a little bit more popular.</p> <p>There&#8217;s a <code>rel</code> attribute in (X)HTML that is used to define the relations the document has to other documents. With this mechanism we can, for example, easily state that a page is to the <em>right</em> of another page, in any of these ways:</p> <pre><code class="ultraviolet"><span class="TagContainer"><span class="TagContainer">&lt;</span><span class="TagName">link</span> <span class="TagAttribute">rel</span>=<span class="String"><span class="String">&quot;</span>right<span class="String">&quot;</span></span> <span class="TagAttribute">href</span>=<span class="String"><span class="String">&quot;</span>smurfs.html<span class="String">&quot;</span></span> /<span class="TagContainer">&gt;</span></span> <span class="TagContainer"><span class="TagContainer">&lt;</span><span class="TagName">a</span> <span class="TagAttribute">rel</span>=<span class="String"><span class="String">&quot;</span>right<span class="String">&quot;</span></span> <span class="TagAttribute">href</span>=<span class="String"><span class="String">&quot;</span>smurfs.html<span class="String">&quot;</span></span><span class="TagContainer">&gt;</span></span>Smurfs<span class="TagContainer"><span class="TagContainer">&lt;/</span><span class="TagName">a</span><span class="TagContainer">&gt;</span></span> </code></pre> <p>This information can then be accessed from JavaScript when arrow keys are pressed.</p> <h2>An Implementation</h2> <p>My <a href="http://photos.vemod.net/" class="external">photo gallery</a> has a <a href="http://photos.vemod.net/rel-keyboard-navigation.js" class="external">simple and elegant implementation</a> of this idea that you&#8217;re free to use under the very liberal <a href="http://sam.zoy.org/wtfpl/COPYING" title="Do What The Fuck You Want To Public License" class="external"><span class="caps">WTFPL</span></a>. Here&#8217;s an <a href="http://photos.vemod.net/4294970229.html" class="external">example photo page</a> &#8211; try going there and pressing the arrow keys on your keyboard.</p><p><small>Tags: <a href="http://termos.vemod.net/javascript" class="tag" rel="tag">JavaScript</a> and <a href="http://termos.vemod.net/HTML" class="tag" rel="tag">HTML</a></small></p> Mon, 25 Aug 2008 01:49:04 +0200 2008-08-25T01:49:04+02:00 Post-Installation Notes for Mac OS X Leopard http://termos.vemod.net/post-installation-notes-for-mac-os-x-leopard <h2>Make the menu bar opaque</h2> <p>Check the checkbox at the bottom of Desktop &#38; Screen-Saver in System Preferences.</p> <h2>Get back the 2D dock</h2> <pre><code>defaults write com.apple.dock no-glass -boolean YES killall Dock</code></pre> <h2>Disable delayed <span class="caps">TCP</span> acks</h2> <p>These make Samba/CIFS transfer slow as hell.</p> <pre><code>x="net.inet.tcp.delayed_ack=0" echo "$x" | sudo tee -a /etc/sysctl.conf sudo chown root:wheel /etc/sysctl.conf sudo chmod 0644 /etc/sysctl.conf sudo sysctl -w "$x" </code></pre> <h2>Fix iTunes</h2> <p>Not really an <span class="caps">OS X</span> thing, but whatever&#8230;</p> <pre><code>defaults write com.apple.iTunes show-store-arrow-links -bool FALSE defaults write com.apple.itunes show-genre-when-browsing -bool FALSE</code></pre> <h2>Enable full keyboard access</h2> <p>It&#8217;s somewhere in System Preferences&#8230;</p><p><small>Tags: <a href="http://termos.vemod.net/mac" class="tag" rel="tag">Mac</a></small></p> Mon, 04 Aug 2008 17:42:24 +0200 2008-08-04T17:42:24+02:00 Photos http://termos.vemod.net/photos <p style="text-align:center;">My photos are available at <a href="http://photos.vemod.net/" class="external">photos.vemod.net</a>.</p> <p style="text-align:center;"><a href="http://photos.vemod.net/4294969967.html"><img src="http://photos.vemod.net/images/4294969967.jpg" alt="" /></a></p><p><small>Tags: </small></p> Mon, 21 Jul 2008 17:46:03 +0200 2008-07-21T17:46:03+02:00 TextMate Integration for Rack::ShowExceptions http://termos.vemod.net/textmate-integration-for-rack-showexceptions <p><code><a href="http://rack.rubyforge.org/">Rack</a>::ShowExceptions</code> is very nice, but it is even nicer with links straight into TextMate:</p> <p style="text-align:center;"><img src="/stuff/textmate-integration-for-rack-showexceptions.png" alt="" /></p> <p>You can get the functionality by cherry picking <a href="http://github.com/Qerub/rack/commit/859bba0de77d391134c422d87370cff3924f1cef" class="external">859bba0de77d391134c422d87370cff3924f1cef</a> from git://github.com/Qerub/rack.git.</p><p><small>Tags: <a href="http://termos.vemod.net/ruby" class="tag" rel="tag">Ruby</a> and <a href="http://termos.vemod.net/mac" class="tag" rel="tag">Mac</a></small></p> Thu, 10 Jul 2008 00:55:19 +0200 2008-07-10T00:55:19+02:00 Slugalizer http://termos.vemod.net/slugalizer <h1 style="text-align:center;"><img title="Slugalizer" src="/stuff/slugalizer.png" alt="Slugalizer" /></h1> <p>Slugalizer is a one-method <a href="http://termos.vemod.net/ruby" rel="tag">Ruby</a> library that can <em>slugalize</em> (or <em>slugify</em>) strings, like this:</p> <pre><code class="ultraviolet"><span class="LibraryClassType">Slugalizer</span>.<span class="FunctionName">slugalize</span>(<span class="String"><span class="String">&quot;</span>Åh, räksmörgåsar!<span class="String">&quot;</span></span>) <span class="LineComment"><span class="LineComment">#</span> =&gt; &quot;ah-raksmorgasar&quot; </span> </code></pre> <h2>Download</h2> <p><a href="http://code.vemod.net/svn/misc/slugalizer/slugalizer.rb" class="ruby code">slugalizer.rb</a></p><p><small>Tags: <a href="http://termos.vemod.net/ruby" class="tag" rel="tag">Ruby</a></small></p> Thu, 10 Jul 2008 00:39:14 +0200 2008-07-10T00:39:14+02:00 Termos