<?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>Adam Risi - [online]</title>
	<atom:link href="http://www.adamrisi.com/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.adamrisi.com</link>
	<description>science, technology, and sarcasm</description>
	<lastBuildDate>Mon, 12 Jul 2010 16:17:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>(ab)Using function pointers and void pointers to achieve truly generic functions in C</title>
		<link>http://www.adamrisi.com/?p=142</link>
		<comments>http://www.adamrisi.com/?p=142#comments</comments>
		<pubDate>Fri, 09 Jul 2010 17:45:33 +0000</pubDate>
		<dc:creator>Adam</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.adamrisi.com/?p=142</guid>
		<description><![CDATA[This has got to be some of the strangest code I have ever written. I was recently working on my implementation of a Finite State Machine engine in C, when I decided that I really wanted a way to pass both a function pointer (easy), and a list of arguments that could be passed to [...]]]></description>
			<content:encoded><![CDATA[<p>This has got to be some of the strangest code I have ever written. I was recently working on my implementation of a <a href="http://github.com/ajrisi/fsm">Finite State Machine engine in C</a>, when I decided that I really wanted a way to pass both a function pointer (easy), and a list of arguments that could be passed to that function (more difficult), as part of a table (really just an array) describing what functions, and what arguments to pass (really hard).</p>
<p>I toyed with ideas like variadic macros (or functions), abusing some sort of global stack of void pointers to various types of structs, and a bunch of other ideas. Finally, I came up with the following code (an example of the technique):</p>
<pre class="brush: c">#include &lt;stdio.h&gt;

struct threeint_args {
  int a;
  int b;
  int c;
};

void mult(void *args)
{
  struct threeint_args *ma = (struct threeint_args*)args;
  printf("%d * %d * %d = %d\n",
    ma-&gt;a, ma-&gt;b, ma-&gt;c,
    ma-&gt;a * ma-&gt;b * ma-&gt;c);
}

void add(void *args)
{
  struct threeint_args *aa = (struct threeint_args*)args;
  printf("%d + %d + %d = %d\n",
  aa-&gt;a, aa-&gt;b, aa-&gt;c,
  aa-&gt;a + aa-&gt;b + aa-&gt;c);
}

struct generic_func {
  void(*func)(void*);
  void *args;
};

void run_generics(struct generic_func gfs[])
{
  struct generic_func *gf = gfs;
  while(gf-&gt;func != NULL) {
    gf-&gt;func(gf-&gt;args);
    gf++;
  }
}

int main(int argc, char **argv)
{
  struct generic_func examples[] =
    {
      {mult, (void*)&amp;(struct threeint_args){1, 2, 3}},
      {add, (void*)&amp;(struct threeint_args){1, 2, 3}},

      {mult, (void*)&amp;(struct threeint_args){4, 5, 6}},
      {add, (void*)&amp;(struct threeint_args){4, 5, 6}},

      {mult, (void*)&amp;(struct threeint_args){7, 8, 9}},
      {add, (void*)&amp;(struct threeint_args){7, 8, 9}},

      {NULL}
    };

  run_generics(examples);
}</pre>
<p>&#8220;Alright&#8221;, I thought to myself, &#8220;this little program probably will throw a fit if I try to compile it, but lets try anyway.&#8221;</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">gcc</span> <span style="color: #660033;">-ggdb</span> <span style="color: #660033;">-o</span> <span style="color: #7a0874; font-weight: bold;">test</span> test.c
$</pre></div></div>

<p>&#8220;Now wait a minute &#8211; no complaints? Certainly, if I try to run it, there will be some sort of segfault, or bug, or something. This can&#8217;t be right&#8230;&#8221;</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">valgrind</span> .<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">test</span>
==<span style="color: #000000;">16546</span>== Memcheck, a memory error detector
==<span style="color: #000000;">16546</span>== Copyright <span style="color: #7a0874; font-weight: bold;">&#40;</span>C<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000;">2002</span>-<span style="color: #000000;">2009</span>, and GNU GPLd, by Julian Seward et al.
==<span style="color: #000000;">16546</span>== Using Valgrind-3.6.0.SVN-Debian and LibVEX; rerun with <span style="color: #660033;">-h</span> <span style="color: #000000; font-weight: bold;">for</span> copyright info
==<span style="color: #000000;">16546</span>== Command: .<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">test</span>
==<span style="color: #000000;">16546</span>==
<span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000;">2</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000;">3</span> = <span style="color: #000000;">6</span>
<span style="color: #000000;">1</span> + <span style="color: #000000;">2</span> + <span style="color: #000000;">3</span> = <span style="color: #000000;">6</span>
<span style="color: #000000;">4</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000;">5</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000;">6</span> = <span style="color: #000000;">120</span>
<span style="color: #000000;">4</span> + <span style="color: #000000;">5</span> + <span style="color: #000000;">6</span> = <span style="color: #000000;">15</span>
<span style="color: #000000;">7</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000;">8</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000;">9</span> = <span style="color: #000000;">504</span>
<span style="color: #000000;">7</span> + <span style="color: #000000;">8</span> + <span style="color: #000000;">9</span> = <span style="color: #000000;">24</span>
==<span style="color: #000000;">16546</span>==
==<span style="color: #000000;">16546</span>== HEAP SUMMARY:
==<span style="color: #000000;">16546</span>==     <span style="color: #000000; font-weight: bold;">in</span> use at <span style="color: #7a0874; font-weight: bold;">exit</span>: <span style="color: #000000;">0</span> bytes <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000;">0</span> blocks
==<span style="color: #000000;">16546</span>==   total heap usage: <span style="color: #000000;">0</span> allocs, <span style="color: #000000;">0</span> frees, <span style="color: #000000;">0</span> bytes allocated
==<span style="color: #000000;">16546</span>==
==<span style="color: #000000;">16546</span>== All heap blocks were freed <span style="color: #660033;">--</span> no leaks are possible
==<span style="color: #000000;">16546</span>==
==<span style="color: #000000;">16546</span>== For counts of detected and suppressed errors, rerun with: <span style="color: #660033;">-v</span>
==<span style="color: #000000;">16546</span>== ERROR SUMMARY: <span style="color: #000000;">0</span> errors from <span style="color: #000000;">0</span> contexts <span style="color: #7a0874; font-weight: bold;">&#40;</span>suppressed: <span style="color: #000000;">4</span> from <span style="color: #000000;">4</span><span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p><em>Holy s**t</em>. That just worked.</p>
<p>I don&#8217;t often get surprised by code that I write. After all, if I am writing it, it means I understand it (most of the time). This example; however, completely flabbergasted me. Being able to store the pointer to a function, and a pointer to the arguments to the function in an array means I can do all sorts of things. I could develop a signals and slots mechanism, I can pass table-local contexts to function pointers, hell, I could rule the world. I couldn&#8217;t find anything else like this on the web &#8211; so I thought I would share!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.adamrisi.com/?feed=rss2&amp;p=142</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The easiest way to use a Cricket A600 under Ubuntu (and any other linux)</title>
		<link>http://www.adamrisi.com/?p=138</link>
		<comments>http://www.adamrisi.com/?p=138#comments</comments>
		<pubDate>Sun, 03 Jan 2010 01:48:47 +0000</pubDate>
		<dc:creator>Adam</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.adamrisi.com/?p=138</guid>
		<description><![CDATA[The Cricket A600 is a cheap, little broadband USB device &#8211; but it has been the source of major headaches for some people. Especially those trying to set it up under linux. Well, after trying many things, and failing many times, I have found an elegant and command based way of getting on the web. [...]]]></description>
			<content:encoded><![CDATA[<p>The Cricket A600 is a cheap, little broadband USB device &#8211; but it has been the source of major headaches for some people. Especially those trying to set it up under linux. Well, after trying many things, and failing many times, I have found an elegant and command based way of getting on the web. </p>
<p>First, get this file: <a href='http://www.ubuntugeek.com/images/Cricket_Mode_Switch.tar.gz' >Cricket flip-flopper</a> Compile it up (or use the precompiled 32 bit binaries), and install it. Keep the extracted files handy.</p>
<p>Drop in the A600, and wait for it to show up as a CDROM drive. In the previously extracted files, run &#8220;sudo ./flipflop.sh&#8221;. Let it finish.</p>
<p>Check dmesg to make sure you saw &#8220;ttyACM0&#8243; go by at some point. Grep is good for this. </p>
<p>Lastly, install wvdial, and use the following in your /etc/wvdial.conf :</p>
<p>&#8230;<br />
Modem = /dev/ttyACM0<br />
Phone = #777<br />
&#8230;</p>
<p>Exec <strong>sudo wvdial</strong>, and off you go!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.adamrisi.com/?feed=rss2&amp;p=138</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tiny Little DNS Server has a new home (picodns update)</title>
		<link>http://www.adamrisi.com/?p=137</link>
		<comments>http://www.adamrisi.com/?p=137#comments</comments>
		<pubDate>Thu, 12 Nov 2009 05:08:16 +0000</pubDate>
		<dc:creator>Adam</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.adamrisi.com/?p=137</guid>
		<description><![CDATA[As I program more, I discover the true value of a repository is very, very high. So, I decided to move picodns, my little DNS server project, over to github, where it will be preserved for anyone just in case my server goes down. PicoDNS also features extensive user documentation. Not to mention github is [...]]]></description>
			<content:encoded><![CDATA[<p>As I program more, I discover the true value of a repository is very, very high. So, I decided to move picodns, my <a href="http://www.adamrisi.com/?p=45">little DNS server project</a>, over to github, where it will be preserved for anyone just in case my server goes down. PicoDNS also features <a href="http://github.com/ajrisi/picodns/raw/master/UserDocs.pdf">extensive user documentation</a>.</p>
<p>Not to mention github is awesome.</p>
<p>git clone git://github.com/ajrisi/picodns.git</p>
]]></content:encoded>
			<wfw:commentRss>http://www.adamrisi.com/?feed=rss2&amp;p=137</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>lsif goes v2.0</title>
		<link>http://www.adamrisi.com/?p=136</link>
		<comments>http://www.adamrisi.com/?p=136#comments</comments>
		<pubDate>Thu, 12 Nov 2009 04:30:03 +0000</pubDate>
		<dc:creator>Adam</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.adamrisi.com/?p=136</guid>
		<description><![CDATA[The software I contributed, and blogged about a while ago has gone v2.0. The newly modified source code now compiles and works on a larger variety of linux systems. The purpose of the software is essentially to list the network interfaces, their IP address, and whatever their IP address resolves into. It&#8217;s just a single [...]]]></description>
			<content:encoded><![CDATA[<p>The software I contributed, and <a href="http://www.adamrisi.com/?p=84">blogged about</a> a while ago has gone v2.0. The newly modified source code now compiles and works on a larger variety of linux systems.</p>
<p>The purpose of the software is essentially to list the network interfaces, their IP address, and whatever their IP address resolves into. It&#8217;s just a single file of delicious C code, and it works like a charm. Check it out!</p>
<p>git clone git://github.com/ajrisi/lsif.git</p>
]]></content:encoded>
			<wfw:commentRss>http://www.adamrisi.com/?feed=rss2&amp;p=136</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>lsif: list network interfaces on linux</title>
		<link>http://www.adamrisi.com/?p=132</link>
		<comments>http://www.adamrisi.com/?p=132#comments</comments>
		<pubDate>Mon, 12 Oct 2009 14:57:14 +0000</pubDate>
		<dc:creator>Adam</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.adamrisi.com/?p=132</guid>
		<description><![CDATA[I wrote some code a while ago that got a bit of attention, so I have decided to do a little bit of a re-write and update! The new code is called lsif, and it lists network interfaces on a computer, their IP address, and what that IP address resolves into.  You can download a [...]]]></description>
			<content:encoded><![CDATA[<p>I wrote <a href="http://www.adamrisi.com/?p=84">some code a while ago</a> that got a bit of attention, so I have decided to do a little bit of a re-write and update!</p>
<p>The new code is called <strong>lsif</strong>, and it lists network interfaces on a computer, their IP address, and what that IP address resolves into.  You can download a copy from github by doing:</p>
<p>git clone git://github.com/ajrisi/lsif.git</p>
<p>Or, visit <a href="http://github.com/ajrisi/lsif">the page at github</a> for more download options! As always, post here with any questions, and I will do my best to help you out! Of course, the benefit of using something like github is that if I need to do a revision, sending it out to all of you is easy. Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.adamrisi.com/?feed=rss2&amp;p=132</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linux Key Logger</title>
		<link>http://www.adamrisi.com/?p=129</link>
		<comments>http://www.adamrisi.com/?p=129#comments</comments>
		<pubDate>Tue, 22 Sep 2009 22:07:40 +0000</pubDate>
		<dc:creator>Adam</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.adamrisi.com/?p=129</guid>
		<description><![CDATA[Recently I decided to write a key logger for Linux, both as an exercise, and because I couldn&#8217;t seem to find a good one out there. I wrote up a quick (and simple) key logger that will listen for keys based on the event input chain that Linux uses, and then echo them to stdout. [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I decided to write a key logger for Linux, both as an exercise, and because I couldn&#8217;t seem to find a good one out there. I wrote up a quick (and simple) key logger that will listen for keys based on the event input chain that Linux uses, and then echo them to stdout. This allows you to send the key presses over a network, save them to file, or do almost anything else you can think of. This code will auto-detect the keyboard if possible, or the keyboard device can be listed on the command line.</p>
<p>Download: <a href="http://adamrisi.com/code/keylogger/keylogger.tar.gz">keylogger.tar.gz</a></p>
<p><a href="http://adamrisi.com/code/keylogger/src">View Source</a></p>
<p><strong>Installation</strong> is simple:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">tar</span> xvf keylogger.tar.gz
<span style="color: #7a0874; font-weight: bold;">cd</span> keylogger
<span style="color: #c20cb9; font-weight: bold;">make</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

<p>Documentation:</p>
<p>Look at keylogger&#8217;s man page: <strong>man keylogger</strong></p>
<p>My code was based off of uberkey, and a few other key loggers available on the net.</p>
<p>Note: There may occasionally be discrepancies between the documentation for the program (<strong>man keylogger</strong>), and the program itself. If this happens, then the documentation will normally be updated within a day or two.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.adamrisi.com/?feed=rss2&amp;p=129</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Why robots need an e-stop</title>
		<link>http://www.adamrisi.com/?p=124</link>
		<comments>http://www.adamrisi.com/?p=124#comments</comments>
		<pubDate>Sun, 30 Aug 2009 21:24:19 +0000</pubDate>
		<dc:creator>Adam</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.adamrisi.com/?p=124</guid>
		<description><![CDATA[The good news: My robot is alive! The bad news: It has a thirst for blood, and nobody can stop it!]]></description>
			<content:encoded><![CDATA[<p>The good news: My robot is alive!</p>
<p>The bad news: It has a thirst for blood, and nobody can stop it!</p>
<p><object width="425" height="350" data="http://www.youtube.com/v/w9mGYEjAktk" type="application/x-shockwave-flash"><param name="src" value="http://www.youtube.com/v/w9mGYEjAktk" /></object></p>
]]></content:encoded>
			<wfw:commentRss>http://www.adamrisi.com/?feed=rss2&amp;p=124</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Holy sh*t! It&#8217;s a blog post</title>
		<link>http://www.adamrisi.com/?p=120</link>
		<comments>http://www.adamrisi.com/?p=120#comments</comments>
		<pubDate>Thu, 20 Aug 2009 05:12:52 +0000</pubDate>
		<dc:creator>Adam</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.adamrisi.com/?p=120</guid>
		<description><![CDATA[Alright, I haven&#8217;t blogged in a while. It&#8217;s true, I know it. I&#8217;m sorry, OK?! Gorsh! Enough &#8220;hellos&#8221;, lets get down to business. Rachel got found (my missing friend). I made a RFID door unlocker. I am all ready to start another quarter at RIT. And this, this is a funny comic: Cyanide &#38; Happiness [...]]]></description>
			<content:encoded><![CDATA[<p>Alright, I haven&#8217;t blogged in a while. It&#8217;s true, I know it. I&#8217;m sorry, OK?! Gorsh!</p>
<p>Enough &#8220;hellos&#8221;, lets get down to business. Rachel got found (my missing friend). I made a RFID door unlocker. I am all ready to start another quarter at RIT. And this, this is a funny comic:</p>
<p style="text-align: center;"><a href="http://www.explosm.net/comics/883/"><img src="http://www.flashasylum.com/db/files/Comics/Kris/future.png" border="0" alt="Cyanide and Happiness, a daily webcomic" /></a><br />
Cyanide &amp; Happiness @ <a href="http://www.explosm.net">Explosm.net</a></p>
<p style="text-align: left;">I feel like its a delightful statement on the dangers of &#8220;feature creep&#8221;, oh, and funny. Yep, lots of funny. Anyway, just saying &#8220;Hi&#8221;, and that I hope to be posting more when I am back in the run of things at RIT. Yay school!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.adamrisi.com/?feed=rss2&amp;p=120</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Blogging from a tent</title>
		<link>http://www.adamrisi.com/?p=117</link>
		<comments>http://www.adamrisi.com/?p=117#comments</comments>
		<pubDate>Tue, 30 Jun 2009 23:14:21 +0000</pubDate>
		<dc:creator>Adam</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.adamrisi.com/?p=117</guid>
		<description><![CDATA[Since its raining, and I find it far too exciting to blog, I just thought I would let you all know that I am in my new tent! I got a Big Agnes Emerald Mountain SL3 (for $205 &#8211; dont ask me how), and I thought I would try it out in the yard. It&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>Since its raining, and I find it far too exciting to blog, I just thought I would let you all know that I am in my new tent! I got a Big Agnes Emerald Mountain SL3 (for $205 &#8211; dont ask me how), and I thought I would try it out in the yard. It&#8217;s awesome! Loads of room and waterproof right from the get-go. I am impressed Big Agnes!</p>
<p>If only thunderstorms and daisy-chained extension cords went together just a little bit better&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.adamrisi.com/?feed=rss2&amp;p=117</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MISSING: Rachel Lynn Martel from Georgia, VT</title>
		<link>http://www.adamrisi.com/?p=112</link>
		<comments>http://www.adamrisi.com/?p=112#comments</comments>
		<pubDate>Mon, 08 Jun 2009 14:10:57 +0000</pubDate>
		<dc:creator>Adam</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.adamrisi.com/?p=112</guid>
		<description><![CDATA[Update: SHE WAS FOUND. Thank you all for reading my post. Today, I have some unfortunate news to bring to you &#8211; One of my high school friends has gone missing. Her name is Rachel Lynn Martel. She has been missing since 5/28/2009 (as of this post, 12 days). If you see Rachel, please call [...]]]></description>
			<content:encoded><![CDATA[<p>Update: SHE WAS FOUND. Thank you all for reading my post.</p>
<p>Today, I have some unfortunate news to bring to you &#8211; One of my high school friends has gone missing. Her name is Rachel Lynn Martel.</p>
<p>She has been missing since 5/28/2009 (as of this post, 12 days).</p>
<p>If you see Rachel, please call the Essex Police Department at 802-879-4923. As I gather more information, it will be posted here.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.adamrisi.com/?feed=rss2&amp;p=112</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
