<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

  <title><![CDATA[Yuval Adam]]></title>
  <link href="http://blog.y3xz.com/atom.xml" rel="self"/>
  <link href="http://blog.y3xz.com/"/>
  <updated>2013-04-24T10:07:30+03:00</updated>
  <id>http://blog.y3xz.com/</id>
  <author>
    <name><![CDATA[Yuval Adam]]></name>
    
  </author>
  <generator uri="http://octopress.org/">Octopress</generator>

  
  <entry>
    <title type="html"><![CDATA[(Re)building the Cryptoparty Community]]></title>
    <link href="http://blog.y3xz.com/blog/2013/01/03/re-building-the-cryptoparty-community/"/>
    <updated>2013-01-03T13:42:00+02:00</updated>
    <id>http://blog.y3xz.com/blog/2013/01/03/re-building-the-cryptoparty-community</id>
    <content type="html"><![CDATA[<blockquote><p>&#8220;Assume good faith&#8221; -(rule 0 of every community)</p></blockquote>

<p>The saddest thing about the recent events involving Cryptoparty and 29C3 is that I have yet to notice a single discussion which was constructive. 29C3 was the first chance for the Cryptoparty community to meet in a physical place and discuss how to evolve from there. We had that chance, and we blew it.</p>

<p>The 29C3 Cryptoparty itself was actually quite fun, and even though we were essentially preaching to the choir, it was a good experience. There was a good discussion on the first day sharing experiences and knowledge from various Cryptopartae. We also had some productive hours of discussing how we should continue work on the Cryptoparty Handbook. Alas, we should&#8217;ve done more than that. The setting was toxic - despite people keeping a straight face, everyone knew there&#8217;s something wrong.</p>

<p>The Cryptoparty community has just started to take form. The social connections have just started to take place. Up until now, we just had the Cryptoparty meme - symbolized by a hashtag bearing the same name - and some local meetups. We have just barely started to form global connections and extrapolate the collective knowledge into further projects and long-term goals. For me, that was one of the main goals of meeting the people behind Cryptoparty at 29C3.</p>

<p>What we got instead was a shitstorm of rage and anger, rendering the environment completely non-productive. If the goal is to make for some juicy gossip on teh twitterz, we&#8217;re definitely winning. But let&#8217;s not delude ourselves that this is some form of constructive community action.</p>

<p>I applaud all who participate in the 140-character-free-for-all - it definitely satisfied my primal need for some good gossip. At the end of the day, it&#8217;s pretty easy to discern who in the community is actually interested in building shit and spreading crypto through honest <em>constructive</em> discussion.</p>

<p>Key members of the Cryptoparty community are well aware of my stance on certain issues of the past two weeks, as I have approached them <em>directly</em> and let them know of my concerns and views. I see no use in discussing these recent events in public, since none of them have anything to do - whatsoever - with building the Cryptoparty community.</p>

<p>I hope that by the time 30C3 occurs, we - as a community - can show significant progress not only in our efforts to spread the use of crypto, but in the way we handle communications between ourselves, with honesty and respect.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[A Primer on Cheap Software Defined Radios]]></title>
    <link href="http://blog.y3xz.com/blog/2012/12/02/a-primer-on-cheap-software-defined-radios/"/>
    <updated>2012-12-02T03:01:00+02:00</updated>
    <id>http://blog.y3xz.com/blog/2012/12/02/a-primer-on-cheap-software-defined-radios</id>
    <content type="html"><![CDATA[<p>I&#8217;ve always been fascinated by radio. I clearly remember discovering <a href="https://en.wikipedia.org/wiki/Numbers_station">numbers stations</a> at the age of 9 using my grandparent&#8217;s old shortwave radio, and I was fascinated by the concept of stuff being broadcast over the air - discounting FM radio which was <em>ordinary</em>.</p>

<p>Actually, I&#8217;ve always wanted to buy a frequency scanner and learn more about radio, but never got around to actually doing so, something didn&#8217;t feel right. Last week, the <em>right</em> thing I was waiting for was found - an open-source software stack and a $15 USB dongle turn my desktop computer into a <a href="https://en.wikipedia.org/wiki/Software-defined_radio">software defined radio</a>. Essentially, this means that anyone can, very cheaply, pull data out of thin air (literally), and analyze it using <strong>code</strong>.</p>

<p>Up until now, SDR could only be achieved using expensive equipment, and using proprietary drivers and software. The $15 SDR option is a serious breakthrough in making the SDR world more accessible. As with most new technologies, the open-source SDR world is still not very user-friendly, and in this post I&#8217;ll try to outline the basic stuff a beginner should know when entering this world.</p>

<p><img class="right" src="http://voltar.org/gnuradio/mixer_diagram.grc.png"></p>

<p>The basis for SDR is <a href="http://gnuradio.org/redmine/projects/gnuradio/wiki">GNU Radio</a>, which is an open source toolkit that provides all the necessary mathematical building blocks to begin implementing SDR. In essence, GNU Radio is a set of APIs that allow to build usable SDR programs. An important part of GNU Radio is the GNU Radio Companion which is a simple GUI that allows to connect various signal processing components into a single graph and generate code from it. The thing is that, for most basic cases, we don&#8217;t really want to write the signal processing code ourselves.</p>

<p>Let&#8217;s go back to the hardware part. Up until now, if you wanted to do SDR you had to use expensive receivers, such as the <a href="http://www.universal-radio.com/catalog/widerxvr/2500.html">Icom R2500</a>. Naturally, these proprietary products natively supported Windows PCs, and you could forget about Linux, not to mention seeing any code for the software or drivers. Granted, <a href="https://en.wikipedia.org/wiki/Universal_Software_Radio_Peripheral">USRP</a> devices were much more open and accessible, but the hardware was still very expensive, and posed a high barrier of entry for novice users that just wanted to play around.</p>

<p>As it turns out, it&#8217;s possible to use cheap DVT-B USB dongles (like <a href="https://dx.com/p/mini-dvb-t-digital-tv-usb-2-0-dongle-with-fm-dab-remote-controller-844092096">this</a> one) and hack them into proper SDR receivers. <a href="https://en.wikipedia.org/wiki/DVB-T">DVB-T</a> is a worldwide standard for digital TV broadcast, and apparently the cheap tuners that are manufactured en masse are just the thing we can use to do <a href="http://thread.gmane.org/gmane.linux.drivers.video-input-infrastructure/44461/focus=44461"><em>poor&#8217;s man SDR</em></a>.</p>

<p>The software that we use to handle the cheap dongles is <a href="http://sdr.osmocom.org/trac/wiki/rtl-sdr">rtl-sdr</a> and is the core of the setup. Now, setting up the entire stack is the tricky part. The GNU Radio stack has <em>lots</em> of dependencies, both C and Python libs, and has no easy, cross-platform, way of setting up. I actually kind of gave up on my Mac setup, and took me several hours to get shit running on my Linux box. Other than throwing a bunch of links, I really don&#8217;t have any better installation instructions that the ones out there. There will be lots of errors and dependency issues along the way, it&#8217;s a matter of sifting through wikis and lots of Googling &#8216;till something works. Here are some links that should cover most of what you&#8217;ll need:</p>

<ul>
<li><a href="http://gnuradio.org/redmine/projects/gnuradio/wiki/InstallingGR">Installing GNU Radio</a></li>
<li><a href="http://sdr.osmocom.org/trac/wiki/GrOsmoSDR">Installing GNU Radio OsmoSDR</a></li>
<li><a href="http://sdr.osmocom.org/trac/wiki/rtl-sdr#Buildingthesoftware">Building rtl-sdr</a></li>
<li><a href="https://github.com/titanous/homebrew-gnuradio">GNU Radio homebrew recipies</a> (Mac OS X only, obviously)</li>
<li><a href="http://www.reddit.com/r/rtlsdr/">rtl-sdr community subreddit</a></li>
</ul>


<p>Fortunately, all tools use standard autoconf and cmake toolchains, so the installation procedure for most packages will be similar. If all went well, at this point, we&#8217;ll want to see the following test running smoothly:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>rtl_test -t
</span><span class='line'>Found 1 device<span class="o">(</span>s<span class="o">)</span>:
</span><span class='line'>  0:  ezcap USB 2.0 DVB-T/DAB/FM dongle
</span><span class='line'>
</span><span class='line'>Using device 0: ezcap USB 2.0 DVB-T/DAB/FM dongle
</span><span class='line'>Found Elonics E4000 tuner
</span><span class='line'>Supported gain values <span class="o">(</span>18<span class="o">)</span>: -1.0 1.5 4.0 6.5 9.0 11.5 14.0 16.5 19.0 21.5 24.0 29.0 34.0 42.0 43.0 45.0 47.0 49.0
</span><span class='line'>Benchmarking E4000 PLL...
</span><span class='line'><span class="o">[</span>E4K<span class="o">]</span> PLL not locked <span class="k">for </span>51000000 Hz!
</span><span class='line'><span class="o">[</span>E4K<span class="o">]</span> PLL not locked <span class="k">for </span>2227000000 Hz!
</span><span class='line'><span class="o">[</span>E4K<span class="o">]</span> PLL not locked <span class="k">for </span>1114000000 Hz!
</span><span class='line'><span class="o">[</span>E4K<span class="o">]</span> PLL not locked <span class="k">for </span>1241000000 Hz!
</span><span class='line'>E4K range: 52 to 2226 MHz
</span><span class='line'>E4K L-band gap: 1114 to 1241 MHz
</span></code></pre></td></tr></table></div></figure>


<p>After getting the dongle and the drivers all setup we want to listen to some stuff! As I mentioned earlier, building various signal processing flows is totally beyond the scope for what we&#8217;re trying to do, all we want is a simple tuner with some knobs to twist, and eventually hear some sound coming out the speakers. The most easiest receiver software I&#8217;ve found so far is <a href="http://www.oz9aec.net/index.php/gnu-radio/gqrx-sdr">gqrx</a> (<a href="https://github.com/csete/gqrx">also on Github</a>).</p>

<p><img class="right" src="https://farm9.staticflickr.com/8027/7144857315_4632536298_z.jpg" width="400"></p>

<p>Gqrx is very easy to grok, even for beginners with no experience listening to the radio waves. Start off by picking a frequency that you know should be active, broadcast FM radio is the obvious choice here, and just tinker with the knobs until it sounds reasonable. Learn what the difference between AM and FM is. Learn how the FM filter works. Play with the squelch levels to silence the white noise on channels that aren&#8217;t always active. From my experience, it takes a while to understand how everything comes together.</p>

<p>After playing around with broadcast FM, you can advance to other  transmissions: air traffic, ham radio, police and fire services, navigation beacons, GPS, GSM, POCSAG, P25. Each of these subjects is an entire post in and of itself.</p>

<p>The final point I want to make is that listening to radio waves has lots of nuances to it. The stock antenna shipped with the dongles is absolutely insufficient to receive anything other than strong signals. If you&#8217;re serious in doing SDR, you&#8217;ll have to invest time researching proper antenna setups and reducing noise.</p>

<p>Nonetheless, this cheap SDR setup is mind-blowing in how easy it can be to start playing around with stuff that used to be extremely expensive.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Deploying Periodical Tasks on Heroku]]></title>
    <link href="http://blog.y3xz.com/blog/2012/11/16/deploying-periodical-tasks-on-heroku/"/>
    <updated>2012-11-16T19:23:00+02:00</updated>
    <id>http://blog.y3xz.com/blog/2012/11/16/deploying-periodical-tasks-on-heroku</id>
    <content type="html"><![CDATA[<p>Heroku is an awesome platform for hosting web applications, that much is obvious. A few days ago I had another application to deploy on Heroku, but with a different usage profile. The application, <a href="https://github.com/yuvadm/rotter-tweets">a simple breaking news tweeting app</a>, periodically scrapes a popular Israeli forum with breaking headlines, and tweets them - a fairly straightforward task. However, this application has no request-response cycle, and in fact has no open web gateway, just a simple task running periodically, every minute in our case.</p>

<p>Naturally, this task needs to run on a 24/7-available server, not just on a random desktop. Sure I have several VMs I can piggyback this task on, but I wanted to find the way to package this little task properly such that I can deploy it easily on Heroku and forget about the whole thing. Since I&#8217;m running a single process on a single Heroku dyno, if I could get it to work, it wouldn&#8217;t cost a thing.</p>

<p>For asyncronous and scheduled tasks in Python, the obvious solution is to use <a href="http://celeryproject.org/">Celery</a>. The core of the setup is a single Celery worker running a periodical task. Since we only have one worker, and we can&#8217;t spare another process for the Celery heartbeat process (it&#8217;d cost another Heroku dyno which isn&#8217;t free), we&#8217;ll use the <code>celery worker</code> process with the <code>-B</code> flag that bundles the worker and the heartbeat into one convenient process.</p>

<p>Celery can&#8217;t work without a messaging broker, naturally with Heroku we&#8217;ll use the <code>redistogo:nano</code> plan.</p>

<p>Here&#8217;s the code for a simple worker, <code>tasks.py</code>:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
<span class='line-number'>22</span>
</pre></td><td class='code'><pre><code class='python'><span class='line'><span class="kn">import</span> <span class="nn">logging</span>
</span><span class='line'>
</span><span class='line'><span class="kn">from</span> <span class="nn">celery</span> <span class="kn">import</span> <span class="n">Celery</span>
</span><span class='line'><span class="kn">from</span> <span class="nn">celery.task</span> <span class="kn">import</span> <span class="n">periodic_task</span>
</span><span class='line'><span class="kn">from</span> <span class="nn">datetime</span> <span class="kn">import</span> <span class="n">timedelta</span>
</span><span class='line'><span class="kn">from</span> <span class="nn">os</span> <span class="kn">import</span> <span class="n">environ</span>
</span><span class='line'>
</span><span class='line'><span class="n">REDIS_URL</span> <span class="o">=</span> <span class="n">environ</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;REDISTOGO_URL&#39;</span><span class="p">,</span> <span class="s">&#39;redis://localhost&#39;</span><span class="p">)</span>
</span><span class='line'>
</span><span class='line'><span class="n">celery</span> <span class="o">=</span> <span class="n">Celery</span><span class="p">(</span><span class="s">&#39;tasks&#39;</span><span class="p">,</span> <span class="n">broker</span><span class="o">=</span><span class="n">REDIS_URL</span><span class="p">)</span>
</span><span class='line'>
</span><span class='line'>
</span><span class='line'><span class="k">def</span> <span class="nf">fib</span><span class="p">(</span><span class="n">n</span><span class="p">):</span>
</span><span class='line'>    <span class="k">if</span> <span class="n">n</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
</span><span class='line'>        <span class="k">return</span> <span class="n">fib</span><span class="p">(</span><span class="n">n</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span> <span class="o">+</span> <span class="n">fib</span><span class="p">(</span><span class="n">n</span> <span class="o">-</span> <span class="mi">2</span><span class="p">)</span>
</span><span class='line'>    <span class="k">else</span><span class="p">:</span>
</span><span class='line'>        <span class="k">return</span> <span class="mi">1</span>
</span><span class='line'>
</span><span class='line'>
</span><span class='line'><span class="nd">@periodic_task</span><span class="p">(</span><span class="n">run_every</span><span class="o">=</span><span class="n">timedelta</span><span class="p">(</span><span class="n">seconds</span><span class="o">=</span><span class="mi">10</span><span class="p">))</span>
</span><span class='line'><span class="k">def</span> <span class="nf">print_fib</span><span class="p">():</span>
</span><span class='line'>    <span class="n">logging</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="n">fib</span><span class="p">(</span><span class="mi">30</span><span class="p">))</span>
</span></code></pre></td></tr></table></div></figure>


<p>To wrap it up, you&#8217;ll need a <code>Procfile</code> with a single line launching the worker:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='python'><span class='line'><span class="n">worker</span><span class="p">:</span> <span class="n">celery</span> <span class="o">-</span><span class="n">A</span> <span class="n">tasks</span> <span class="n">worker</span> <span class="o">-</span><span class="n">B</span> <span class="o">--</span><span class="n">loglevel</span><span class="o">=</span><span class="n">info</span>
</span></code></pre></td></tr></table></div></figure>


<p>I find this setup to be <em>very</em> convenient if I need to deploy a single recurring task, and not care at all about setting up cron jobs or manually configuring deployment environments. Heroku FTW.</p>

<p>All the code, as always, is in a single repo on Github: <a href="https://github.com/yuvadm/heroku-periodical">https://github.com/yuvadm/heroku-periodical</a>. Enjoy!</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[An Open Toolchain for the TI Stellaris]]></title>
    <link href="http://blog.y3xz.com/blog/2012/10/29/an-open-toolchain-for-the-ti-stellaris/"/>
    <updated>2012-10-29T23:21:00+02:00</updated>
    <id>http://blog.y3xz.com/blog/2012/10/29/an-open-toolchain-for-the-ti-stellaris</id>
    <content type="html"><![CDATA[<p><img class="right" src="http://blog.y3xz.com/images/stellaris.jpg"></p>

<p><a href="http://blog.y3xz.com/blog/2012/10/07/setting-up-an-arm-eabi-toolchain-on-mac-os-x/">In my last post</a> I set up an ARM EABI toolchain to work with my CCC r0ket badge. Incidentally, I just received my <a href="http://www.ti.com/stellaris">Texas Instruments Stellaris</a> dev board and wanted to start playing around with it. Unfortunately, TI&#8217;s development tools are highly bloated, proprietary and almost exclusively geared towards Windows environments. Unacceptable. I wasn&#8217;t about to download a 1.3GB file just to get a LED blinking on a dev board using my Mac.</p>

<p>As it turns out, all the building blocks are there, and it&#8217;s just a matter of putting them together. Here&#8217;s how to get a simple project compiled and flashed on your TI Stellaris by using an open toolchain.</p>

<p>First, we need a cross-compiler. For that, we use the ARM EABI toolchain which can be installed using the amazing <a href="https://github.com/jsnyder/arm-eabi-toolchain">ARM EABI Toolchain Builder</a>. Follow the instructions, and make sure you have the respective <code>bin</code> directory in your path.</p>

<p>Next, we need the flashing tools. Fortunately, some code is already available from the <a href="https://github.com/utzig/lm4tools">lm4tools</a> package. It&#8217;s dependent on <code>libusb</code>, so install that with your favorite package manager, and otherwise it&#8217;s a breeze to install. <code>lm4tools</code> supplies us with both a flashing utility as well as with a USB/ICDI debugging bridge. For now we just want the flashing utility. The package already comes with a readymade binary, which we can try to test, but we&#8217;ll go ahead and compile our own. It&#8217;s just more fun that way :)</p>

<p>Finally, we need all the source and header files relevant to the Stellaris. Those all exist in TI&#8217;s StellarisWare packages, but are a bitch to download. Seriously, I won&#8217;t even try to link to them. I extracted all the necessary files to <a href="https://github.com/yuvadm/stellaris">my own Stellaris repo on Github</a>, and cloning that should get you everything you need. After cloning the repo, <code>cd</code> into one of the projects, such as <code>boards/ek-lm4f120xl/project0</code>.</p>

<p>If all is well, running <code>make</code> will quickly yield the output binary located in <code>gcc/project0.bin</code>. We&#8217;re now ready to flash. Point to your <code>lm4flash</code> util and run:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>./path/to/lm4flash gcc/project0.bin
</span></code></pre></td></tr></table></div></figure>


<p>If the flashing process was successful, the RGB LED on the Stellaris should now be blinking blue and red alternatively. Awesome. A trivial exercise would be to add a green blink to the sequence.</p>

<p>It&#8217;s cool to have the board running at last, but it&#8217;s a shame TI doesn&#8217;t make this stuff more accessible and open. From what I&#8217;ve seen so far, the Stellaris is a pretty neat board, and I hope to write more in the future about the advanced functionality you can get out of it.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Setting up an ARM EABI toolchain on Mac OS X]]></title>
    <link href="http://blog.y3xz.com/blog/2012/10/07/setting-up-an-arm-eabi-toolchain-on-mac-os-x/"/>
    <updated>2012-10-07T16:35:00+02:00</updated>
    <id>http://blog.y3xz.com/blog/2012/10/07/setting-up-an-arm-eabi-toolchain-on-mac-os-x</id>
    <content type="html"><![CDATA[<p><img class="right" src="http://r0ket.badge.events.ccc.de/_media/wiki:r0ket_space_iii.jpg?w=400" title="r0ket badge" ></p>

<p><a href="http://events.ccc.de/2012/08/03/call-for-participation-for-29th-chaos-communication-congress/">29C3</a> is coming up, and after completeing and submitting my talk proposals, I&#8217;ve recently started hacking on my <a href="http://r0ket.badge.events.ccc.de/">r0ket badge</a>, which I managed to get my hands on a year ago at 28C3.</p>

<p>After setting it up and doing some SMD soldering with the RGB flame module, the next step is hacking on the r0ket&#8217;s firmware, writing <a href="http://r0ket.badge.events.ccc.de/l0dables">l0dable</a> applications.</p>

<p>The r0ket has an ARM processor and its firmware and applications are cross-compiled using the ARM EABI toolchain. The r0ket wiki has instructions on <a href="http://r0ket.badge.events.ccc.de/build_mac">how to set up an environment on Mac OS X</a>, and I&#8217;ll try to give some comlementary tips on how to accomplish that.</p>

<p>My preferred option would be to use standard <a href="https://github.com/mxcl/homebrew/">homebrew</a> formulae as much as possible. Unfortunately, homebrew chose not to include the ARM EABI toolchain in it&#8217;s offerings. <a href="https://github.com/jpc/homebrew">A homebrew fork</a> has support for the <code>arm-none-eabi-gcc</code> formula, but I found it not up to date.</p>

<p>If you use MacPorts, it might be possible to <code>sudo port install arm-none-eabi-gcc</code>, but unfortunately MacPorts and homebrew are mutually exclusive, and I&#8217;m definitely sticking with homebrew.</p>

<p>By far, the easiest solution I found was a simple-to-use makefile wrapped up with some patches specifically built for the task of building an ARM EABI toolchain, they can be found <a href="https://github.com/jsnyder/arm-eabi-toolchain">on github</a>.</p>

<p>Make sure you have the proper dependencies first:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'>brew install mpfr gmp libmpc libelf texinfo
</span></code></pre></td></tr></table></div></figure>


<p>Then simply clone the repository, and run the makefile:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'>git clone https://github.com/jsnyder/arm-eabi-toolchain
</span><span class='line'><span class="nb">cd </span>arm-eabi-toolchain
</span><span class='line'>make install-cross
</span></code></pre></td></tr></table></div></figure>


<p>Remember you&#8217;re building the entire toolchain, so expect this step to take at least an hour, and your Mac to heat up running 100% CPU. When all the tools are built you can find them located at <code>~/arm-cs-tools</code>. Remember to somehow add <code>~/arm-cs-tools/bin</code> to your <code>$PATH</code>.</p>

<p>The bonus for all this is that I just recently received my <a href="http://www.ti.com/ww/en/launchpad/stellaris_head.html">Texas Instruments Stellaris Launchpad</a> evaluation kits, and I&#8217;ll definitely be making heavy use of this toolchain. Not to mention that an ARM-based Arduino board is in the making&#8230;</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Flask and PostgreSQL on Heroku]]></title>
    <link href="http://blog.y3xz.com/blog/2012/08/16/flask-and-postgresql-on-heroku/"/>
    <updated>2012-08-16T19:01:00+03:00</updated>
    <id>http://blog.y3xz.com/blog/2012/08/16/flask-and-postgresql-on-heroku</id>
    <content type="html"><![CDATA[<p><a href="http://heroku.com">Heroku</a> is increasingly becoming my favorite platform to deploy simple Python applications on. Heroku actually gives you a completely managed environment where you can deploy an app in literally minutes. Not to mention that the free tier usage on Heroku (1 dyno, Postgres dev plan) can actually get you pretty far.</p>

<p>You can follow the official docs on Heroku that explain <a href="https://devcenter.heroku.com/articles/python/">how to get started from scratch</a>, but I find them lacking some explanation on how to set up Postgres, so here&#8217;s the complete formula I use to rapidly deploy simple Python apps.</p>

<p>All the code in this post can be found in the <a href="https://github.com/yuvadm/heroku-python-skeleton">matching repository on Github</a>.</p>

<p>I&#8217;m going to assume you have a basic project setup, if not just follow the aforementioned tutorial. So now we need to add support for PostgreSQL. We&#8217;ll do that by using <a href="http://packages.python.org/Flask-SQLAlchemy/">Flask-SQLAlchemy</a> which will give us everything we need to connect to the Postgres DB as well as an easy to use ORM. So first we need to install the dependency and add it to our <code>requirements.txt</code>:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>pip install flask-sqlalchemy psycopg2
</span><span class='line'><span class="c"># don&#39;t forget to update requirements.txt</span>
</span><span class='line'><span class="nv">$ </span>pip freeze &gt; requirements.txt
</span></code></pre></td></tr></table></div></figure>


<p>Before we continue we&#8217;ll have to create the Postgres DB and we&#8217;ll start off with the free dev plan which allows for up to 10K rows and 20 simultaneous connections:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>heroku addons:add heroku-postgresql:dev
</span><span class='line'>-----&gt; Adding heroku-postgresql:dev to some-app-name... <span class="k">done</span>, v196 <span class="o">(</span>free<span class="o">)</span>
</span><span class='line'>Attached as HEROKU_POSTGRESQL_COLOR
</span><span class='line'>Database has been created and is available
</span></code></pre></td></tr></table></div></figure>


<p>Once the database is setup we should promote it such that the <code>DATABASE_URL</code> environment variable will be set:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>heroku pg:promote HEROKU_POSTGRESQL_COLOR
</span><span class='line'>Promoting HEROKU_POSTGRESQL_COLOR_URL to DATABASE_URL... <span class="k">done</span>
</span></code></pre></td></tr></table></div></figure>


<p>Now we can go ahead and import the library and add the basic connection boilerplate:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class='python'><span class='line'><span class="kn">from</span> <span class="nn">flask.ext.sqlalchemy</span> <span class="kn">import</span> <span class="n">SQLAlchemy</span>
</span><span class='line'>
</span><span class='line'><span class="n">app</span> <span class="o">=</span> <span class="n">Flask</span><span class="p">(</span><span class="n">__name__</span><span class="p">)</span>
</span><span class='line'><span class="n">app</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s">&#39;SQLALCHEMY_DATABASE_URI&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s">&#39;DATABASE_URL&#39;</span><span class="p">]</span>
</span><span class='line'><span class="n">db</span> <span class="o">=</span> <span class="n">SQLAlchemy</span><span class="p">(</span><span class="n">app</span><span class="p">)</span>
</span></code></pre></td></tr></table></div></figure>


<p>For this step, you can optionally use Kenneth Reitz&#8217;s <a href="https://github.com/kennethreitz/flask-heroku">flask-heroku</a> library, which handles setting all connection URLs automatically, not only for Postgres, but for other services such as redis, sentry, exceptional and others.</p>

<p>The next step is to commit the boilerplate code and create the actual DB tables:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>git commit -a -m <span class="s2">&quot;added DB boilerplate&quot;</span>
</span><span class='line'><span class="nv">$ </span>git push heroku master
</span><span class='line'><span class="c"># ...</span>
</span><span class='line'><span class="nv">$ </span>heroku run python
</span></code></pre></td></tr></table></div></figure>


<p>Once we have a connected Python terminal we can run:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class='python'><span class='line'><span class="o">&gt;&gt;&gt;</span> <span class="kn">from</span> <span class="nn">app</span> <span class="kn">import</span> <span class="n">db</span>
</span><span class='line'><span class="o">&gt;&gt;&gt;</span> <span class="n">db</span><span class="o">.</span><span class="n">create_all</span><span class="p">()</span>
</span></code></pre></td></tr></table></div></figure>


<p>And we&#8217;re set! From here we can start using SQLAlchemy&#8217;s code to define models and create, query and delete objects. Here are some examples. We can start off by creating a new <code>User</code> model:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
</pre></td><td class='code'><pre><code class='python'><span class='line'><span class="k">class</span> <span class="nc">User</span><span class="p">(</span><span class="n">db</span><span class="o">.</span><span class="n">Model</span><span class="p">):</span>
</span><span class='line'>    <span class="nb">id</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">Column</span><span class="p">(</span><span class="n">db</span><span class="o">.</span><span class="n">Integer</span><span class="p">,</span> <span class="n">primary_key</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
</span><span class='line'>    <span class="n">name</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">Column</span><span class="p">(</span><span class="n">db</span><span class="o">.</span><span class="n">String</span><span class="p">(</span><span class="mi">80</span><span class="p">))</span>
</span><span class='line'>    <span class="n">email</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">Column</span><span class="p">(</span><span class="n">db</span><span class="o">.</span><span class="n">String</span><span class="p">(</span><span class="mi">120</span><span class="p">),</span> <span class="n">unique</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
</span><span class='line'>
</span><span class='line'>    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">email</span><span class="p">):</span>
</span><span class='line'>        <span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="n">name</span>
</span><span class='line'>        <span class="bp">self</span><span class="o">.</span><span class="n">email</span> <span class="o">=</span> <span class="n">email</span>
</span><span class='line'>
</span><span class='line'>    <span class="k">def</span> <span class="nf">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
</span><span class='line'>        <span class="k">return</span> <span class="s">&#39;&lt;Name </span><span class="si">%r</span><span class="s">&gt;&#39;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span>
</span></code></pre></td></tr></table></div></figure>


<p>We can create the object itself:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class='python'><span class='line'><span class="n">user</span> <span class="o">=</span> <span class="n">User</span><span class="p">(</span><span class="s">&#39;John Doe&#39;</span><span class="p">,</span> <span class="s">&#39;john.doe@example.com&#39;</span><span class="p">)</span>
</span><span class='line'><span class="n">db</span><span class="o">.</span><span class="n">session</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">user</span><span class="p">)</span>
</span><span class='line'><span class="n">db</span><span class="o">.</span><span class="n">session</span><span class="o">.</span><span class="n">commit</span><span class="p">()</span>
</span></code></pre></td></tr></table></div></figure>


<p>We can query objects:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='python'><span class='line'><span class="n">all_users</span> <span class="o">=</span> <span class="n">User</span><span class="o">.</span><span class="n">query</span><span class="o">.</span><span class="n">all</span><span class="p">()</span>
</span></code></pre></td></tr></table></div></figure>


<p>And we can delete objects:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class='python'><span class='line'><span class="n">user</span> <span class="o">=</span> <span class="n">User</span><span class="p">(</span><span class="s">&#39;John Doe&#39;</span><span class="p">,</span> <span class="s">&#39;john.doe@example.com&#39;</span><span class="p">)</span>
</span><span class='line'><span class="n">db</span><span class="o">.</span><span class="n">session</span><span class="o">.</span><span class="n">delete</span><span class="p">(</span><span class="n">user</span><span class="p">)</span>
</span><span class='line'><span class="n">db</span><span class="o">.</span><span class="n">session</span><span class="o">.</span><span class="n">commit</span><span class="p">()</span>
</span></code></pre></td></tr></table></div></figure>


<p>And that&#8217;s all you need to know about setting up a Flask + Postgres app on Heroku.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[A modern Python stack for a real-time web application]]></title>
    <link href="http://blog.y3xz.com/blog/2012/06/08/a-modern-python-stack-for-a-real-time-web-application/"/>
    <updated>2012-06-08T00:00:00+03:00</updated>
    <id>http://blog.y3xz.com/blog/2012/06/08/a-modern-python-stack-for-a-real-time-web-application</id>
    <content type="html"><![CDATA[<p>Earlier today I wrote <a href="http://stackoverflow.com/a/10950702/24545">a detailed answer on Stack Overflow</a> about a suggested Python
stack for building a modern real-time web application. This is based upon the
work I did over the past several months with
<a href="http://plantacomment.com">PlantAComment.com</a>, <a href="http://blog.y3xz.com/blog/2012/05/20/webgl--liquid-galaxy-fun/">which I&#8217;ve also written about recently</a>.</p>

<p>In any case, I&#8217;ve found this stack to be pretty damn solid. Since we were
doing real-time WebGL rendering, and synching that data on a multi-client
landscape, we actually were sending dozens of messages per seconds (granted,
small messages) and that also worked out surprisingly well.</p>

<p>Anyway, enough with the talk, here&#8217;s the stack. For starters, the entire app
is served on the <a href="http://www.tornadoweb.org/">Tornado web server</a>, which is a
non-blocking web server that excels in this kind of stuff, and also has some
nice &#8220;classic&#8221; web app support such as authentication, templates, etc., so we
also used it for serving up the entire app itself, and not only the real-time
evented stuff.</p>

<p>Next up is the messaging protocol. We started out using
<a href="http://socket.io">socket.io</a>, which has a default implementation in Node.js,
and is supported on Tornado via
<a href="https://github.com/mrjoes/tornadio2">tornadio2</a>. This worked out fine, but
following a conversation with MrJoes (tornadio2 maintainer), we decided to
switch and use <a href="https://github.com/sockjs/sockjs-client">sock.js</a>, which also
has a Tornado server implementation, <a href="https://github.com/MrJoes/sockjs-tornado">sockjs-tornado</a>. In essence, socket.io&#8217;s
protocol is known to have some defects, and the fact that anything other than
the Node.js implementation is a second-class citizen just feels awkward.
Sock.js is a fully-tested protocol, and generally feels more solid, so we
decided to go with it.</p>

<p>Most messaging examples in Tornado involve using a class-level variable that
maintains all connections to all connected clients. This is a horrible setup
and should never be used for anything beyond trivial applications. It&#8217;s like
maintaining data inside your web server because you&#8217;re too lazy to spin up a
database.</p>

<p>So for all the messaging stuff, we decided to use Redis&#8217; <a href="http://redis.io/commands#pubsub">pub-sub capabilites</a>. And since we&#8217;re in the context
of Tornado, we&#8217;re also going to need a proper asynchronous interface - which
is done beautifully by the <a href="https://github.com/evilkost/brukva">brukva</a>
library. As a side note, I should mention that brukva is implemented using
adisp, and does not employ any of the Tornado async building blocks. There is
another project, <a href="https://github.com/leporo/tornado-redis">tornado-redis</a>,
which claims to do just that, but I haven&#8217;t got around to actually using it.
You might have more luck with that, though. In any case, brukva works just
fine.</p>

<p>(<strong>Update</strong>: Since the original post, tornado-redis has proven to be the superior option, as it uses the standard async tools provided by Tornado.)</p>

<p>And that&#8217;s pretty much it. We can bring it all together with this
<code>ConnectionHandler</code> which has all the functionality we need:</p>

<div><script src='https://gist.github.com/2897508.js'></script>
<noscript><pre><code>class ConnectionHandler(SockJSConnection):
    def __init__(self, *args, **kwargs):
        super(ConnectionHandler, self).__init__(*args, **kwargs)
        self.client = brukva.Client()
        self.client.connect()
        self.client.subscribe('some_channel')

    def on_open(self, info):
        self.client.listen(self.on_chan_message)

    def on_message(self, msg):
        # this is a message broadcast from the client
        # handle it as necessary (this implementation ignores them)
        pass

    def on_chan_message(self, msg):
        # this is a message received from redis
        # send it to the client
        self.send(msg.body)

    def on_close(self):
        self.client.unsubscribe('text_stream')
        self.client.disconnect()
</code></pre></noscript></div>


<p>And that&#8217;s how you do real-time messaging with Python.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[WebGL / Liquid Galaxy Fun]]></title>
    <link href="http://blog.y3xz.com/blog/2012/05/20/webgl--liquid-galaxy-fun/"/>
    <updated>2012-05-20T00:00:00+03:00</updated>
    <id>http://blog.y3xz.com/blog/2012/05/20/webgl&#8211;liquid-galaxy-fun</id>
    <content type="html"><![CDATA[<p>The past several weeks have kept me very busy on my latest collaboration with
new-media artists <a href="http://omta.co">Omer and Tal Golan</a>.</p>

<p><img src="http://blog.y3xz.com/images/tumblr_m4bm1g9IUB1qgekad.png"></p>

<p>Our project, <a href="http://plantacomment.com">PlantAComment.com</a> (שיח גלריה, in
Hebrew) is an interactive installation that encourages visitors to plant
thoughts that manifest themselves as trees in a semi-apocalyptic 3D world. The
installation premiered this week at the <a href="http://www.freshpaint.co.il/en/">2012 Fresh Paint art fair in Tel Aviv</a>. Throughout the week, our project has
received much acclaim from visitors of all ages.</p>

<p>On the technical side, the project is a behemoth in terms of how many
technologies we&#8217;ve used to make it all happen. The server-side is based on a
core Tornado web server that handles all HTTP requests, as well as WebSocket
connections. Redis is used both as a back-end store, as well as for pub/sub
for new messages that are received via SMS text messages, as well as Twitter
and G+ posts. With the help of the amazing <a href="http://www.linkedin.com/in/nirofek">Nir Ofek</a>, we&#8217;ve also implemented advanced
semantic analysis on all incoming texts, allowing us to cluster similar
subjects on the same trees. Credits to the beautiful soundscape go to the
most-talented Nir Danan.</p>

<p>The most impressive aspect of the project, by far, is the WebGL implementation
of the 3D world that is able of running in-browser on any WebGL-capable modern
browser. The highlight for the installation was deploying our project on
Google&#8217;s Liquid Galaxy setup - a 7-machine setup connected to 7 55&#8221; LED
screens that run in complete synchronization, showing a 180 degree view of the
world. This is the first time in the world an art project is deployed on this
setup.</p>

<p>Expect to hear more about this project in the near future ;)</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Deploying a Bottle App on ep.io]]></title>
    <link href="http://blog.y3xz.com/blog/2012/03/18/deploying-a-bottle-app-on-epio/"/>
    <updated>2012-03-18T00:00:00+02:00</updated>
    <id>http://blog.y3xz.com/blog/2012/03/18/deploying-a-bottle-app-on-epio</id>
    <content type="html"><![CDATA[<p><a href="http://bottlepy.org/">Bottle</a> apps can be deployed on
<a href="https://www.ep.io/">ep.io</a> as generic WSGI apps. It&#8217;s not an immediate thing,
since there&#8217;s a small workaround that you need to apply before being able to
set bottle as a requirement to be installed.</p>

<p>For some reason the Bottle version that ep.io pulls from PyPI has some weird
<code>ImportError</code>. The solution is to pull directy from the git repo.</p>

<p>Here&#8217;s a full working example:</p>

<div><script src='https://gist.github.com/2065828.js'></script>
<noscript><pre><code>from bottle import app, route

@route('/')
def index():
    return 'Oh Hai!'

application = app()
</code></pre></noscript></div>



]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Stack Overflow, stop blocking me]]></title>
    <link href="http://blog.y3xz.com/blog/2012/03/11/stack-overflow-stop-blocking-me/"/>
    <updated>2012-03-11T00:00:00+02:00</updated>
    <id>http://blog.y3xz.com/blog/2012/03/11/stack-overflow-stop-blocking-me</id>
    <content type="html"><![CDATA[<p><img class="right" src="http://blog.y3xz.com/images/tumblr_m0qighBJdP1qgekad.png"></p>

<p>Seriously, Stack Overflow, WTF?</p>

<p>For three days now, at PyCon2012, I can&#8217;t browse any Stack Overflow / Stack
Exchange page. Why? All the wireless networks here at the conference are
unencrypted. Connecting without passing through a secure connection (VPN/SSH
tunnel) is an endeavor I would recommend to no one. Riding an open wireless
network <a href="http://www.urbandictionary.com/define.php?term=bareback">bareback</a>?
No way.</p>

<p>So, I use <a href="http://blog.y3xz.com/blog/2011/05/22/poor-%0Amans-vpn/">the amazing sshuttle</a> which is routed to one of my servers on Amazon EC2. But guess what?
<a href="http://meta.stackoverflow.com/questions/116109/amazon-web-services-ip-blocks-filtering">Stack Exchange blocks all incoming traffic from EC2</a>. Why? Supposedly, to prevent screen-scraping bots.</p>

<p>Now, I&#8217;m not intimate with SO/SE&#8217;s traffic patterns, and I&#8217;m sure they are
highly susceptible to content farm scraper bots. But blocking all EC2 IPs is
the most stupid way to do this that anyone can think of. Real scraper bots
that depend on content mining will easily find other IPs to access SO/SE from.</p>

<p>Newsflash - I (and other legit VPN users) don&#8217;t have a spare bank of public
IPs or VPN endpoints.</p>

<p>A simple solution would be to easily rate limit requests per <em>any</em> IP to a
reasonable rate that normal users would never notice (say, 5 requests/sec).</p>

<p>Until Stack Overflow / Stack Exchange implements a better way of blocking
scrape-bots without blocking legit users - I&#8217;ll continue to suffer anytime I&#8217;m
not under a secure wireless network.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Configuring postfix to work with Gmail on Mac OS X]]></title>
    <link href="http://blog.y3xz.com/blog/2012/01/11/configuring-postfix-to-work-with-gmail-on-mac-os-x/"/>
    <updated>2012-01-11T00:00:00+02:00</updated>
    <id>http://blog.y3xz.com/blog/2012/01/11/configuring-postfix-to-work-with-gmail-on-mac-os-x</id>
    <content type="html"><![CDATA[<p>One of the things I&#8217;m sorry I didn&#8217;t do earlier is setup postfix on my Mac,
such that I&#8217;ll be able to send quick emails (not to mention git patches)
directly from command line.</p>

<p>As we all know, sending emails directly from your machine is a sure way to get
yourself blacklisted as spam. So using an SMTP relay is pretty much required.
But since my main email account is hosted on Gmail, and I want to be able to
connect securely to Googles SMTP servers, this requires some configuration.</p>

<p>First thing&#8217;s first, add your authentication details to the relay. If you&#8217;re
using Gmail, this goes like this, create a new file:</p>

<pre><code>sudo vi /etc/postfix/relay_password
</code></pre>

<p>And add the auth details to it, just one line:</p>

<pre><code>smtp.gmail.com:587 your_user_name@gmail.com:your_password
</code></pre>

<p>Next, we need to generate a lookup DB from these details:</p>

<pre><code>sudo postmap /etc/postfix/relay_password
</code></pre>

<p>And make sure the <code>relay_password.db</code> file has been generated.</p>

<p>Now it&#8217;s time to update the <code>main.cf</code> configuration file. You might want to
keep a backup before you add the following changes. First, check that the line</p>

<pre><code>tls_random_source = dev:/dev/urandom
</code></pre>

<p>exists in the file and is not commented out, this should be the case by
default. Now here&#8217;s the main logic which you can simply append to the end of
the file:</p>

<pre><code>relayhost = smtp.gmail.com:587

smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/relay_password
smtp_sasl_security_options = noanonymous

smtp_tls_security_level = may
smtp_tls_CApath = /etc/postfix/certs
smtp_tls_session_cache_database = btree:/etc/postfix/smtp_scache
smtp_tls_session_cache_timeout = 3600s
smtp_tls_loglevel = 1
</code></pre>

<p>The last thing we need to do is setup the root SSL certificate that Google
uses, which is the Thawte Premium Server CA. First:</p>

<pre><code>sudo mkdir /etc/postfix/certs &amp;&amp; cd certs
</code></pre>

<p>Then, download the PEM file:</p>

<pre><code>sudo wget https://www.thawte.com/roots/thawte_Premium_Server_CA.pem
</code></pre>

<p>Now we need to run a rehash on the PEM file:</p>

<pre><code>sudo c_rehash /etc/postfix/certs/
</code></pre>

<p>And that&#8217;s it! Give it a test run, and hopefully you&#8217;ll receive an e-mail
strongly authenticated and relayed from your Gmail account:</p>

<pre><code>echo "Relay Test" | mail -s "Relay Testing" test_recipient@domain.com
</code></pre>

<p>As an extra added bonus, you might want to set your hostname to something more
descriptive than <code>mymachine.local</code> by adding this line to the <code>main.cf</code>:</p>

<pre><code>myhostname = some-domain-i-own.com
</code></pre>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Resolving a Corrupt sudoers in Mac OS X]]></title>
    <link href="http://blog.y3xz.com/blog/2012/01/06/resolving-a-corrupt-sudoers-in-mac-os-x/"/>
    <updated>2012-01-06T00:00:00+02:00</updated>
    <id>http://blog.y3xz.com/blog/2012/01/06/resolving-a-corrupt-sudoers-in-mac-os-x</id>
    <content type="html"><![CDATA[<p>During 28C3, I was being over-paranoid about the security of my laptop, and I
accidentally did something really really (really) stupid to my <code>/etc/sudoers</code>
file, I commented out this line:</p>

<pre><code># User privilege specification
root    ALL=(ALL) ALL
# %admin  ALL=(ALL) ALL
</code></pre>

<p>See what I did there? No more <code>sudo</code> for my admin user. End of story. I
thought I was doomed. The only way to resolve this situation, essentially, is
to boot into some sort of safe mode with the Mac OS X installation disk.
Needless to say I didn&#8217;t have it with me.</p>

<p>Luckily, Mac OS X is built in a way that allows resolving a corrupt <code>sudoers</code>,
exploiting the way the OS manages permissions. This method was first described
<a href="http://blog.astrails.com/2009/9/29/how-to-fix-a-hosed-etc-sudoers-file-on-mac-osx">here</a>, props to Astrails for the idea.</p>

<p>The idea is that the while the command line <code>sudo</code> works with the <code>sudoers</code>
file, the UI authentication does not.</p>

<p><img src="http://upload.wikimedia.org/wikipedia/en/6/6f/Mac_OS_X_Authenticate.png" alt="" /></p>

<p>Exploiting this, you can change the file permissions on <code>/etc/sudoers</code> without
needing <code>sudo</code> access. All you need to do is open a Finder window, <code>Shift-Cmd-G</code> and go to the <code>/etc</code> folder. From there, select the <code>sudoers</code> file and
open its info pane (<code>Cmd-I</code>). Scroll down to the Sharing &amp; Permissions panel,
and unlock it using your admin password. You now can temporarily change the
file permissions such that you&#8217;ll be able to edit it without <code>sudo</code> access.</p>

<p>Now all you need to do is fix the crap that you did to your <code>sudoers</code> file,
reset the permissions back to <code>440</code> and you&#8217;re all set.</p>

<p>Next time, if you think you need to edit your <code>sudoers</code> file, <strong>DO NOT</strong>.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Bitcoin for Dummies]]></title>
    <link href="http://blog.y3xz.com/blog/2012/01/03/bitcoin-for-dummies/"/>
    <updated>2012-01-03T00:00:00+02:00</updated>
    <id>http://blog.y3xz.com/blog/2012/01/03/bitcoin-for-dummies</id>
    <content type="html"><![CDATA[<p>I recently started delving into the world of a new currency which you might
have heard of - Bitcoin. I figured out I want to know more about it, and what
applications it might have. As it turns out, the concepts behind Bitcoin are
actually not that complicated, and I believe that if you are able to grasp the
concept of money as we know it, in the form of the proverbial cold-hard-cash,
you should have no problem understanding Bitcoin and how it works. I&#8217;ll
simplify some concepts in order to make things understandable, but the
concepts will absolutely remain true to form.</p>

<h2>What is Bitcoin?</h2>

<p>Bitcoin is the name of a currency that exists entirely in a network of
computers, even your computer at home can be part of that network. There are
no real, physical, coins or bills. Nothing other than data stored in various
computers all over the world.</p>

<h2>How does it work?</h2>

<p>Bitcoin, at its core, is essentially a huge list of transactions, that anyone
can have a copy of. A simple list might look like this:</p>

<pre><code>A (10) -&gt; B
B (4) -&gt; A
B (3) -&gt; A
</code></pre>

<p>In this simple list, we have two people, A and B. A sent B 10 bitcoins, after
which B returned 4 bitcoins to A, and then decided to send 3 more bitcoins
back to A. So this list is nothing more than a series of transaction details.</p>

<p>So assuming both A and B had 20 bitcoins to start with, after the three
transactions, A now has 17 bitcoins left, while B has 23 bitcoins in his
wallet. Easy stuff. Now, for an outsider to know how much money each party
has, all he needs to do is know how many bitcoins each one had to begin with,
and from there he can simply add and subtract the details of the transactions
and find out who has how many Bitcoins. This is, in essence, the Bitcoin
system.</p>

<h2>How is this data saved?</h2>

<p>This transaction list is shared between many computers all over the world. If
A wants to send B 10 bitcoins, he would just issue that transaction on his
computer, which would then, in turn, tell the whole world &#8220;Hey! A just sent B
10 bitcoins!&#8221;. Over time, that message would propagate all over the Internet
to everyone running a Bitcoin client. That&#8217;s all there is to issuing a
transaction.</p>

<h2>Wait, so, I can fake transactions!</h2>

<p>Not really, no. Transactions are secured using strong data encryption methods.
These are the exact same methods that are in use to securely transfer your
credit card details when making an online purchase, or when logging in to your
e-mail account. These methods ensure that only the sending party is able to
issue genuine transactions.</p>

<h2>So who verifies the transactions?</h2>

<p>Well, someone has to go over the list of transactions and approve them,
otherwise the list has no value. Therefore, anyone who wants to can contribute
to the system by reviewing the recent transactions, and doing some heavy
calculations on the data, to ensure that they are all indeed valid.</p>

<h2>Why would anyone do that?</h2>

<p>Simple, because by donating computing power, you actually receive Bitcoins
from the system! The process of verifying the transactions is called mining,
and is rewarded with Bitcoins that the system generates just for you, out of
thin air. This is how Bitcoins are &#8220;printed&#8221;.</p>

<h2>Is there any other way to get Bitcoins?</h2>

<p>Sure. If a friend of yours is willing to, he can give or sell you any amount
of Bitcoins he wants, as long as he had some to start with. He will issue a
transaction saying that he transfers some Bitcoins to your possession. He can
either do that for free, but more likely that he&#8217;ll ask you for something in
return, so you&#8217;ll probably be paying him back either in cash, or giving
selling some product or service to him. In any case, that&#8217;s up to the two
parties to solve between themselves.</p>

<h2>So how is this different from the current cash system?</h2>

<p>It&#8217;s not! Think about it, coins and bills are just pieces of metal and paper,
with little significant value. The value they have is the one that we give
them. By printing &#8220;100&#8221; on a piece of paper, we&#8217;re saying that it is worth 100
units of something. So when people start to accept Bitcoin as a valid
currency, it is in not that different than any other currency in use around
the world, other than that it has no physical existence.</p>

<h2>I have 100 Bitcoins, what does that mean?</h2>

<p>That means that over time, you have accumulated 100 Bitcoins, either from
transactions with various people, or by mining them (and then it would be the
&#8216;system&#8217; that gave you the Bitcoins). Anyone going over the list of
transaction and verifying its accuracy will end up with the same answer &#8220;yep,
he really is the legit owner of 100 Bitcoins&#8221;. You are free to do whatever you
want with these Bitcoins in your possession.</p>

<h2>Review</h2>

<p>In essence, this is all there is to the Bitcoin system. Of course, there are
many more issues that derive from this system. In further posts I&#8217;ll talk
about the exact monetary value of Bitcoins, how anonymous (if at all) the
system is, and various interesting dilemmas that arise from the usage of such
a currency.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[28C3: Data Mining the Israeli Population Census]]></title>
    <link href="http://blog.y3xz.com/blog/2011/12/28/28c3-data-mining-the-israeli-population-census/"/>
    <updated>2011-12-28T00:00:00+02:00</updated>
    <id>http://blog.y3xz.com/blog/2011/12/28/28c3-data-mining-the-israeli-population-census</id>
    <content type="html"><![CDATA[<p>The slides from my talk today at 28C3 are now online:</p>

<script src="http://speakerdeck.com/embed/4ef1fe9b77c16d004c012031.js"></script>


<p>And so is the final version of the video:</p>

<iframe width="560" height="315" src="http://www.youtube.com/embed/ow7cvZOzp6w" frameborder="0" allowfullscreen></iframe>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Preparing for 28C3; Here's a heatmap of the Israeli population.]]></title>
    <link href="http://blog.y3xz.com/blog/2011/12/19/preparing-for-28c3-heres-a-heatmap-of-the-israeli-population/"/>
    <updated>2011-12-19T00:00:00+02:00</updated>
    <id>http://blog.y3xz.com/blog/2011/12/19/preparing-for-28c3-heres-a-heatmap-of-the-israeli-population</id>
    <content type="html"><![CDATA[<p><img src="http://blog.y3xz.com/images/tumblr_lwg35ajXRL1qhid1ro1_400.png"></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[28C3 Talk]]></title>
    <link href="http://blog.y3xz.com/blog/2011/11/27/28c3-talk/"/>
    <updated>2011-11-27T00:00:00+02:00</updated>
    <id>http://blog.y3xz.com/blog/2011/11/27/28c3-talk</id>
    <content type="html"><![CDATA[<p>So remember my previous post about how it&#8217;s possible to <a href="http://blog.y3xz.com/blog/2011/07/20/data-mining-the-israeli-population-census/">data mine the Israeli census database</a>?</p>

<p>My proposal to give a talk about that at the upcoming 28th Chaos Communication
Congress (28C3) has been officially accepted, <a href="http://events.ccc.de/congress/2011/Fahrplan/events/4652.en.html">and is now published in the Fahrplan</a>.</p>

<p>Make sure you drop by if you plan on attending!</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Keynote Syntax Highlighting]]></title>
    <link href="http://blog.y3xz.com/blog/2011/11/11/keynote-syntax-highlighting/"/>
    <updated>2011-11-11T00:00:00+02:00</updated>
    <id>http://blog.y3xz.com/blog/2011/11/11/keynote-syntax-highlighting</id>
    <content type="html"><![CDATA[<p>Need to copy some code from TextMate to Keynote and want to keep your cool
syntax highlighting?</p>

<p>Suffer no more - <a href="https://github.com/drnic/copy-as-rtf-tmbundle">https://github.com/drnic/copy-as-rtf-tmbundle</a></p>

<pre><code>mkdir -p ~/Library/Application\ Support/TextMate/Bundles
cd ~/Library/Application\ Support/TextMate/Bundles
git clone git://github.com/drnic/copy-as-rtf-tmbundle.git "Copy as RTF.tmbundle"
</code></pre>

<p>After that just reload the TextMate Bundles: <code>Bundles &gt; Bundle Editor &gt; Reload
Bundles</code>.</p>

<p>Copy any code with <code>Cmd-Alt-Ctrl-R</code> and paste into Keynote, your delicious
syntax highlighting will be there!</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Setting up an iodine IP-over-DNS proxy]]></title>
    <link href="http://blog.y3xz.com/blog/2011/11/01/setting-up-an-iodine-ip-over-dns-proxy/"/>
    <updated>2011-11-01T00:00:00+02:00</updated>
    <id>http://blog.y3xz.com/blog/2011/11/01/setting-up-an-iodine-ip-over-dns-proxy</id>
    <content type="html"><![CDATA[<p>Here&#8217;s a nice method to bypass any annoying wifi gateways, such as the ones
you find at hotels and airports. A prerequisite is that the gateway allows DNS
requests to be made.</p>

<p>Once we have that in the clear, we&#8217;ll need root access to a server with full
access to its DNS records. We&#8217;ll be using iodine and iodined on both sides of
the tunnel.</p>

<p>First of all, we&#8217;ll need to create the proper DNS records - we&#8217;re going to
need two of those, one would be a NS record for the DNS lookup, the second is
an A record to the server itself.</p>

<p>I&#8217;m using Amazon&#8217;s Route53 service with the most excellent
<a href="https://github.com/boto/boto">boto</a> command line tools, so I would do this:</p>

<pre><code>$ route53 add_record ZXXXXXXXXXXXXX iodine.domain.com. NS tunnel.domain.com. 259200 some_comment
$ route53 add_record ZXXXXXXXXXXXXX tunnel.domain.com. A 111.222.33.4 900 some_comment
</code></pre>

<p>It obviously doesn&#8217;t matter what tools you use, you just want these two DNS
records:</p>

<pre><code>iodine      IN  NS  tunnel.mydomain.com.
tunnel      IN  A   111.222.33.4
</code></pre>

<p>So now we have the DNS records set up. Now it&#8217;s time to install iodined on the
server. I&#8217;m using a standard Ubuntu server - and if it&#8217;s 11.04 and up, you&#8217;re
lucky because iodine has an apt package:</p>

<pre><code>sudo apt-get install iodine
</code></pre>

<p>By default, the service does not launch on startup, but that good since we
still need to configure it. The service config file is located at
<code>/etc/defaults/iodine</code>. Here you&#8217;ll want to set your <code>iodined</code> password and
any command line args. If you want, you can always set <code>iodined</code>&#8217;s run level -
to launch on startup - by using the <code>runlevel</code> tool.</p>

<p>Alternatively, you can always just run <code>iodined</code> from the command line in
foreground mode:</p>

<pre><code>iodined -f -P yourpassword 192.168.99.1 iodine.mydomain.com
</code></pre>

<p>The arguments you&#8217;re going to need are a password of your choice, an internal
IP that is not in use, and the tunnel domain to listen to. Last thing, you&#8217;re
going to want to make sure your firewall is open inbound to UDP requests on
port 53.</p>

<p>Once you have that you can go on to <a href="http://code.kryo.se/iodine/check-it">http://code.kryo.se/iodine/check-it</a>
and test your setup with the <code>iodine.mydomain.com</code> domain. If all is good you
can continue to install the client.</p>

<p>Last step, installing the client. I&#8217;m on a Mac with
<a href="http://mxcl.github.com/homebrew/">homebrew</a> installed, so again installing it
is kind of a breeze:</p>

<pre><code>sudo brew install iodine
</code></pre>

<p>Once that&#8217;s installed, launch the client:</p>

<pre><code>sudo iodine -P yourpassword iodine.mydomain.com
</code></pre>

<p>and if all is well you have just set up a fancy IP-over-DNS tunnel! For final
testing try to ping your server via the IP you gave it: <code>192.168.99.1</code>. Once
you have the tunnel you can start routing traffic through it. For this you&#8217;ll
probably want to establish a secure connection, preferably via SSH. Remember
that all DNS requests are non-secure and very easy to sniff over the network.</p>

<p>For further reference you can (should) check out the <a href="http://code.kryo.se/iodine/README.html">iodine README</a>.</p>

<h2>Pitfalls</h2>

<ul>
<li>Make sure you install the same iodine versions on both the client and the server. If you fail to do so you will get protocol errors. There is no backwards compatibility here.</li>
</ul>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Installing TL-WN722N on Ubuntu 11.10]]></title>
    <link href="http://blog.y3xz.com/blog/2011/10/23/installing-tl-wn722n-on-ubuntu-1110/"/>
    <updated>2011-10-23T00:00:00+02:00</updated>
    <id>http://blog.y3xz.com/blog/2011/10/23/installing-tl-wn722n-on-ubuntu-1110</id>
    <content type="html"><![CDATA[<p>I just finished installing the TL-WN722N TP-Link wiresless USB adapter on a
Ubuntu 11.10 machine. I started off with the instructions on
<a href="http://dwiel.net/blog/tp-link-tl-wn722n-on-ubuntu-10-04">http://dwiel.net/blog/tp-link-tl-wn722n-on-ubuntu-10-04</a> and at least for me the steps were much more simple.</p>

<p>All I needed to do was:</p>

<pre><code>$ wget http://www.orbit-lab.org/kernel/compat-wireless-2.6-stable/v2.6.38/compat-wireless-2.6.38.2-2.tar.bz2
$ tar xvf compat-wireless-2.6.38.2-2.tar.bz2
$ cd compat-wireless-2.6.38.2-2
$ ./scripts/driver-select ath9k_htc
$ sudo make
$ sudo make install
</code></pre>

<p>That&#8217;s pretty much it. I suspect other up-to-date versions of compat-wireless
will also do the trick, but for now - this does just fine.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Django @login_required decorator with 403]]></title>
    <link href="http://blog.y3xz.com/blog/2011/10/21/django-login_required-decorator-with-403/"/>
    <updated>2011-10-21T00:00:00+02:00</updated>
    <id>http://blog.y3xz.com/blog/2011/10/21/django-login_required-decorator-with-403</id>
    <content type="html"><![CDATA[<p>Django has a neat decorator called
<a href="https://docs.djangoproject.com/en/dev/topics/auth/#the-%0Alogin-required-decorator"><code>@login_required</code></a> which - when attached to a view - ensures that
<code>request.user</code> is logged in, and otherwise redirects the user to the login
page (as defined in <code>LOGIN_URL</code>).</p>

<p>However, in AJAX calls this has no meaning. In most applications, AJAX calls
should fail, preferably with a 403 (unauthorized) HTTP return code.
Interestingly enough, Django has no such decorator.</p>

<p>So I just took the regular Django <code>@login_required</code> and modified it to
immediately fail with 403 if the user is not authenticated. Enjoy -</p>

<div><script src='https://gist.github.com/1303651.js'></script>
<noscript><pre><code>try:
    from functools import update_wrapper, wraps
except ImportError:
    from django.utils.functional import update_wrapper, wraps  # Python 2.4 fallback.

from django.http import HttpResponseForbidden
from django.utils.decorators import available_attrs

def user_passes_test(test_func):
    def decorator(view_func):
        def _wrapped_view(request, *args, **kwargs):
            if test_func(request.user):
                return view_func(request, *args, **kwargs)
            return HttpResponseForbidden()
        return wraps(view_func, assigned=available_attrs(view_func))(_wrapped_view)
    return decorator

def login_required_403(function=None):
    actual_decorator = user_passes_test(
        lambda u: u.is_authenticated()
    )
    if function:
        return actual_decorator(function)
    return actual_decorator
</code></pre></noscript></div>



]]></content>
  </entry>
  
</feed>
