samhuri.net/wayback/@done/2007.08.11-sjs - geeky ramblings.html

1419 lines
67 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>sjs - geeky ramblings</title>
<link rel="openid.server" href="http://www.myopenid.com/server" />
<link rel="openid.delegate" href="http://sami-samhuri.myopenid.com/" />
<meta http-equiv="X-XRDS-Location" content="http://sami-samhuri.myopenid.com/xrds" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="alternate" type="application/rss+xml" title="RSS" href="http://feeds.feedburner.com/sjs" />
<script src="http://web.archive.org/web/20070811125748js_/http://sami.samhuri.net/javascripts/prototype.js" type="text/javascript"></script>
<link href="http://web.archive.org/web/20070811125748cs_/http://sami.samhuri.net/stylesheets/application.css" rel="stylesheet" type="text/css" />
</head>
<body>
<!-- BEGIN WAYBACK TOOLBAR INSERT -->
<script type="text/javascript" src="http://staticweb.archive.org/js/disclaim-element.js" ></script>
<script type="text/javascript" src="http://staticweb.archive.org/js/graph-calc.js" ></script>
<script type="text/javascript" src="http://staticweb.archive.org/jflot/jquery.min.js" ></script>
<script type="text/javascript">
//<![CDATA[
var firstDate = 820454400000;
var lastDate = 1325375999999;
var wbPrefix = "http://web.archive.org/web/";
var wbCurrentUrl = "http://sami.samhuri.net/";
var curYear = -1;
var curMonth = -1;
var yearCount = 16;
var firstYear = 1996;
var imgWidth=400;
var yearImgWidth = 25;
var monthImgWidth = 2;
var trackerVal = "none";
var displayDay = "11";
var displayMonth = "Aug";
var displayYear = "2007";
var prettyMonths = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
function showTrackers(val) {
if(val == trackerVal) {
return;
}
if(val == "inline") {
document.getElementById("displayYearEl").style.color = "#ec008c";
document.getElementById("displayMonthEl").style.color = "#ec008c";
document.getElementById("displayDayEl").style.color = "#ec008c";
} else {
document.getElementById("displayYearEl").innerHTML = displayYear;
document.getElementById("displayYearEl").style.color = "#ff0";
document.getElementById("displayMonthEl").innerHTML = displayMonth;
document.getElementById("displayMonthEl").style.color = "#ff0";
document.getElementById("displayDayEl").innerHTML = displayDay;
document.getElementById("displayDayEl").style.color = "#ff0";
}
document.getElementById("wbMouseTrackYearImg").style.display = val;
document.getElementById("wbMouseTrackMonthImg").style.display = val;
trackerVal = val;
}
function getElementX2(obj) {
var thing = jQuery(obj);
if((thing == undefined)
|| (typeof thing == "undefined")
|| (typeof thing.offset == "undefined")) {
return getElementX(obj);
}
return Math.round(thing.offset().left);
}
function trackMouseMove(event,element) {
var eventX = getEventX(event);
var elementX = getElementX2(element);
var xOff = eventX - elementX;
if(xOff < 0) {
xOff = 0;
} else if(xOff > imgWidth) {
xOff = imgWidth;
}
var monthOff = xOff % yearImgWidth;
var year = Math.floor(xOff / yearImgWidth);
var yearStart = year * yearImgWidth;
var monthOfYear = Math.floor(monthOff / monthImgWidth);
if(monthOfYear > 11) {
monthOfYear = 11;
}
// 1 extra border pixel at the left edge of the year:
var month = (year * 12) + monthOfYear;
var day = 1;
if(monthOff % 2 == 1) {
day = 15;
}
var dateString =
zeroPad(year + firstYear) +
zeroPad(monthOfYear+1,2) +
zeroPad(day,2) + "000000";
var monthString = prettyMonths[monthOfYear];
document.getElementById("displayYearEl").innerHTML = year + 1996;
document.getElementById("displayMonthEl").innerHTML = monthString;
// looks too jarring when it changes..
//document.getElementById("displayDayEl").innerHTML = zeroPad(day,2);
var url = wbPrefix + dateString + '/' + wbCurrentUrl;
document.getElementById('wm-graph-anchor').href = url;
//document.getElementById("wmtbURL").value="evX("+eventX+") elX("+elementX+") xO("+xOff+") y("+year+") m("+month+") monthOff("+monthOff+") DS("+dateString+") Moy("+monthOfYear+") ms("+monthString+")";
if(curYear != year) {
var yrOff = year * yearImgWidth;
document.getElementById("wbMouseTrackYearImg").style.left = yrOff + "px";
curYear = year;
}
if(curMonth != month) {
var mtOff = year + (month * monthImgWidth) + 1;
document.getElementById("wbMouseTrackMonthImg").style.left = mtOff + "px";
curMonth = month;
}
}
//]]>
</script>
<style type="text/css">body{margin-top:0!important;padding-top:0!important;min-width:800px!important;}#wm-ipp a:hover{text-decoration:underline!important;}</style>
<div id="wm-ipp" style="display:none; position:relative;padding:0 5px;min-height:70px;min-width:800px; z-index:9000;">
<div id="wm-ipp-inside" style="position:fixed;padding:0!important;margin:0!important;width:97%;min-width:780px;border:5px solid #000;border-top:none;background-image:url(http://staticweb.archive.org/images/toolbar/wm_tb_bk_trns.png);text-align:center;-moz-box-shadow:1px 1px 3px #333;-webkit-box-shadow:1px 1px 3px #333;box-shadow:1px 1px 3px #333;font-size:11px!important;font-family:'Lucida Grande','Arial',sans-serif!important;">
<table style="border-collapse:collapse;margin:0;padding:0;width:100%;"><tbody><tr>
<td style="padding:10px;vertical-align:top;min-width:110px;">
<a href="http://wayback.archive.org/web/" title="Wayback Machine home page" style="background-color:transparent;border:none;"><img src="http://staticweb.archive.org/images/toolbar/wayback-toolbar-logo.png" alt="Wayback Machine" width="110" height="39" border="0"/></a>
</td>
<td style="padding:0!important;text-align:center;vertical-align:top;width:100%;">
<table style="border-collapse:collapse;margin:0 auto;padding:0;width:570px;"><tbody><tr>
<td style="padding:3px 0;" colspan="2">
<form target="_top" method="get" action="http://wayback.archive.org/web/form-submit.jsp" name="wmtb" id="wmtb" style="margin:0!important;padding:0!important;"><input type="text" name="url" id="wmtbURL" value="http://sami.samhuri.net/" style="width:400px;font-size:11px;font-family:'Lucida Grande','Arial',sans-serif;" onfocus="javascript:this.focus();this.select();" /><input type="hidden" name="type" value="replay" /><input type="hidden" name="date" value="20070811125748" /><input type="submit" value="Go" style="font-size:11px;font-family:'Lucida Grande','Arial',sans-serif;margin-left:5px;" /><span id="wm_tb_options" style="display:block;"></span></form>
</td>
<td style="vertical-align:bottom;padding:5px 0 0 0!important;" rowspan="2">
<table style="border-collapse:collapse;width:110px;color:#99a;font-family:'Helvetica','Lucida Grande','Arial',sans-serif;"><tbody>
<!-- NEXT/PREV MONTH NAV AND MONTH INDICATOR -->
<tr style="width:110px;height:16px;font-size:10px!important;">
<td style="padding-right:9px;font-size:11px!important;font-weight:bold;text-transform:uppercase;text-align:right;white-space:nowrap;overflow:visible;" nowrap="nowrap">
<a href="http://sami.samhuri.net/" style="text-decoration:none;color:#33f;font-weight:bold;background-color:transparent;border:none;" title="29 Jun 2007"><strong>JUN</strong></a>
</td>
<td id="displayMonthEl" style="background:#000;color:#ff0;font-size:11px!important;font-weight:bold;text-transform:uppercase;width:34px;height:15px;padding-top:1px;text-align:center;" title="You are here: 12:57:48 Aug 11, 2007">AUG</td>
<td style="padding-left:9px;font-size:11px!important;font-weight:bold;text-transform:uppercase;white-space:nowrap;overflow:visible;" nowrap="nowrap">
<a href="http://sami.samhuri.net/" style="text-decoration:none;color:#33f;font-weight:bold;background-color:transparent;border:none;" title="11 Oct 2007"><strong>OCT</strong></a>
</td>
</tr>
<!-- NEXT/PREV CAPTURE NAV AND DAY OF MONTH INDICATOR -->
<tr>
<td style="padding-right:9px;white-space:nowrap;overflow:visible;text-align:right!important;vertical-align:middle!important;" nowrap="nowrap">
<a href="http://sami.samhuri.net/" title="10:31:38 Jun 29, 2007" style="background-color:transparent;border:none;"><img src="http://staticweb.archive.org/images/toolbar/wm_tb_prv_on.png" alt="Previous capture" width="14" height="16" border="0" /></a>
</td>
<td id="displayDayEl" style="background:#000;color:#ff0;width:34px;height:24px;padding:2px 0 0 0;text-align:center;font-size:24px;font-weight: bold;" title="You are here: 12:57:48 Aug 11, 2007">11</td>
<td style="padding-left:9px;white-space:nowrap;overflow:visible;text-align:left!important;vertical-align:middle!important;" nowrap="nowrap">
<a href="http://sami.samhuri.net/" title="23:50:42 Sep 10, 2007" style="background-color:transparent;border:none;"><img src="http://staticweb.archive.org/images/toolbar/wm_tb_nxt_on.png" alt="Next capture" width="14" height="16" border="0"/></a>
</td>
</tr>
<!-- NEXT/PREV YEAR NAV AND YEAR INDICATOR -->
<tr style="width:110px;height:13px;font-size:9px!important;">
<td style="padding-right:9px;font-size:11px!important;font-weight: bold;text-align:right;white-space:nowrap;overflow:visible;" nowrap="nowrap">
<a href="http://sami.samhuri.net/" style="text-decoration:none;color:#33f;font-weight:bold;background-color:transparent;border:none;" title="20 Jun 2006"><strong>2006</strong></a>
</td>
<td id="displayYearEl" style="background:#000;color:#ff0;font-size:11px!important;font-weight: bold;padding-top:1px;width:34px;height:13px;text-align:center;" title="You are here: 12:57:48 Aug 11, 2007">2007</td>
<td style="padding-left:9px;font-size:11px!important;font-weight: bold;white-space:nowrap;overflow:visible;" nowrap="nowrap">
<a href="http://sami.samhuri.net/" style="text-decoration:none;color:#33f;font-weight:bold;background-color:transparent;border:none;" title="1 Feb 2009"><strong>2009</strong></a>
</td>
</tr>
</tbody></table>
</td>
</tr>
<tr>
<td style="vertical-align:middle;padding:0!important;">
<a href="http://wayback.archive.org/web/20070811125748*/http://sami.samhuri.net/" style="color:#33f;font-size:11px;font-weight:bold;background-color:transparent;border:none;" title="See a list of every capture for this URL"><strong>23 captures</strong></a>
<div style="margin:0!important;padding:0!important;color:#666;font-size:9px;padding-top:2px!important;white-space:nowrap;" title="Timespan for captures of this URL">3 Mar 06 - 31 May 09</div>
</td>
<td style="padding:0!important;">
<a style="position:relative; white-space:nowrap; width:400px;height:27px;" href="" id="wm-graph-anchor">
<div id="wm-ipp-sparkline" style="position:relative; white-space:nowrap; width:400px;height:27px;background-color:#fff;cursor:pointer;border-right:1px solid #ccc;" title="Explore captures for this URL">
<img id="sparklineImgId" style="position:absolute; z-index:9012; top:0px; left:0px;"
onmouseover="showTrackers('inline');"
onmouseout="showTrackers('none');"
onmousemove="trackMouseMove(event,this)"
alt="sparklines"
width="400"
height="27"
border="0"
src="http://wayback.archive.org/jsp/graph.jsp?graphdata=400_27_1996:-1:000000000000_1997:-1:000000000000_1998:-1:000000000000_1999:-1:000000000000_2000:-1:000000000000_2001:-1:000000000000_2002:-1:000000000000_2003:-1:000000000000_2004:-1:000000000000_2005:-1:000000000000_2006:-1:001102000100_2007:7:001121011211_2008:-1:011100100000_2009:-1:010110000000_2010:-1:000000000000_2011:-1:000000000000"></img>
<img id="wbMouseTrackYearImg"
style="display:none; position:absolute; z-index:9010;"
width="25"
height="27"
border="0"
src="http://staticweb.archive.org/images/toolbar/transp-yellow-pixel.png"></img>
<img id="wbMouseTrackMonthImg"
style="display:none; position:absolute; z-index:9011; "
width="2"
height="27"
border="0"
src="http://staticweb.archive.org/images/toolbar/transp-red-pixel.png"></img>
</div>
</a>
</td>
</tr></tbody></table>
</td>
<td style="text-align:right;padding:5px;width:65px;font-size:11px!important;">
<a href="javascript:;" onclick="document.getElementById('wm-ipp').style.display='none';" style="display:block;padding-right:18px;background:url(http://staticweb.archive.org/images/toolbar/wm_tb_close.png) no-repeat 100% 0;color:#33f;font-family:'Lucida Grande','Arial',sans-serif;margin-bottom:23px;background-color:transparent;border:none;" title="Close the toolbar">Close</a>
<a href="http://faq.web.archive.org/" style="display:block;padding-right:18px;background:url(http://staticweb.archive.org/images/toolbar/wm_tb_help.png) no-repeat 100% 0;color:#33f;font-family:'Lucida Grande','Arial',sans-serif;background-color:transparent;border:none;" title="Get some help using the Wayback Machine">Help</a>
</td>
</tr></tbody></table>
</div>
</div>
<script type="text/javascript">
var wmDisclaimBanner = document.getElementById("wm-ipp");
if(wmDisclaimBanner != null) {
disclaimElement(wmDisclaimBanner);
}
</script>
<!-- END WAYBACK TOOLBAR INSERT -->
<div id="container">
<div id="header">
<h1><span><a href="http://sami.samhuri.net/">sjs</a></span></h1>
<h2>geeky ramblings</h2>
</div>
<div id="page">
<div id="content">
<div class="hentry" id="article-217">
<h2 class="entry-title">
<a href="http://sami.samhuri.net/2007/8/10/cheat-from-emacs">Cheat from Emacs</a>
<span class="comment_count">4</span>
</h2>
<div class="vcard">
Posted by <span class="fn">sjs</span>
</div>
<abbr class="published" title="2007-08-10T01:56:00+00:00">on Friday, August 10</abbr>
<br class="clear" />
<div class="entry-content">
<p><em>Update: I had inadvertently used <code>string-join</code>, a function provided by something in my ~/.emacs.d. The script has been updated to work with a vanilla Emacs (23, but should work with 22 as well).</em></p>
<p><em>Update #2 [2007/08/10]: Editing cheats and diffs have been implemented.</em></p>
<p>We all know and love <a href="http://cheat.errtheblog.com/">cheat</a>. Now you can cheat without leaving Emacs (and without using a shell in Emacs).</p>
<p>Just save <a href="http://sami.samhuri.net/assets/2007/8/10/cheat.el">cheat.el</a> in ~/.emacs.d and then <code>(require 'cheat)</code> in your ~/.emacs. I also bind <code>C-z C-c</code> to <code>cheat</code>, you may want to do something similar.</p>
<p><del>You can't do everything you can do with cheat on the command line yet</del>, and for most of the commands the cheat command itself is used. <em>Now you can do everything the command line client does from within Emacs, though you may need to revert to using <code>cheat-command</code> (described below).</em></p>
<p>Here's the rundown:</p>
<ul>
<li><code>cheat</code> - Lookup a cheat sheet interactively (<code>cheat &lt;name&gt;</code>)</li>
<li><code>cheat-sheets</code> - List all cheat sheets (<code>cheat sheets</code>)</li>
<li><code>cheat-recent</code> - List recently added cheat sheets (<code>cheat recent</code>)</li>
<li><code>cheat-versions</code> - List versions of a cheat sheet interactively (<code>cheat &lt;name&gt; --versions</code>)</li>
<li><code>cheat-clear-cache</code> - Clear a cached sheet interactively, clear them all if no name is given. (<code>cheat --clear-cache [&lt;name&gt;]</code>)</li>
<li><code>cheat-add-current-buffer</code> - Add a new cheat using the specified name and the contents of the current buffer as the body. (<code>cheat &lt;name&gt; --add</code>)</li>
<li><code>cheat-edit</code> - Retrieve a fresh copy of the named cheat and display the body in a buffer for editing.</li>
<li><code>cheat-save-current-buffer</code> - Save the current cheat buffer, which should be named <code>*cheat-&lt;name&gt;*</code>.</li>
<li><code>cheat-diff</code> - Show the diff between the current version and the given version of the named cheat. If the version given is of the form <em>m:n</em> then show the diff between versions <em>m</em> and <em>n</em>. (<code>cheat &lt;name&gt; --diff &lt;version&gt;</code>)</li>
<li><code>cheat-command</code> - Pass any arguments you want to cheat interactively.</li>
</ul>
<p><em>(Added)</em> <del>I may add support for <code>--diff</code> and <code>--edit</code> in the future.</del></p>
<p>Please do send me your patches so everyone can benefit from them.</p>
</div>
<ul class="meta">
<li>
Sections: <a href="http://sami.samhuri.net/emacs">Emacs</a>
</li>
<li>
Tags: <a href="http://sami.samhuri.net/tags/cheat">cheat</a>&nbsp;<a href="http://sami.samhuri.net/tags/emacs">emacs</a>&nbsp;
</li>
<li>
Meta:
<a href="http://sami.samhuri.net/2007/8/10/cheat-from-emacs">4 comments</a>,
<a href="http://sami.samhuri.net/2007/8/10/cheat-from-emacs">permalink</a>
</li>
</ul>
</div>
<div class="hentry" id="article-214">
<h2 class="entry-title">
<a href="http://sami.samhuri.net/2007/8/9/snap-crunchle-pop">Snap, crunchle, pop</a>
<span class="comment_count">1</span>
</h2>
<div class="vcard">
Posted by <span class="fn">sjs</span>
</div>
<abbr class="published" title="2007-08-09T10:17:00+00:00">on Thursday, August 09</abbr>
<br class="clear" />
<div class="entry-content">
<p>I think that every now and then we need to be reminded of the frail nature of our human bodies. Yesterday morning as I walked to my kitchen I was turning right by pivoting on my right foot when my 24 years of walking experience suddenly failed me. I clearly did something wrong, as I heard a crunching pop or two in my right ankle and went down. Luckily it's just a sprain but my foot is fairly bruised and still sore today. I'm trying to follow the <a href="http://orthopedics.about.com/cs/sprainsstrains/a/sprain_4.htm">RICE</a> method for recuperating but one can only lay down for so long before having to eat, work, use the bathroom, etc. Thank goodness I don't work on my feet or I'd be out of commission. If it still hurts next week I'm going to see a doctor but till then I'm trying not to leave my house. The idea of hopping and hobbling to a bus to go to a doctor does not thrill me in the slightest.</p>
<p>Oh, if you find yourself in a bind an upside down hockey stick is a decent makeshift crutch. You'll need 2 hands to operate the thing though.</p>
<p>At the opposite end of the spectrum there are times when we seem to be amazingly resilient creatures. Check out a documentary called <em>"101 Things Removed from the Human Head"</em> if you can find it anywhere. One of those things was a boat anchor, I kid you not.</p>
</div>
<ul class="meta">
<li>
Tags: <a href="http://sami.samhuri.net/tags/humans">humans</a>&nbsp;<a href="http://sami.samhuri.net/tags/injury">injury</a>&nbsp;<a href="http://sami.samhuri.net/tags/life">life</a>&nbsp;
</li>
<li>
Meta:
<a href="http://sami.samhuri.net/2007/8/9/snap-crunchle-pop">1 comment</a>,
<a href="http://sami.samhuri.net/2007/8/9/snap-crunchle-pop">permalink</a>
</li>
</ul>
</div>
<div class="hentry" id="article-210">
<h2 class="entry-title">
<a href="http://sami.samhuri.net/2007/8/2/elschemo-boolean-logic-and-branching">ElSchemo: Boolean logic and branching</a>
<span class="comment_count">0</span>
</h2>
<div class="vcard">
Posted by <span class="fn">sjs</span>
</div>
<abbr class="published" title="2007-08-02T16:59:00+00:00">on Thursday, August 02</abbr>
<br class="clear" />
<div class="entry-content">
<p>Well it has been a while since my last post. I'll try not to do that
frequently. Anyhow, on to the good stuff.</p>
<p>I've been developing a Scheme
interpreter in Haskell called
<a href="http://sami.samhuri.net/2007/6/25/floating-point-in-elschemo">ElSchemo</a>.
It started from <a href="http://halogen.note.amherst.edu/~jdtang/scheme_in_48/tutorial/overview.html">Jonathan's excellent Haskell
tutorial</a>
which I followed in order to learn both Haskell and Scheme. Basically
that means the code here is for me to get some feedback as much
as to show others how to do this kind of stuff. This may not be too
interesting if you haven't at least browsed the tutorial.</p>
<p>I'm going to cover 3 new special forms: <code>and</code>, <code>or</code>, and <code>cond</code>. I
promised to cover the <code>let</code> family of special forms this time around
but methinks this is long enough as it is. My sincere apologies if
you've been waiting for those.</p>
<div class="extended">
<p><a href="http://sami.samhuri.net/2007/8/2/elschemo-boolean-logic-and-branching">Continue reading...</a></p>
</div>
</div>
<ul class="meta">
<li>
Tags: <a href="http://sami.samhuri.net/tags/elschemo">elschemo</a>&nbsp;<a href="http://sami.samhuri.net/tags/haskell">haskell</a>&nbsp;<a href="http://sami.samhuri.net/tags/scheme">scheme</a>&nbsp;
</li>
<li>
Meta:
<a href="http://sami.samhuri.net/2007/8/2/elschemo-boolean-logic-and-branching">0 comments</a>,
<a href="http://sami.samhuri.net/2007/8/2/elschemo-boolean-logic-and-branching">permalink</a>
</li>
</ul>
</div>
<div class="hentry" id="article-157">
<h2 class="entry-title">
<a href="http://sami.samhuri.net/2007/7/12/poeple">people</a>
<span class="comment_count">0</span>
</h2>
<div class="vcard">
Posted by <span class="fn">sjs</span>
</div>
<abbr class="published" title="2007-07-12T12:28:00+00:00">on Thursday, July 12</abbr>
<br class="clear" />
<div class="entry-content">
<p>Sometimes this is difficult to remember for someone who (likes to think that he) thinks somewhat logically.</p>
<blockquote>
<p>When dealing with people, let us remember that we are not dealing with creatures of logic. We are dealing with creatures of emotion, creatures bristling with prejudices and motivated by pride and vanity.</p>
</blockquote>
<p>&#8212;<a href="http://en.wikipedia.org/wiki/Dale_Carnegie">Dale Carnegie</a>, <em><a href="http://en.wikipedia.org/wiki/How_to_Win_Friends_and_Influence_People">How to Win Friends and Influence People</a></em></p>
</div>
<ul class="meta">
<li>
Tags: <a href="http://sami.samhuri.net/tags/life">life</a>&nbsp;<a href="http://sami.samhuri.net/tags/people">people</a>&nbsp;
</li>
<li>
Meta:
<a href="http://sami.samhuri.net/2007/7/12/poeple">0 comments</a>,
<a href="http://sami.samhuri.net/2007/7/12/poeple">permalink</a>
</li>
</ul>
</div>
<div class="hentry" id="article-133">
<h2 class="entry-title">
<a href="http://sami.samhuri.net/2007/7/6/see-your-regular-expressions-in-emacs">See your regular expressions in Emacs</a>
<span class="comment_count">0</span>
</h2>
<div class="vcard">
Posted by <span class="fn">sjs</span>
</div>
<abbr class="published" title="2007-07-06T16:45:00+00:00">on Friday, July 06</abbr>
<br class="clear" />
<div class="entry-content">
<p>First, if you are an Emacs newbie then be sure to read (at least) the introduction of <a href="http://stuff.mit.edu/iap/emacs">Being Productive with Emacs</a>. For some reason the PDF and HTML versions are slightly similar.</p>
<p>Anyway, it mentions <code>re-builder</code> which is an awesome little gem if you use regular expressions at all<sup><a href="http://sami.samhuri.net/#fn1">1</a></sup>. What this baby does is open a small window at the bottom of your screen in which you can type a regex. It is parsed as you type it and matches are highlighted in the other window. Genius.</p>
<p>[1] If you don't use them I encourage you to "learn them"http://regex.info/. Don't pay any attention to <a href="http://regex.info/blog/2006-09-15/247">Jamie Zawinsky</a> and his lack of appreciation for a fantastic tool.</p>
</div>
<ul class="meta">
<li>
Tags: <a href="http://sami.samhuri.net/tags/emacs">emacs</a>&nbsp;<a href="http://sami.samhuri.net/tags/regex">regex</a>&nbsp;
</li>
<li>
Meta:
<a href="http://sami.samhuri.net/2007/7/6/see-your-regular-expressions-in-emacs">0 comments</a>,
<a href="http://sami.samhuri.net/2007/7/6/see-your-regular-expressions-in-emacs">permalink</a>
</li>
</ul>
</div>
<div class="hentry" id="article-128">
<h2 class="entry-title">
<a href="http://sami.samhuri.net/2007/7/6/rushcheck-quickcheck-for-ruby">RushCheck: QuickCheck for Ruby</a>
<span class="comment_count">0</span>
</h2>
<div class="vcard">
Posted by <span class="fn">sjs</span>
</div>
<abbr class="published" title="2007-07-05T19:50:00+00:00">on Thursday, July 05</abbr>
<br class="clear" />
<div class="entry-content">
<p>I cannot wait to try out <a href="http://rushcheck.rubyforge.org/about.html">RushCheck</a>. It is <a href="http://www.cs.chalmers.se/~rjmh/QuickCheck/">QuickCheck</a> for Ruby. I don't have experience with QuickCheck or anything but it's clear to see how this helps you make certain your code is robust.</p>
</div>
<ul class="meta">
<li>
Tags: <a href="http://sami.samhuri.net/tags/quickcheck">quickcheck</a>&nbsp;<a href="http://sami.samhuri.net/tags/ruby">ruby</a>&nbsp;<a href="http://sami.samhuri.net/tags/rushcheck">rushcheck</a>&nbsp;
</li>
<li>
Meta:
<a href="http://sami.samhuri.net/2007/7/6/rushcheck-quickcheck-for-ruby">0 comments</a>,
<a href="http://sami.samhuri.net/2007/7/6/rushcheck-quickcheck-for-ruby">permalink</a>
</li>
</ul>
</div>
<div class="hentry" id="article-120">
<h2 class="entry-title">
<a href="http://sami.samhuri.net/2007/7/3/a-textmate-tip-for-emacs-users">A TextMate tip for Emacs users</a>
<span class="comment_count">0</span>
</h2>
<div class="vcard">
Posted by <span class="fn">sjs</span>
</div>
<abbr class="published" title="2007-07-03T16:45:00+00:00">on Tuesday, July 03</abbr>
<br class="clear" />
<div class="entry-content">
<p><em>Update: The only place I've seen this mentioned is in a <a href="http://macromates.com/blog/2005/screencast/#comment-660">comment</a> on the MacroMates blog.</em></p>
<p>My Linux box is down due to a hardware failure; a cheap SATA controller to be specific. Perhaps that will be a story for another day. As a result I've been working on my MacBook and back in TextMate. Old habits. And I haven't gotten comfortable in any of the OS X Emacsen yet.</p>
<p>This gave me an opportunity to accidentally discover some shortcuts in TextMate. A result of the Emacs shortcuts that my fingers are already wired to, here are some TextMate keyboard shortcuts that may or may not be <a href="http://macromates.com/textmate/manual/">documented</a> (I need to RTFM some day).</p>
<ul>
<li>As in most Cocoa text areas, <code>C-f</code>, <code>C-b</code>, <code>C-n</code>, <code>C-p</code>, <code>C-a</code>, <code>C-e</code>, and <code>C-t</code> work as expected (and others I'm sure).</li>
<li><code>C-k</code>: behaves as a vanilla Emacs, killing till a newline or killing a bare newline. I use the word killing specifically because you can yank it back with...</li>
<li><code>C-y</code>: yanks back the last thing on the kill ring (paste history). You still have to use <code>C-S-v</code> to yank previous items.</li>
</ul>
<p>I think TextMate may have helped ease me into Emacs without me even knowing. I had my suspicions that Allan was an Emacs fan and now I'm certain of it. I keep finding things in one that the other has, which makes switching between them easy. Well done Allan.</p>
</div>
<ul class="meta">
<li>
Tags: <a href="http://sami.samhuri.net/tags/emacs">emacs</a>&nbsp;<a href="http://sami.samhuri.net/tags/keyboard%20shortcuts">keyboard shortcuts</a>&nbsp;<a href="http://sami.samhuri.net/tags/textmate">textmate</a>&nbsp;
</li>
<li>
Meta:
<a href="http://sami.samhuri.net/2007/7/3/a-textmate-tip-for-emacs-users">0 comments</a>,
<a href="http://sami.samhuri.net/2007/7/3/a-textmate-tip-for-emacs-users">permalink</a>
</li>
</ul>
</div>
<div class="hentry" id="article-115">
<h2 class="entry-title">
<a href="http://sami.samhuri.net/2007/7/1/controlling-volume-via-the-keyboard-on-linux">Controlling volume via the keyboard on Linux</a>
<span class="comment_count">0</span>
</h2>
<div class="vcard">
Posted by <span class="fn">sjs</span>
</div>
<abbr class="published" title="2007-06-30T23:13:00+00:00">on Saturday, June 30</abbr>
<br class="clear" />
<div class="entry-content">
<p>I was using Amarok's global keyboard shortcuts to control the volume of my music via the <a href="http://pfuca-store.stores.yahoo.net/haphackeylit1.html">keyboard</a> but I wanted to control the system volume as well. A quick script later and now I can control both, and thanks to libnotify I get some feedback on what happened. It's not as pretty as OS X's volume control or <a href="http://growl.info/">Growl</a> but it'll certainly do.</p>
<p><a href="http://sami.samhuri.net/assets/2007/7/1/volume.rb">&darr; Download volume.rb</a></p>
<p>I save this as <strong>~/bin/volume</strong> and call it thusly: <code>volume +</code> and <code>volume -</code>. I bind Alt-+ and Alt&#8212;to those in my fluxbox config. If you don't have a preferred key binding program I recommend trying <a href="http://hocwp.free.fr/xbindkeys/xbindkeys.html">xbindkeys</a>. apt-get install, emerge, paludis -i, or rpm -i as needed.</p>
</div>
<ul class="meta">
<li>
Tags: <a href="http://sami.samhuri.net/tags/alsa">alsa</a>&nbsp;<a href="http://sami.samhuri.net/tags/linux">linux</a>&nbsp;<a href="http://sami.samhuri.net/tags/ruby">ruby</a>&nbsp;<a href="http://sami.samhuri.net/tags/volume">volume</a>&nbsp;
</li>
<li>
Meta:
<a href="http://sami.samhuri.net/2007/7/1/controlling-volume-via-the-keyboard-on-linux">0 comments</a>,
<a href="http://sami.samhuri.net/2007/7/1/controlling-volume-via-the-keyboard-on-linux">permalink</a>
</li>
</ul>
</div>
<div class="hentry" id="article-112">
<h2 class="entry-title">
<a href="http://sami.samhuri.net/2007/6/29/recent-ruby-and-rails-regales">Recent Ruby and Rails Regales</a>
<span class="comment_count">0</span>
</h2>
<div class="vcard">
Posted by <span class="fn">sjs</span>
</div>
<abbr class="published" title="2007-06-28T19:23:00+00:00">on Thursday, June 28</abbr>
<br class="clear" />
<div class="entry-content">
<p>Some cool Ruby and [the former on] Rails things are springing up and I haven't written much about the two Rs lately, though I work with them daily.</p>
<h3>Rails on Rules</h3>
<p>My friend <a href="http://jim.roepcke.com/">Jim Roepcke</a> is researching and implementing a plugin/framework designed to work with Rails called <a href="http://willingtofail.com/research/rules/index.html">Rails on Rules</a>. His inspiration is <a href="http://developer.apple.com/documentation/WebObjects/Developing_With_D2W/Architecture/chapter_3_section_13.html">the rule system</a> from <a href="http://developer.apple.com/documentation/WebObjects/WebObjects_Overview/index.html">WebObjects'</a> <a href="http://developer.apple.com/documentation/WebObjects/Developing_With_D2W/Introduction/chapter_1_section_1.html">Direct to Web</a>. He posted a good <a href="http://willingtofail.com/research/rules/example.html">example</a> for me, but this baby isn't just for template/view logic. If some of the Rails conventions were specified in a default set of rules which the developer could further customize then you basically have a nice way of doing things that you would otherwise code by hand. I think it would be a boon for the <a href="http://activescaffold.com/">ActiveScaffold</a> project. We're meeting up to talk about this soon and I'll have more to say after then, but it sounds pretty cool.</p>
<h3>Sake Bomb!</h3>
<p>I've noticed a trend among some <a href="http://www.railsenvy.com/2007/6/11/ruby-on-rails-rake-tutorial">recent posts</a> about Rake: the authors keep talking about booze. Are we nothing but a bunch of booze hounds?! Well one can hope. There's some motivation to learn more about a tool, having more time to drink after work. This week <a href="http://ozmm.org/">Chris Wanstrath</a> dropped a <a href="http://errtheblog.com/post/6069">Sake Bomb</a> on the Ruby community. Like piston, sake is something you can just pick up and use instantly. Interestingly the different pronunciations of <code>rake</code> and <code>sake</code> help me from confusing the two on the command line... so far.</p>
<h3>Secure Associations (for Rails)</h3>
<p><a href="http://tuples.us/">Jordan McKible</a> released the <a href="http://tuples.us/2007/06/28/secure_associations-plugin-gets-some-love/">secure_associations</a> plugin. It lets you protect your models' *_id attributes from mass-assignment via <code>belongs_to_protected</code> and <code>has_many_protected</code>. It's a mild enhancement, but an enhancement nonetheless. This is useful to enough people that it should be in Rails proper.</p>
<h3>Regular expressions and strings with embedded objects</h3>
<p><a href="http://t-a-w.blogspot.com/">taw</a> taught me a <a href="http://t-a-w.blogspot.com/2007/06/regular-expressions-and-strings-with.html">new technique for simplifying regular expressions</a> by transforming the text in a reversible manner. In one example he replaced literal strings in SQL - which are easily parsed via a regex - with what he calls embedded objects. They're just tokens to identify the temporarily removed strings, but the important thing is that they don't interfere with the regexes that operate on the other parts of the SQL, which would have been very difficult to get right with the strings inside it. If I made it sound complicated just read the post, he explains it well.</p>
<p>If you believe anything <a href="http://steve-yegge.blogspot.com/2007/06/rich-programmer-food.html">Steve Yegge</a> says then that last regex trick may come in handy for Q&#38;D parsing in any language, be it Ruby, NBL, or whataver.</p>
</div>
<ul class="meta">
<li>
Tags: <a href="http://sami.samhuri.net/tags/rails">rails</a>&nbsp;<a href="http://sami.samhuri.net/tags/rails%20on%20rules">rails on rules</a>&nbsp;<a href="http://sami.samhuri.net/tags/regular%20expressions">regular expressions</a>&nbsp;<a href="http://sami.samhuri.net/tags/ruby">ruby</a>&nbsp;<a href="http://sami.samhuri.net/tags/sake">sake</a>&nbsp;<a href="http://sami.samhuri.net/tags/secure%20associations">secure associations</a>&nbsp;
</li>
<li>
Meta:
<a href="http://sami.samhuri.net/2007/6/29/recent-ruby-and-rails-regales">0 comments</a>,
<a href="http://sami.samhuri.net/2007/6/29/recent-ruby-and-rails-regales">permalink</a>
</li>
</ul>
</div>
<div class="hentry" id="article-110">
<h2 class="entry-title">
<a href="http://sami.samhuri.net/2007/6/26/emacs-tagify-region-or-insert-tag">Emacs: tagify-region-or-insert-tag</a>
<span class="comment_count">1</span>
</h2>
<div class="vcard">
Posted by <span class="fn">sjs</span>
</div>
<abbr class="published" title="2007-06-25T22:13:00+00:00">on Monday, June 25</abbr>
<br class="clear" />
<div class="entry-content">
<p>After <a href="http://sami.samhuri.net/2007/6/26/rtfm">axing</a> half of <a href="http://sami.samhuri.net/2007/6/23/emacs-for-textmate-junkies">wrap-region.el</a> I renamed it to <a href="http://sami.samhuri.net/assets/2007/6/26/tagify.el">tagify.el</a> and improved it ever so slightly. It's leaner, and does more!</p>
<p><code>tagify-region-or-insert-tag</code> does the same thing as <code>wrap-region-with-tag</code> except if there is no region it now inserts the opening and closing tags and sets point in between them. I have this bound to <code>C-z t</code>, as I use <code>C-z</code> as my personal command prefix.</p>
<p><code>&lt;</code> is bound to <code>tagify-region-or-insert-self</code> which really doesn't warrant an explanation.</p>
</div>
<ul class="meta">
<li>
Tags: <a href="http://sami.samhuri.net/tags/emacs">emacs</a>&nbsp;<a href="http://sami.samhuri.net/tags/tagify">tagify</a>&nbsp;
</li>
<li>
Meta:
<a href="http://sami.samhuri.net/2007/6/26/emacs-tagify-region-or-insert-tag">1 comment</a>,
<a href="http://sami.samhuri.net/2007/6/26/emacs-tagify-region-or-insert-tag">permalink</a>
</li>
</ul>
</div>
<div class="hentry" id="article-109">
<h2 class="entry-title">
<a href="http://sami.samhuri.net/2007/6/26/rtfm">RTFM!</a>
<span class="comment_count">0</span>
</h2>
<div class="vcard">
Posted by <span class="fn">sjs</span>
</div>
<abbr class="published" title="2007-06-25T21:19:00+00:00">on Monday, June 25</abbr>
<br class="clear" />
<div class="entry-content">
<p>I should read the Emacs manual sometime, especially since I have it in dead-tree form. Check out <a href="http://www.gnu.org/software/emacs/manual/html_node/autotype/Inserting-Pairs.html">skeleton pairs</a> in the Emacs manual, or better yet <code>C-h f skeleton-pair-insert-maybe</code>. skeleton-pair has already been massaged to do what you most likely want if you set the correct options. Cool. I like Emacs more every day.</p>
<p>This renders <a href="http://sami.samhuri.net/2007/6/23/emacs-for-textmate-junkies">wrap-region</a> useless, which is great! I like a trim .emacs and .emacs.d.</p>
</div>
<ul class="meta">
<li>
Tags: <a href="http://sami.samhuri.net/tags/emacs">emacs</a>&nbsp;<a href="http://sami.samhuri.net/tags/rtfm">rtfm</a>&nbsp;
</li>
<li>
Meta:
<a href="http://sami.samhuri.net/2007/6/26/rtfm">0 comments</a>,
<a href="http://sami.samhuri.net/2007/6/26/rtfm">permalink</a>
</li>
</ul>
</div>
<div class="hentry" id="article-107">
<h2 class="entry-title">
<a href="http://sami.samhuri.net/2007/6/25/propaganda-makes-me-sick">Propaganda makes me sick</a>
<span class="comment_count">0</span>
</h2>
<div class="vcard">
Posted by <span class="fn">sjs</span>
</div>
<abbr class="published" title="2007-06-25T10:55:00+00:00">on Monday, June 25</abbr>
<br class="clear" />
<div class="entry-content">
<p>Things <a href="http://arstechnica.com/news.ars/post/20070625-spying-on-campus-fbi-warns-mit-harvard.html">like this</a> in modern times are surprising. Can't people spot this phony crap for what it is?</p>
<p><tt>First they put away the dealers, keep our kids safe and off the streets<br/>
Then they put away the prostitutes, keep married men cloistered at home<br/>
Then they shooed away the bums, and they beat and bashed the queers<br/>
Turned away asylum-seekers, fed us suspicions and fears<br/>
We didn't raise our voice, we didn't make a fuss<br/>
It´s funny there was no one left to notice, when they came for us<br/>
<br/>
<strong>Looks like witches are in season, you better fly your flag and be aware<br/>
Of anyone who might fit the description, diversity is now our biggest fear<br/>
Now with our conversations tapped, and our differences exposed<br/>
How ya supposed to love your neighbour, with our minds and curtains
closed?<br/>
We used to worry &#8216;bout big brother<br/>
Now we got a big father and an even bigger mother</strong><br/>
<br/>
And still you believe, this aristocracy gives a fuck about you<br/>
They put the mock in democracy, and you swallowed every hook<br/>
The sad truth is, you'd rather follow the school into the net<br/>
&#8216;Cause swimming alone at sea, is not the kind of freedom that you
actually want<br/>
So go back to your crib, and suck on a tit<br/>
Bask in the warmth of your diaper, you're sitting in shit<br/>
And piss, while sucking on a giant pacifier<br/>
A country of adult infants, a legion of mental midgets<br/>
A country of adult infants, a country of adult infants<br/>
All regaining their unconsciousness<br/>
</tt>
&#8212;from the song <a href="http://www.nofxwiki.net/w/Lyrics:Regaining_Unconsciousness_%28song%29">Regaining Unconsciousness</a>, by <a href="http://www.nofx.org/">NOFX</a></p>
</div>
<ul class="meta">
<li>
Tags: <a href="http://sami.samhuri.net/tags/propaganda">propaganda</a>&nbsp;
</li>
<li>
Meta:
<a href="http://sami.samhuri.net/2007/6/25/propaganda-makes-me-sick">0 comments</a>,
<a href="http://sami.samhuri.net/2007/6/25/propaganda-makes-me-sick">permalink</a>
</li>
</ul>
</div>
<div class="hentry" id="article-101">
<h2 class="entry-title">
<a href="http://sami.samhuri.net/2007/6/25/floating-point-in-elschemo">Floating point in ElSchemo</a>
<span class="comment_count">0</span>
</h2>
<div class="vcard">
Posted by <span class="fn">sjs</span>
</div>
<abbr class="published" title="2007-06-24T18:53:00+00:00">on Sunday, June 24</abbr>
<br class="clear" />
<div class="entry-content">
<p><em>Update: I've cleaned the code up a little bit by having LispNum derive Eq, Ord and Show.</em></p>
<p><em>NB: My Scheme interpreter is based on Jonathan Tang's <a href="http://halogen.note.amherst.edu/~jdtang/scheme_in_48/tutorial/firststeps.html">Write Yourself a Scheme in 48 hours</a> Haskell tutorial. Not all of this makes sense outside that context, and the context of my previous posts on the subject.</em></p>
<p>My <a href="http://sami.samhuri.net/2007/06/14/more-scheming-with-haskell">scheme interpreter</a> has been christened ElSchemo, since it was sorely in need of a better name than "my Scheme interpreter". It's also seen far too much of my time and sports jazzy new features. I'll probably post the full code up here sooner or later, including my stdlib.scm and <a href="http://cubiclemuses.com/cm/blog/tags/Misp">misp</a> slightly modified to run with ElSchemo's limited vocabulary (namely the lack of <code>define-syntax</code>).</p>
<p>But that will be for another day, because today I want to talk about implementing floating point numbers, from parsing to operating on them.</p>
<div class="extended">
<p><a href="http://sami.samhuri.net/2007/6/25/floating-point-in-elschemo">Continue reading...</a></p>
</div>
</div>
<ul class="meta">
<li>
Tags: <a href="http://sami.samhuri.net/tags/elschemo">elschemo</a>&nbsp;<a href="http://sami.samhuri.net/tags/haskell">haskell</a>&nbsp;<a href="http://sami.samhuri.net/tags/scheme">scheme</a>&nbsp;
</li>
<li>
Meta:
<a href="http://sami.samhuri.net/2007/6/25/floating-point-in-elschemo">0 comments</a>,
<a href="http://sami.samhuri.net/2007/6/25/floating-point-in-elschemo">permalink</a>
</li>
</ul>
</div>
<div class="hentry" id="article-94">
<h2 class="entry-title">
<a href="http://sami.samhuri.net/2007/6/23/emacs-for-textmate-junkies">Emacs for TextMate junkies</a>
<span class="comment_count">6</span>
</h2>
<div class="vcard">
Posted by <span class="fn">sjs</span>
</div>
<abbr class="published" title="2007-06-23T02:17:00+00:00">on Saturday, June 23</abbr>
<br class="clear" />
<div class="entry-content">
<p><em>Update #1: What I first posted will take out your &lt; key by mistake (it's available via <code>C-q &lt;</code>), it has since been revised to Do The Right Thing.</em></p>
<p><em>Update #2: Thanks to an anonymouse[sic] commenter this code is a little cleaner.</em></p>
<p><em>Update #3: I should read the Emacs manual sometime, especially since I have it in dead-tree form. Check out <a href="http://www.gnu.org/software/emacs/manual/html_node/autotype/Inserting-Pairs.html">skeleton pairs</a> in the Emacs manual.</em></p>
<p>Despite my current infatuation with Emacs there are many reasons I started using TextMate, especially little time-savers that are very addictive. I'll talk about one of those features tonight. When you have text selected in TextMate and you hit say the <code>'</code> (single quote) then TextMate will surround the selected text with single quotes. The same goes for double quotes, parentheses, brackets, and braces. This little trick is one of my favourites so I had to come up with something similar in Emacs. It was easy since a <a href="http://osdir.com/ml/emacs.nxml.general/2005-08/msg00002.html">mailing list post</a> has a solution for surrounding the current region with tags, which served as a great starting point.</p>
<table class="CodeRay"><tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }"><pre>1<tt>
</tt>2<tt>
</tt>3<tt>
</tt>4<tt>
</tt>5<tt>
</tt>6<tt>
</tt>7<tt>
</tt></pre></td>
<td class="code"><pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">(defun surround-region-with-tag (tag-name beg end)<tt>
</tt> (interactive &quot;sTag name: \nr&quot;)<tt>
</tt> (save-excursion<tt>
</tt> (goto-char beg)<tt>
</tt> (insert &quot;&lt;&quot; tag-name &quot;&gt;&quot;)<tt>
</tt> (goto-char (+ end 2 (length tag-name)))<tt>
</tt> (insert &quot;&lt;/&quot; tag-name &quot;&gt;&quot;)))</pre></td>
</tr></table>
<p>With a little modification I now have the following in my ~/.emacs file:</p>
<table class="CodeRay"><tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }"><pre>1<tt>
</tt>2<tt>
</tt>3<tt>
</tt>4<tt>
</tt>5<tt>
</tt>6<tt>
</tt>7<tt>
</tt>8<tt>
</tt>9<tt>
</tt><strong>10</strong><tt>
</tt>11<tt>
</tt>12<tt>
</tt>13<tt>
</tt>14<tt>
</tt>15<tt>
</tt>16<tt>
</tt>17<tt>
</tt>18<tt>
</tt>19<tt>
</tt><strong>20</strong><tt>
</tt>21<tt>
</tt>22<tt>
</tt>23<tt>
</tt>24<tt>
</tt>25<tt>
</tt>26<tt>
</tt>27<tt>
</tt>28<tt>
</tt>29<tt>
</tt><strong>30</strong><tt>
</tt>31<tt>
</tt>32<tt>
</tt>33<tt>
</tt>34<tt>
</tt>35<tt>
</tt>36<tt>
</tt>37<tt>
</tt>38<tt>
</tt>39<tt>
</tt><strong>40</strong><tt>
</tt>41<tt>
</tt>42<tt>
</tt>43<tt>
</tt>44<tt>
</tt>45<tt>
</tt>46<tt>
</tt>47<tt>
</tt></pre></td>
<td class="code"><pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">;; help out a TextMate junkie<tt>
</tt><tt>
</tt>(defun wrap-region (left right beg end)<tt>
</tt> &quot;Wrap the region in arbitrary text, LEFT goes to the left and RIGHT goes to the right.&quot;<tt>
</tt> (interactive)<tt>
</tt> (save-excursion<tt>
</tt> (goto-char beg)<tt>
</tt> (insert left)<tt>
</tt> (goto-char (+ end (length left)))<tt>
</tt> (insert right)))<tt>
</tt><tt>
</tt>(defmacro wrap-region-with-function (left right)<tt>
</tt> &quot;Returns a function which, when called, will interactively `wrap-region-or-insert' using LEFT and RIGHT.&quot;<tt>
</tt> `(lambda () (interactive)<tt>
</tt> (wrap-region-or-insert ,left ,right)))<tt>
</tt><tt>
</tt>(defun wrap-region-with-tag-or-insert ()<tt>
</tt> (interactive)<tt>
</tt> (if (and mark-active transient-mark-mode)<tt>
</tt> (call-interactively 'wrap-region-with-tag)<tt>
</tt> (insert &quot;&lt;&quot;)))<tt>
</tt><tt>
</tt>(defun wrap-region-with-tag (tag beg end)<tt>
</tt> &quot;Wrap the region in the given HTML/XML tag using `wrap-region'. If any<tt>
</tt>attributes are specified then they are only included in the opening tag.&quot;<tt>
</tt> (interactive &quot;*sTag (including attributes): \nr&quot;)<tt>
</tt> (let* ((elems (split-string tag &quot; &quot;))<tt>
</tt> (tag-name (car elems))<tt>
</tt> (right (concat &quot;&lt;/&quot; tag-name &quot;&gt;&quot;)))<tt>
</tt> (if (= 1 (length elems))<tt>
</tt> (wrap-region (concat &quot;&lt;&quot; tag-name &quot;&gt;&quot;) right beg end)<tt>
</tt> (wrap-region (concat &quot;&lt;&quot; tag &quot;&gt;&quot;) right beg end))))<tt>
</tt><tt>
</tt>(defun wrap-region-or-insert (left right)<tt>
</tt> &quot;Wrap the region with `wrap-region' if an active region is marked, otherwise insert LEFT at point.&quot;<tt>
</tt> (interactive)<tt>
</tt> (if (and mark-active transient-mark-mode)<tt>
</tt> (wrap-region left right (region-beginning) (region-end))<tt>
</tt> (insert left)))<tt>
</tt><tt>
</tt>(global-set-key &quot;'&quot; (wrap-region-with-function &quot;'&quot; &quot;'&quot;))<tt>
</tt>(global-set-key &quot;\&quot;&quot; (wrap-region-with-function &quot;\&quot;&quot; &quot;\&quot;&quot;))<tt>
</tt>(global-set-key &quot;`&quot; (wrap-region-with-function &quot;`&quot; &quot;`&quot;))<tt>
</tt>(global-set-key &quot;(&quot; (wrap-region-with-function &quot;(&quot; &quot;)&quot;))<tt>
</tt>(global-set-key &quot;[&quot; (wrap-region-with-function &quot;[&quot; &quot;]&quot;))<tt>
</tt>(global-set-key &quot;{&quot; (wrap-region-with-function &quot;{&quot; &quot;}&quot;))<tt>
</tt>(global-set-key &quot;&lt;&quot; 'wrap-region-with-tag-or-insert) ;; I opted not to have a wrap-with-angle-brackets</pre></td>
</tr></table>
<p><a href="http://sami.samhuri.net/assets/2007/6/23/wrap-region.el" alt="wrap-region.el">Download wrap-region.el</a></p>
<p>That more or less sums up why I like Emacs so much. I wanted that functionality so I implemented it (barely! It was basically done for me), debugged it by immediately evaluating sexps and then trying it out, and then once it worked I reloaded my config and used the wanted feature. That's just awesome, and shows one strength of open source.</p>
</div>
<ul class="meta">
<li>
Tags: <a href="http://sami.samhuri.net/tags/emacs">emacs</a>&nbsp;<a href="http://sami.samhuri.net/tags/textmate">textmate</a>&nbsp;
</li>
<li>
Meta:
<a href="http://sami.samhuri.net/2007/6/23/emacs-for-textmate-junkies">6 comments</a>,
<a href="http://sami.samhuri.net/2007/6/23/emacs-for-textmate-junkies">permalink</a>
</li>
</ul>
</div>
<div class="hentry" id="article-92">
<h2 class="entry-title">
<a href="http://sami.samhuri.net/2007/6/22/embrace-the-database">Embrace the database</a>
<span class="comment_count">0</span>
</h2>
<div class="vcard">
Posted by <span class="fn">sjs</span>
</div>
<abbr class="published" title="2007-06-22T10:14:00+00:00">on Friday, June 22</abbr>
<br class="clear" />
<div class="entry-content">
<p>If you drink the Rails koolaid you may have read the notorious <a href="http://www.loudthinking.com/arc/2005_09.html">single layer of cleverness</a> post by <a href="http://www.loudthinking.com/">DHH</a>. <em>[5th post on the archive page]</em> In a nutshell he states that it's better to have a single point of cleverness when it comes to business logic. The reasons for this include staying agile, staying in Ruby all the time, and being able to switch the back-end DB at any time. Put the logic in ActiveRecord and use the DB as a dumb data store, that is the Rails way. It's simple. It works. You don't need to be a DBA to be a Rails developer.</p>
<p><a href="http://www.stephenbartholomew.co.uk/">Stephen</a> created a Rails plugin called <a href="http://www.stephenbartholomew.co.uk/2007/6/22/dependent-raise">dependent-raise</a> which imitates a foreign key constraint inside of Rails. I want to try this out because I believe that data integrity is fairly important, but it's really starting to make me think about this single point of cleverness idea.</p>
<p>Are we not reinventing the wheel by employing methods such as this in our code? Capable DBs already do this sort of thing for us. I don't necessarily think it's bad to implement this sort of thing, but I think it's a symptom of NIH syndrome. Instead of reinventing this kind of thing why don't we embrace the DB as a semi-intelligent data store? The work has been done all we have to do is exploit it via Rails.</p>
<p>There are a few reasons that the Rails folks choose not to do so but perhaps some of them could be worked around. Adapting your solution as you progress and realise that things aren't exactly as you thought they were... I believe the word for that sort of thing is agility.</p>
<h3>Database agnosticism</h3>
<p>From SQLite to Oracle, just configure the connection, migrate, and run your app on any database. One of the biggest Rails myths that is backed by the Rails team themselves. It takes a fair amount of work to ensure that any significant app is fully agnostic. Sure you can develop on SQLite and deploy on MySQL without much trouble but there are significant diffirences between RDBMSs that will manifest themselves if you create an app that's more than a toy. Oh, you used finder_sql? Sorry but chances are your app is no longer DB agnostic. FAIL.</p>
<p><strong>Solution:</strong> Drop the lie. Tell people the truth. Theoretically, theory and practice are the same; in practice they are not. Be honest that it's <em>possible</em> to be DB-agnostic but can be a challenge. Under no circumstances should we shun something useful in the name of claiming to be DB-agnostic.</p>
<h3>Staying agile</h3>
<p>If we start making use of FK constraints then we'll have to make changes to both our DB and our code. This makes change more time-consuming and error-prone which means change is less likely to happen. This goes against the grain of an agile methodology. Or does it?</p>
<p><strong>Solution:</strong> Rails should use the features of the DB to keep data intact and fall back on an AR-only solution only if the DB doesn't support the operation. There doesn't need to be any duplication in logic rules either. If Rails could recognise a FK constraint that cascades on delete it could set up the <code>has_many :foos, :dependent =&gt; :destroy</code> relation for us. In fact I only see our code becoming DRYer (maybe even too DRY[1]).</p>
<h3>Staying in Ruby</h3>
<p>Using the DB from within Ruby is a solved problem. I don't see why this couldn't be extended to handle more of the DB as well. Use Ruby, but use it intelligently by embracing outside tools to get the job done.</p>
<p>Many relationships could be derived from constraints as people have pointed out before. There are benefits to using the features of a decent RDBMS, and in some cases I think that we might be losing by not making use of them. I am not saying we should move everything to the DB, I am saying that we should exploit the implemented and debugged capabilities of our RDBMSs the best we can while practicing the agile methods we know and love, all from within Ruby.</p>
<p>[1] I make liberal use of <a href="http://agilewebdevelopment.com/plugins/annotate_models">annotate_models</a> as it is.</p>
</div>
<ul class="meta">
<li>
Tags: <a href="http://sami.samhuri.net/tags/activerecord">activerecord</a>&nbsp;<a href="http://sami.samhuri.net/tags/rails">rails</a>&nbsp;<a href="http://sami.samhuri.net/tags/ruby">ruby</a>&nbsp;
</li>
<li>
Meta:
<a href="http://sami.samhuri.net/2007/6/22/embrace-the-database">0 comments</a>,
<a href="http://sami.samhuri.net/2007/6/22/embrace-the-database">permalink</a>
</li>
</ul>
</div>
</div>
<div id="sidebar">
<div class="sidebar-node">
<div id="search" class="search">
<form action="http://sami.samhuri.net/search" id="sform" method="get" name="sform">
<p><input type="text" id="q" name="q" value="" /></p>
</form>
</div>
</div>
<div class="sidebar-node">
<h3>Archives</h3>
<ul>
<li><a href="http://sami.samhuri.net/archives/2007/8">August 2007</a> (3)</li>
<li><a href="http://sami.samhuri.net/archives/2007/7">July 2007</a> (5)</li>
<li><a href="http://sami.samhuri.net/archives/2007/6">June 2007</a> (14)</li>
<li><a href="http://sami.samhuri.net/archives/2007/5">May 2007</a> (15)</li>
<li><a href="http://sami.samhuri.net/archives/2007/4">April 2007</a> (5)</li>
<li><a href="http://sami.samhuri.net/archives/2007/3">March 2007</a> (5)</li>
<li><a href="http://sami.samhuri.net/archives/2007/2">February 2007</a> (0)</li>
<li><a href="http://sami.samhuri.net/archives/2007/1">January 2007</a> (0)</li>
<li><a href="http://sami.samhuri.net/archives/2006/12">December 2006</a> (1)</li>
<li><a href="http://sami.samhuri.net/archives/2006/11">November 2006</a> (0)</li>
<li><a href="http://sami.samhuri.net/archives/2006/10">October 2006</a> (0)</li>
<li><a href="http://sami.samhuri.net/archives/2006/9">September 2006</a> (1)</li>
<li><a href="http://sami.samhuri.net/archives/2006/8">August 2006</a> (0)</li>
<li><a href="http://sami.samhuri.net/archives/2006/7">July 2006</a> (5)</li>
<li><a href="http://sami.samhuri.net/archives/2006/6">June 2006</a> (4)</li>
<li><a href="http://sami.samhuri.net/archives/2006/5">May 2006</a> (2)</li>
<li><a href="http://sami.samhuri.net/archives/2006/4">April 2006</a> (1)</li>
<li><a href="http://sami.samhuri.net/archives/2006/3">March 2006</a> (3)</li>
<li><a href="http://sami.samhuri.net/archives/2006/2">February 2006</a> (11)</li>
</ul>
</div>
<div class="sidebar-node">
<h3>Sections</h3>
<ul>
<li><a href="http://sami.samhuri.net/">geeky ramblings</a> (15)</li>
<li><a href="http://sami.samhuri.net/emacs">Emacs</a> (2)</li>
</ul>
</div>
<div class="sidebar-node">
<h3>Tags</h3>
<ul>
<li><a href="http://sami.samhuri.net/tags/activerecord">activerecord</a> (2)</li>
<li><a href="http://sami.samhuri.net/tags/alsa">alsa</a> (1)</li>
<li><a href="http://sami.samhuri.net/tags/amusement">amusement</a> (6)</li>
<li><a href="http://sami.samhuri.net/tags/apple">apple</a> (7)</li>
<li><a href="http://sami.samhuri.net/tags/bdd">bdd</a> (1)</li>
<li><a href="http://sami.samhuri.net/tags/bootcamp">bootcamp</a> (1)</li>
<li><a href="http://sami.samhuri.net/tags/buffalo">buffalo</a> (1)</li>
<li><a href="http://sami.samhuri.net/tags/bundle">bundle</a> (1)</li>
<li><a href="http://sami.samhuri.net/tags/cheat">cheat</a> (2)</li>
<li><a href="http://sami.samhuri.net/tags/cheat%20sheet">cheat sheet</a> (1)</li>
<li><a href="http://sami.samhuri.net/tags/coding">coding</a> (22)</li>
<li><a href="http://sami.samhuri.net/tags/cool">cool</a> (1)</li>
<li><a href="http://sami.samhuri.net/tags/coverflow">coverflow</a> (1)</li>
<li><a href="http://sami.samhuri.net/tags/crazy">crazy</a> (2)</li>
<li><a href="http://sami.samhuri.net/tags/digg">digg</a> (2)</li>
<li><a href="http://sami.samhuri.net/tags/drm">drm</a> (1)</li>
<li><a href="http://sami.samhuri.net/tags/dtrace">dtrace</a> (1)</li>
<li><a href="http://sami.samhuri.net/tags/elschemo">elschemo</a> (2)</li>
<li><a href="http://sami.samhuri.net/tags/emacs">emacs</a> (10)</li>
<li><a href="http://sami.samhuri.net/tags/english">english</a> (1)</li>
<li><a href="http://sami.samhuri.net/tags/extensions">extensions</a> (1)</li>
<li><a href="http://sami.samhuri.net/tags/firefox">firefox</a> (2)</li>
<li><a href="http://sami.samhuri.net/tags/framework">framework</a> (2)</li>
<li><a href="http://sami.samhuri.net/tags/funny">funny</a> (2)</li>
<li><a href="http://sami.samhuri.net/tags/fuse">fuse</a> (1)</li>
<li><a href="http://sami.samhuri.net/tags/games">games</a> (1)</li>
<li><a href="http://sami.samhuri.net/tags/gentoo">gentoo</a> (1)</li>
<li><a href="http://sami.samhuri.net/tags/german">german</a> (1)</li>
<li><a href="http://sami.samhuri.net/tags/haskell">haskell</a> (7)</li>
<li><a href="http://sami.samhuri.net/tags/humans">humans</a> (1)</li>
<li><a href="http://sami.samhuri.net/tags/injury">injury</a> (1)</li>
<li><a href="http://sami.samhuri.net/tags/inspirado">inspirado</a> (1)</li>
<li><a href="http://sami.samhuri.net/tags/iphone">iphone</a> (1)</li>
<li><a href="http://sami.samhuri.net/tags/itunes">itunes</a> (1)</li>
<li><a href="http://sami.samhuri.net/tags/i_laughed_i_cried">i_laughed_i_cried</a> (1)</li>
<li><a href="http://sami.samhuri.net/tags/keyboard">keyboard</a> (1)</li>
<li><a href="http://sami.samhuri.net/tags/keyboard%20shortcuts">keyboard shortcuts</a> (1)</li>
<li><a href="http://sami.samhuri.net/tags/life">life</a> (11)</li>
<li><a href="http://sami.samhuri.net/tags/linux">linux</a> (6)</li>
<li><a href="http://sami.samhuri.net/tags/mac%20os%20x">mac os x</a> (7)</li>
<li><a href="http://sami.samhuri.net/tags/mediawiki">mediawiki</a> (1)</li>
<li><a href="http://sami.samhuri.net/tags/mephisto">mephisto</a> (1)</li>
<li><a href="http://sami.samhuri.net/tags/migrations">migrations</a> (2)</li>
<li><a href="http://sami.samhuri.net/tags/munich">munich</a> (1)</li>
<li><a href="http://sami.samhuri.net/tags/mysql">mysql</a> (1)</li>
<li><a href="http://sami.samhuri.net/tags/networking">networking</a> (1)</li>
<li><a href="http://sami.samhuri.net/tags/parallels">parallels</a> (1)</li>
<li><a href="http://sami.samhuri.net/tags/pedantry">pedantry</a> (1)</li>
<li><a href="http://sami.samhuri.net/tags/people">people</a> (1)</li>
<li><a href="http://sami.samhuri.net/tags/photo">photo</a> (1)</li>
<li><a href="http://sami.samhuri.net/tags/php">php</a> (4)</li>
<li><a href="http://sami.samhuri.net/tags/propaganda">propaganda</a> (1)</li>
<li><a href="http://sami.samhuri.net/tags/python">python</a> (1)</li>
<li><a href="http://sami.samhuri.net/tags/quickcheck">quickcheck</a> (1)</li>
<li><a href="http://sami.samhuri.net/tags/rails">rails</a> (18)</li>
<li><a href="http://sami.samhuri.net/tags/rails%20on%20rules">rails on rules</a> (1)</li>
<li><a href="http://sami.samhuri.net/tags/regex">regex</a> (2)</li>
<li><a href="http://sami.samhuri.net/tags/regular%20expressions">regular expressions</a> (1)</li>
<li><a href="http://sami.samhuri.net/tags/rest">rest</a> (1)</li>
<li><a href="http://sami.samhuri.net/tags/rtfm">rtfm</a> (1)</li>
<li><a href="http://sami.samhuri.net/tags/ruby">ruby</a> (12)</li>
<li><a href="http://sami.samhuri.net/tags/rushcheck">rushcheck</a> (1)</li>
<li><a href="http://sami.samhuri.net/tags/sake">sake</a> (1)</li>
<li><a href="http://sami.samhuri.net/tags/scheme">scheme</a> (4)</li>
<li><a href="http://sami.samhuri.net/tags/school">school</a> (1)</li>
<li><a href="http://sami.samhuri.net/tags/seaside">seaside</a> (1)</li>
<li><a href="http://sami.samhuri.net/tags/secure%20associations">secure associations</a> (1)</li>
<li><a href="http://sami.samhuri.net/tags/seekport">seekport</a> (2)</li>
<li><a href="http://sami.samhuri.net/tags/snippets">snippets</a> (3)</li>
<li><a href="http://sami.samhuri.net/tags/tagify">tagify</a> (1)</li>
<li><a href="http://sami.samhuri.net/tags/technology">technology</a> (6)</li>
<li><a href="http://sami.samhuri.net/tags/test/spec">test/spec</a> (1)</li>
<li><a href="http://sami.samhuri.net/tags/textmate">textmate</a> (7)</li>
<li><a href="http://sami.samhuri.net/tags/typo">typo</a> (2)</li>
<li><a href="http://sami.samhuri.net/tags/ubuntu">ubuntu</a> (1)</li>
<li><a href="http://sami.samhuri.net/tags/usability">usability</a> (1)</li>
<li><a href="http://sami.samhuri.net/tags/userscript">userscript</a> (2)</li>
<li><a href="http://sami.samhuri.net/tags/vim">vim</a> (1)</li>
<li><a href="http://sami.samhuri.net/tags/volume">volume</a> (1)</li>
<li><a href="http://sami.samhuri.net/tags/web%20objects">web objects</a> (1)</li>
<li><a href="http://sami.samhuri.net/tags/wikipediafs">wikipediafs</a> (1)</li>
<li><a href="http://sami.samhuri.net/tags/windows">windows</a> (3)</li>
<li><a href="http://sami.samhuri.net/tags/work">work</a> (1)</li>
<li><a href="http://sami.samhuri.net/tags/zend">zend</a> (2)</li>
<li><a href="http://sami.samhuri.net/tags/zsh">zsh</a> (1)</li>
</ul>
</div>
<div class="sidebar-node">
<h3>Friends &amp; cool blogs</h3>
<ul>
<li><a href="http://jim.roepcke.com/">have browser, will travel</a></li>
<li><a href="http://cassandrahill.blogspot.com/">cj's chatter</a></li>
</ul>
</div>
<div class="sidebar-node">
<p><a href="http://twitter.com/_sjs">
<img src="http://web.archive.org/web/20070811125748im_/http://sami.samhuri.net/assets/2007/6/26/icon_twitter.png" alt="[t]" /> twitter</a></p>
</div>
<div class="sidebar-node">
<p><a href="http://mephistoblog.com/" class="powered"><img alt="mephisto-badge-tiny" src="http://web.archive.org/web/20070811125748im_/http://sami.samhuri.net/images/mephisto-badge-tiny.png" /></a></p>
</div>
</div>
<br style="clear:both;" />
</div>
<div id="footer">
<hr />
<p><a href="http://sami.samhuri.net/">sjs</a></p>
<ul>
<li>powered by <a href="http://mephistoblog.com/">Mephisto</a> /
styled with <a href="http://quotedprintable.com/pages/scribbish">scribbish</a></li>
</ul>
</div>
</div>
<script src="http://web.archive.org/web/20070811125748js_/http://www.google-analytics.com/urchin.js" type="text/javascript"> </script>
<script type="text/javascript"> _uacct = "UA-214054-3"; urchinTracker(); </script>
<script src="http://web.archive.org/web/20070811125748js_/http://feeds.feedburner.com/~s/sjs" type="text/javascript" charset="utf-8"></script>
</body>
</html>
<!--
FILE ARCHIVED ON 12:57:48 Aug 11, 2007 AND RETRIEVED FROM THE
INTERNET ARCHIVE ON 2:57:36 Aug 21, 2011.
JAVASCRIPT APPENDED BY WAYBACK MACHINE, COPYRIGHT INTERNET ARCHIVE.
ALL OTHER CONTENT MAY ALSO BE PROTECTED BY COPYRIGHT (17 U.S.C.
SECTION 108(a)(3)).
-->