<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Light Fiction &#187; code</title>
	<atom:link href="http://blog.quodlibetor.com/category/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.quodlibetor.com</link>
	<description>ain't that the truth</description>
	<lastBuildDate>Sun, 30 May 2010 23:44:03 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>emacs, lisp, php, wordcount, and etc.</title>
		<link>http://blog.quodlibetor.com/2008/07/emacs-lisp-php-wordcount-and-etc/</link>
		<comments>http://blog.quodlibetor.com/2008/07/emacs-lisp-php-wordcount-and-etc/#comments</comments>
		<pubDate>Tue, 08 Jul 2008 17:41:37 +0000</pubDate>
		<dc:creator>quodlibetor</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[emacs]]></category>
		<category><![CDATA[lisp]]></category>
		<category><![CDATA[wordcount]]></category>

		<guid isPermaLink="false">http://blog.quodlibetor.com/?p=114</guid>
		<description><![CDATA[Based partially on Steve Yegge&#8217;s advice that you should learn your tools, along with an interest in doing some kind of coding even while being busy with school, I&#8217;ve been working my way through the emacs manual and the emacs-lisp-intro, which latter is highly recommended.
(As an aside, one thing I&#8217;ve been working on has been ]]></description>
			<content:encoded><![CDATA[<p>Based partially on Steve Yegge&#8217;s advice that you should <a title="A good article" href="http://steve.yegge.googlepages.com/practicing-programming">learn your tools</a>, along with an interest in doing some kind of coding even while being busy with school, I&#8217;ve been working my way through the emacs manual and the <a title="a fantastic and fantastically easy intro to elisp" href="http://www.gnu.org/software/emacs/emacs-lisp-intro/">emacs-lisp-intro</a>, which latter is highly recommended.</p>
<p>(As an aside, one thing I&#8217;ve been working on has been learning how to make modes and all the things that would go into that, and because of that I was able to &#8220;fix&#8221; a bug in php-mode, which apparently somebody <a title="bug report biznatch" href="http://code.google.com/p/mewde/issues/detail?id=3">has found useful</a> and thanked me for. First time ever being thanked for fixing code, let me tell you it was really nice and inspired an extra few hours of learning. What I&#8217;m saying is that if you like the work somebody&#8217;s doing saying thanks not only makes thme feel good, it also will improve the chances of thme doing further things that will benefit you.)</p>
<p>One direct result of this is that I have written a short count-words-document function. All the hard work was taken care of by `karl&#8217;, he wrote the main count-words function as part of the text. But I have started to do a lot of editing of LaTeX text in emacs, so that I don&#8217;t have to deal with <abbr title="OpenOffice.org">OOo</abbr>&#8217;s obsessive desire to print my document every time I hit <abbr title="Control-P">C-p</abbr>. I can&#8217;t figure it out ;)</p>
<p>The wordcount function&#8217;s he wrote can count all the words in a region or a buffer, but neither of those are optimal of a LaTeXer, what with all the boilerplate my templates are accumulating. Sure, I <em>could</em> search for the beginning of the document, mark it, and then go to the end and pass the region to the function, but doesn&#8217;t that sound like to much work? Well, I realized that since all my templates begin with a &#8220;begin{document}&#8221; environment, and usually actually a &#8220;begin/end{singlespace}&#8221; env., that I could write a <abbr title="DEfine FUNction">defun</abbr> to just automatically deal with that, so voila:</p>

<div class="wp_syntax"><div class="code"><pre class="lisp" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">defun</span> count-words-document <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&amp;</span>optional arg begin end<span style="color: #66cc66;">&#41;</span>
  <span style="color: #ff0000;">&quot;Without ARG, count all the words in the {document} environment
if ARG exists, count words in region.&quot;</span>
  <span style="color: #66cc66;">&#40;</span>interactive <span style="color: #ff0000;">&quot;P<span style="color: #000099; font-weight: bold;">\n</span>r&quot;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> arg
      <span style="color: #66cc66;">&#40;</span>count-words-region <span style="color: #66cc66;">&#40;</span>prefix-numeric-<span style="color: #b1b100;">value</span> begin<span style="color: #66cc66;">&#41;</span>
			  <span style="color: #66cc66;">&#40;</span>prefix-numeric-<span style="color: #b1b100;">value</span> end<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>save-excursion
      <span style="color: #66cc66;">&#40;</span>goto-char <span style="color: #66cc66;">&#40;</span>point-<span style="color: #b1b100;">min</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>search-forward <span style="color: #ff0000;">&quot;end<span style="color: #000099; font-weight: bold;">\{</span>singlespace<span style="color: #000099; font-weight: bold;">\}</span>&quot;</span> <span style="color: #b1b100;">nil</span> t<span style="color: #66cc66;">&#41;</span>
	  <span style="color: #66cc66;">&#40;</span>count-words-region <span style="color: #66cc66;">&#40;</span>point<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">progn</span>
					<span style="color: #66cc66;">&#40;</span>search-forward <span style="color: #ff0000;">&quot;end<span style="color: #000099; font-weight: bold;">\{</span>document<span style="color: #000099; font-weight: bold;">\}</span>&quot;</span><span style="color: #66cc66;">&#41;</span>
					<span style="color: #66cc66;">&#40;</span>goto-char <span style="color: #66cc66;">&#40;</span>match-beginning <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">progn</span>
	  <span style="color: #66cc66;">&#40;</span>goto-char <span style="color: #66cc66;">&#40;</span>point-<span style="color: #b1b100;">min</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
	  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>search-forward <span style="color: #ff0000;">&quot;begin<span style="color: #000099; font-weight: bold;">\{</span>document<span style="color: #000099; font-weight: bold;">\}</span>&quot;</span> <span style="color: #b1b100;">nil</span> t<span style="color: #66cc66;">&#41;</span>
	      <span style="color: #66cc66;">&#40;</span>count-words-region <span style="color: #66cc66;">&#40;</span>point<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">progn</span>
					    <span style="color: #66cc66;">&#40;</span>search-forward <span style="color: #ff0000;">&quot;end<span style="color: #000099; font-weight: bold;">\{</span>document<span style="color: #000099; font-weight: bold;">\}</span>&quot;</span><span style="color: #66cc66;">&#41;</span>
					    <span style="color: #66cc66;">&#40;</span>goto-char <span style="color: #66cc66;">&#40;</span>match-beginning <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
	    <span style="color: #66cc66;">&#40;</span>count-words-region <span style="color: #66cc66;">&#40;</span>point-<span style="color: #b1b100;">min</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>point-<span style="color: #b1b100;">max</span><span style="color: #66cc66;">&#41;</span> t<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>That function depends on the `count-words-region&#8217; defun which was written by &#8220;karl&#8221; and can be downloaded, for convenience with my additional function <a title="wordcount from sqdc" href="http://svn.quodlibetor.com/pubsh/elisp/wordcount.el">from here</a>. The count-words-document function if called without an argument (e.g. `M-x count-words-document&#8217;) will automatically create a region that begins, in descending order, with `end{singlespace}&#8217;, then `begin{document}&#8217;, then just the beginning of the buffer. The first two conditions will end the region at an `end{document}&#8217; string, and the beginning of the buffer ends at the end of the buffer. So it has a nice descending order of most logical TeX regions. You can also, if you want pass it any argument (e.g. `C-u M-x count-words-document&#8217;) and it will count the words in the current region instead.</p>
<p>This would be nicer if it searched for variables instead of hard-coded regexes, but for now that&#8217;s for a v0.2 or something, since I don&#8217;t know how to define custom variables yet. Also, I just realized that the documentation is horribly incomplete. Anyway:</p>
<p>To install it, stick it in your load-path (if you haven&#8217;t got one set up, adding <code>(setq load-path (cons ".emacs.d" load-path))</code> to your .emacs file will add `.emacs.d&#8217; to your load path, just make the actual directory [that is to say, `mkdir .emacs.d'] and put the file inside it.) and add <code lang="lisp">(load "wordcount")</code> to your .emacs file somewhere below the load-path edit, and voila.</p>
<p>You could also set it to a shortcut key, for example I have it set to `C-c d&#8217;</p>
<p><code>(global-set-key "\C-cd" 'count-words-document)</code></p>
<p>`d&#8217; for Document.</p>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fblog.quodlibetor.com%2F2008%2F07%2Femacs-lisp-php-wordcount-and-etc%2F';
  addthis_title  = 'emacs%2C+lisp%2C+php%2C+wordcount%2C+and+etc.';
  addthis_pub    = 'quodlibetor';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>

<!-- start wp-tags-to-technorati 1.01 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/emacs' rel='tag' target='_self'>emacs</a>, <a class='technorati-link' href='http://technorati.com/tag/lisp' rel='tag' target='_self'>lisp</a>, <a class='technorati-link' href='http://technorati.com/tag/wordcount' rel='tag' target='_self'>wordcount</a></p>

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://blog.quodlibetor.com/2008/07/emacs-lisp-php-wordcount-and-etc/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Subversive Subversion</title>
		<link>http://blog.quodlibetor.com/2008/05/subversive-subversion/</link>
		<comments>http://blog.quodlibetor.com/2008/05/subversive-subversion/#comments</comments>
		<pubDate>Wed, 14 May 2008 23:00:27 +0000</pubDate>
		<dc:creator>quodlibetor</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[svn]]></category>

		<guid isPermaLink="false">http://blog.quodlibetor.com/?p=112</guid>
		<description><![CDATA[In honor of getting subversion up and running on my website, and in honor of sort-of publishing my first code, I wend ahead and set up websvn. With syntax highlighting! (Thanks to mihasya) So, if you&#8217;re ever curious about what I&#8217;ve been coding recently you can check out svn.quodlibetor.com and view logs, etc.
And, of course, ]]></description>
			<content:encoded><![CDATA[<p>In honor of getting subversion up and running on my website, and in honor of sort-of <a title="Hot damn self-publishing" href="http://blog.quodlibetor.com/2008/05/14/my-first-useful-program-ever/">publishing my first code</a>, I wend ahead and set up websvn. With syntax highlighting! (Thanks to <a title="Instructions" href="http://mihasya.com/blog/?p=31">mihasya</a>) So, if you&#8217;re ever curious about what I&#8217;ve been coding recently you can check out <a title="sqdc" href="http://svn.quodlibetor.com">svn.quodlibetor.com</a> and view logs, etc.</p>
<p>And, of course, freedom-loving individual that I am, I would love collaborators (programmers, designers, eventually educators, and of course other kinds of people I haven&#8217;t thought of) on any project you can see there.</p>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fblog.quodlibetor.com%2F2008%2F05%2Fsubversive-subversion%2F';
  addthis_title  = 'Subversive+Subversion';
  addthis_pub    = 'quodlibetor';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>

<!-- start wp-tags-to-technorati 1.01 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/svn' rel='tag' target='_self'>svn</a></p>

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://blog.quodlibetor.com/2008/05/subversive-subversion/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My first useful program, ever</title>
		<link>http://blog.quodlibetor.com/2008/05/my-first-useful-program-ever/</link>
		<comments>http://blog.quodlibetor.com/2008/05/my-first-useful-program-ever/#comments</comments>
		<pubDate>Wed, 14 May 2008 07:23:17 +0000</pubDate>
		<dc:creator>quodlibetor</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[hardware]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://blog.quodlibetor.com/?p=111</guid>
		<description><![CDATA[2:00am, finals week, what would be a good use of my time? Oh, yeah, how about writing a little bash script to keep my external hard drive from constantly spinning down? Observe:

#!/bin/bash
&#160;
while &#91; true &#93;
do
    touch /media/BigEx/.keephdactive
    sleep 4m
done

Wow, right?
Yeah, it&#8217;s been kind of bothering me for months, nothing ]]></description>
			<content:encoded><![CDATA[<p>2:00am, finals week, what would be a good use of my time? Oh, yeah, how about writing a little <a href="http://en.wikipedia.org/wiki/Bash"><abbr title="Bourne Again SHell">bash</abbr></a> script to keep my external hard drive from constantly spinning down? Observe:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #c20cb9; font-weight: bold;">true</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">do</span>
    <span style="color: #c20cb9; font-weight: bold;">touch</span> <span style="color: #000000; font-weight: bold;">/</span>media<span style="color: #000000; font-weight: bold;">/</span>BigEx<span style="color: #000000; font-weight: bold;">/</span>.keephdactive
    <span style="color: #c20cb9; font-weight: bold;">sleep</span> 4m
<span style="color: #000000; font-weight: bold;">done</span></pre></div></div>

<p>Wow, right?</p>
<p>Yeah, it&#8217;s been kind of bothering me for <em>months</em>, nothing on the internet anywhere had an easy way to do this. And then, after 5-ten minutes of googling in vain all of a sudden I thought to myself: &#8220;Hey man, you&#8217;re supposed to be a <em>computer scientist</em>, (tbd) <strong></strong>can&#8217;t you do something about this?&#8221; And so, in less time than several failed google searches, I had this.</p>
<p>If you&#8217;re on linux and you want to get this running, copy &amp; paste the following into your terminal. It will open up your text editor, inside of which you should change the &#8220;BigEx&#8221; to the name of your external hard drive. (What it shows up as in the menus and such.) These commands will just put it in your home folder, at the end there&#8217;s a command to move it out of there, if you don&#8217;t know how.</p>
<p>If you&#8217;re in GNOME (eg Ubuntu):<br />
<code>wget http://svn.quodlibetor.com/pubsh/bash/hdactive.sh &amp;&amp; gedit hdactive.sh &amp;&amp; chmod +rx hdactive.sh</code></p>
<p>If you&#8217;re in KDE (eg Kubuntu, Fedora 9):<br />
<code>wget http://svn.quodlibetor.com/pubsh/bash/hdactive.sh &amp;&amp; kate hdactive.sh &amp;&amp; chmod +rx hdactive.sh</code></p>
<p>The only difference between them is a different text editor. (The &#8220;&amp;&amp;&#8221;s are just ways to join multiple commands together in one line, I did it so that you won&#8217;t have to copy/paste 3 times just to get a little hack working :)</p>
<p>Last thing to do then is run it:</p>
<p><code>./hdactive.sh &amp;</code></p>
<p>should do it. (The &#8220;&amp;&#8221; just means &#8220;run this process in the background.&#8221;)</p>
<p>If you&#8217;re in GNOME and you want this file to run every time you start your system, first it&#8217;s probably a good idea to put it in your /usr/bin directory:</p>
<p><code>sudo mv hdactive.sh /usr/bin/</code></p>
<p>And then you&#8217;ll want to add it to your startup session, which is something I don&#8217;t know a command for, or how to do it in KDE, so menus time: &#8220;System -&gt; Preferences -&gt; Sessions&#8221; select &#8220;+ add&#8221; from the right side, for the name put &#8220;HDactive&#8221; (or whatever) for the command put &#8220;hdactive.sh&#8221; (no quotes) and for comment put &#8220;oh man quodlibetor&#8217;s friggin&#8217; sweet.&#8221;</p>
<p>That last part is essential for the proper working of the code :)</p>
<p>OK, it&#8217;s now officially been <a title="Man, xkcd did everything first" href="http://xkcd.com/196/">an hour and fifteen minutes</a> since I thought &#8220;damn I wish my hard drive would stay on.&#8221; On the one hand, that&#8217;s way too long, on the other hand, my hard drive has stayed on :)</p>
<p>p.s. I know that there are at least a couple things to do to make this work better (eg accept parameters instead of making people change the code by hand) this works for me, and it&#8217;s also damn near my first <em>working </em>bash script ever, so I&#8217;ll change it as I have time. I promise that the link will always work though, and if I change it enough that these instructions don&#8217;t apply any more I&#8217;ll put comments inside it so anybody trying to edit a newer version will see that something&#8217;s weird and what to do about it. You can consider it currently licensed under the <a title="WTFPL homepage. If your work is prudish, this link might be NSFW." href="http://sam.zoy.org/wtfpl/">WTFPL</a>, so do wtf you want to with it :)</p>
<p>[edited a whole bunch of times to get some basic code formatting and syntax highlighting working, since this is my first post with actual code]</p>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fblog.quodlibetor.com%2F2008%2F05%2Fmy-first-useful-program-ever%2F';
  addthis_title  = 'My+first+useful+program%2C+ever';
  addthis_pub    = 'quodlibetor';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>

<!-- start wp-tags-to-technorati 1.01 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/bash' rel='tag' target='_self'>bash</a>, <a class='technorati-link' href='http://technorati.com/tag/hardware' rel='tag' target='_self'>hardware</a>, <a class='technorati-link' href='http://technorati.com/tag/howto' rel='tag' target='_self'>howto</a>, <a class='technorati-link' href='http://technorati.com/tag/linux' rel='tag' target='_self'>linux</a>, <a class='technorati-link' href='http://technorati.com/tag/script' rel='tag' target='_self'>script</a></p>

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://blog.quodlibetor.com/2008/05/my-first-useful-program-ever/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.904 seconds -->
