<?xml version="1.0" encoding="utf-8" ?><feed xmlns="https://www.w3.org/2005/Atom"><title>Matthew Scharley</title><link href="https://matt.scharley.me/" /><link href="https://matt.scharley.me/atom.xml" rel="self" /><updated>2017-12-04T07:16:19Z</updated><id>https://matt.scharley.me</id><author><name>Matthew Scharley</name><email>matt@scharley.me</email></author><entry><title>Software engineers and puzzle solvers</title><link href="https://matt.scharley.me/2016/05/software-engineers-puzzle-solvers.html?utm_source=atom&amp;amp;utm_medium=rss&amp;amp;utm_campaign=atom" /><updated>2016-05-01T04:23:00Z</updated><id>https://matt.scharley.me./src/posts/2016/software-engineers-puzzle-solvers.markdown</id><content type="html"><![CDATA[<p>I&rsquo;ve heard analogies in the past of programmers building applications being
like putting together a jigsaw puzzle&mdash;programming languages and libraries
being puzzle pieces slotted together. I think this is a pretty apt description
of things but I&rsquo;d like to take the analogy a few steps further.</p>

<h2>The puzzle</h2>

<p>Projects. We get them all the time. Each is a puzzle we lay out on the table
and look at and try to solve. All the pieces are different sizes and shapes.
Our jobs as engineers then is to pick the pieces that fit together the best
to create the shape we are aiming for.</p>

<p>More than ever application development isn&rsquo;t about creating something new,
it&rsquo;s about knowing what&rsquo;s available and fitting together the pieces that
already exist to create something novel.</p>

<h2>The pieces</h2>

<p>Frameworks. Libraries. Even entire languages, sometimes more than one of them,
get incorporated into our puzzle. Some pieces fit together well with other
pieces and sometimes two pieces just won&rsquo;t mesh together at all.</p>

<p>Groups of pieces tend to form particular shapes or patterns. We constantly keep
trying to fit different pieces together and inevitably make a few of our own
pieces to help fill in the gaps in the shape we&rsquo;re trying to form.</p>

<p><em>Except there&rsquo;s still something missing&hellip;</em></p>

<h2>The Big Picture</h2>

<p>Every jigsaw has a picture. It&rsquo;s usually the major point of the puzzle&mdash;put
together the jigsaw and then you can appreciate the pretty pictures you can see.</p>

<p>There&rsquo;s a pretty glaring problem here. All those pieces we mentioned; they are
pieces of other peoples puzzle. Pieces that we&rsquo;ve appropriated and melded into
our own puzzle. The puzzle is put together and has the right shape but the
picture is muddled. At best it is blank; the original authors foresaw this
problem and deliberately tried to avoid painting their own image on their
pieces. At worst we have an image that looks like a paint blot.</p>

<p>This concept applies at many levels&mdash;in application architecture where it
can feel like we&rsquo;re trying to paint all our pieces to fit what we need
<em>before</em> slotting them into place and praying for the best when we&rsquo;re done,
in UI design where it can be a literal image that&rsquo;s created by various
components in the system that may not work together very well, in UX where
disparate ideas and ideologies can create a system that is difficult to use.</p>

<p>As engineers it can be easy to lose sight of what we&rsquo;re creating. It&rsquo;s far too
easy to focus on the pieces of the puzzle and lose track of the picture we&rsquo;re
trying to create&mdash;focus on tools and processes instead of what we&rsquo;re using
them to create.</p>

<h2>The Small Picture</h2>

<p><em>Or, a treatise on modular design.</em></p>

<p>Extending the metaphor to breaking point, it&rsquo;s easier to solve many small
puzzles than one large puzzle. The common answer to this is black-box modules
whether this takes the form of a plugin system or a full-blown service-oriented
architecture.</p>

<p>From a human perspective this make a lot of sense. It&rsquo;s easier to solve small
well defined problems. It&rsquo;s easier to keep track of all the pieces and easier
to keep the whole picture in mind when there are fewer pieces forming a smaller
image.</p>
]]></content></entry><entry><title>How to install the rugged gem on Windows with libssh2 support.</title><link href="https://matt.scharley.me/2016/01/rugged-windows.html?utm_source=atom&amp;amp;utm_medium=rss&amp;amp;utm_campaign=atom" /><updated>2016-01-04T07:29:00Z</updated><id>https://matt.scharley.me./src/posts/2016/rugged-windows.markdown</id><content type="html"><![CDATA[<p>So, I&rsquo;ve recently spent a good part of my life trying to get the <code>rugged</code> gem working on Windows with libssh2 support
so that it can access remote repositories with SSH login credentials. I&rsquo;m documenting here the method that finally
worked out for me for my own reference and hopefully it helps someone else out as well.</p>

<h2>0. Install the DevKit</h2>

<p>If you don&rsquo;t already have it then <a href="http://rubyinstaller.org/downloads/">go grab the DevKit</a> and extract it somewhere. I personally highly
recommend injecting the variables from <code>devkitvars.ps1</code> into your <a href="https://superuser.com/questions/25037/change-environment-variables-as-standard-user">user accounts environment variables</a>
rather than using the scripts.</p>

<h2>1. Download and extract CMake into the DevKit.</h2>

<p>The first thing you&rsquo;ll need that doesn&rsquo;t come standard with the DevKit is CMake. This is a hard requirement of <code>rugged</code>
so go <a href="https://cmake.org/download/">grab the ZIP binary distribution from the CMake website</a>. It is unimportant that CMake only
release a 32 bit distribution for Windows. Extract the ZIP file into the DevKit folder. You should end up with a
<code>%RI_DEVKIT%\bin\cmake.exe</code> file if you&rsquo;ve done this step correctly.</p>

<h2>2. Download and extract pkg-config-lite into the DevKit.</h2>

<p>Next is another standard build tool, <code>pkg-config</code>. For ease of install we can just use pkg-config-lite which is good
enough for what we need here and has no extra dependencies. <a href="http://sourceforge.net/projects/pkgconfiglite/files/">You can download pkgconfiglite here.</a>
Just drop the single EXE file into your <code>%RI_DEVKIT%\bin</code> folder.</p>

<h2>3. Download latest release of libssh2.</h2>

<p><a href="http://libssh2.org/">Download the latest release of libssh2.</a> The download links are halfway down the page but don&rsquo;t really stand
out. Extract it somewhere &mdash; it doesn&rsquo;t really matter much where.</p>

<h2>4. Build libssh2.</h2>

<p>The trickiest part of building libssh2 is that you need to use mingw&rsquo;s <code>sh</code> and then mangle paths to keep mingw happy.
The prefix path you pass to configure should be the mingw version of <code>%RI_DEVKIT%</code>. I&rsquo;ve used my own path in the
commands below, but you should update it with the correct path for you.</p>

<p>Open a terminal and navigate to the folder you extracted libssh2 to and run the following commands:</p>

<pre><code class="console">$ sh
$ ./configure --prefix=/c/Ruby22-x64/DevKit-mingw64-64-4.7.2 --with-wincng --disable-shared
$ make &amp;&amp; make install
$ exit
</code></pre>

<h2>5. Fix prefix in <code>%RI_DEVKIT%\lib\pkg-config\libssh2.pc</code> to a Windows path.</h2>

<p>Open this file in your favourite text editor and modify the <code>prefix=</code> line back to a valid Windows-style path:</p>

<pre><code class="ini">prefix=c:/Ruby22-x64/DevKit-mingw64-64-4.7.2
</code></pre>

<h2>6. Compile rugged from source.</h2>

<blockquote>
<p>As of the time of writing (2016-01-04) <a href="libgit2/rugged#559">the master branch of rugged doesn&rsquo;t support libssh2 on Windows</a>.
I&rsquo;m working on getting this fix into master for everyone to enjoy.</p>
</blockquote>

<pre><code class="console">$ git clone https://github.com/mscharley/rugged.git mscharley-rugged -b windows-pkg-config
$ cd mscharley-rugged
$ git submodule init
$ git submodule update
$ gem build *.gemspec
$ gem install *.gem
</code></pre>

<h2>7. Test it out!</h2>

<pre><code class="ruby">#!/usr/bin/env ruby

require &#39;rugged&#39;

# Or your favourite SSH key...
ssh_key = File.expand_path(&#39;~/.ssh/id_rsa&#39;)
# Or a path to a repository on your computer.
repo = &#39;.&#39;

repo = Rugged::Repository.new(repo)
# You can parse the username out of the remote url, but it is required here.
creds = Rugged::Credentials::SshKey.new(username: &#39;git&#39;, privatekey: ssh_key)
repo.remotes[&#39;origin&#39;].fetch credentials: creds
</code></pre>
]]></content></entry><entry><title>Usmu, the new static site generator and my new website</title><link href="https://matt.scharley.me/2016/01/usmu-new-static-site-generator.html?utm_source=atom&amp;amp;utm_medium=rss&amp;amp;utm_campaign=atom" /><updated>2016-01-03T02:34:00Z</updated><id>https://matt.scharley.me./src/posts/2016/usmu-new-static-site-generator.markdown</id><content type="html"><![CDATA[<p>So, there&rsquo;s a new static site generator on the block. <a href="https://github.com/usmu/usmu">It&rsquo;s called Usmu and it&rsquo;s my answer to the likes of Jekyll.</a></p>

<p>Usmu is built from the ground up to be extensible and modifiable. It is not, as Jekyll is, designed to be used as a
secure public hosting solution though obviously the resultant HTML could safely be displayed via virtually any web
host.</p>

<p>I&rsquo;m also making a very real effort to get it supported everywhere. To date, Usmu core and all core plugins like the S3
uploader all work on both Linux and Windows and should work on OS X (but I don&rsquo;t have anything available to test with).
If there&rsquo;s a compatibility issue then it&rsquo;s a bug.</p>

<p>Usmu is a Tilt API client. This means that <a href="https://github.com/rtomayko/tilt#readme">it automatically supports any template type that Tilt supports</a>,
which is quite a lot. Out of the box Usmu ships with Slim for use with templates and Markdown via the redcarpet gem
(or Kramdown for the JRuby folks).</p>

<p><del>For the Github fans <a href="https://github.com/usmu/usmu/issues/33">there&rsquo;s already plans on making deploying to Github Pages simple</a>.</del> <a href="https://github.com/usmu/usmu-github-pages">Github Pages support is live!</a></p>

<p>If you&rsquo;re interested to see what an Usmu site looks like under the hood <a href="https://github.com/mscharley/mscharley.github.io">you can check out the source for this website</a>.</p>
]]></content></entry><entry><title>Introducing jekyll-compass</title><link href="https://matt.scharley.me/2014/01/introducing-jekyll-compass.html?utm_source=atom&amp;amp;utm_medium=rss&amp;amp;utm_campaign=atom" /><updated>2014-01-13T21:14:00Z</updated><id>https://matt.scharley.me./src/posts/2014/introducing-jekyll-compass.markdown</id><content type="html"><![CDATA[<p>That&rsquo;s right, <a href="https://github.com/mscharley/jekyll-compass">I wrote a plugin for Jekyll</a>. Jekyll is the static site generator I use for this very
website, and I was sick of orchestrating Compass around Jekyll. <a href="https://github.com/mscharley/jekyll-compass/blob/master/README.md">Now, Compass sings to my own tune</a>.
Specifically, this is a generator plugin for Jekyll which will take your directory of Sass or Compass files in a <code>_sass</code>
folder inside your source folder and output the results directly into your <code>_site</code> output folder. It will run
automatically whenever your site is built by Jekyll, so it will always be up to date. For example, a run of this site
might look like this:</p>

<pre><code class="console">$ jekyll build
Configuration file: D:/Websites/matt.scharley.me/_config.yml
            Source: D:/Websites/matt.scharley.me
       Destination: D:/Websites/matt.scharley.me/_site
Generating Compass: D:/Websites/matt.scharley.me/_sass =&gt; D:/Websites/matt.scharley.me/_site/css
identical _site/css/handheld.css
identical _site/css/ie8.css
identical _site/css/print.css
   remove images/sprites-s8bbc0e5b70.png
   create images/sprites-s8bbc0e5b70.png
identical _site/css/style.css

      Generating... done.
</code></pre>

<p>I originally created this plugin back just before Jekyll 1.3 was released but it&rsquo;s gone through a few spurts of growth
and I now feel it&rsquo;s up to public usage. So please, if you are using either Compass or plain Sass then please give this
plugin a shot. If you are using simple Sass, then this plugin will allow you to easily manage <code>@import</code> properly with
full partial support; and if you do decide to upgrade to Compass at some point, well, you already have you simply need
to start using it. It&rsquo;s worth it, I promise.</p>

<p><a href="https://github.com/mscharley/jekyll-compass/issues">Issues to the issue queue please</a>, but feel free to discuss this plugin below.</p>
]]></content></entry><entry><title>Creating Inline SVG backgrounds with PNG sprites as fallbacks using Compass</title><link href="https://matt.scharley.me/2013/11/compass-inline-svg-png-fallback-with-sprites.html?utm_source=atom&amp;amp;utm_medium=rss&amp;amp;utm_campaign=atom" /><updated>2013-11-02T07:21:00Z</updated><id>https://matt.scharley.me./src/posts/2013/compass-inline-svg-png-fallback-with-sprites.markdown</id><content type="html"><![CDATA[<p>Hey everyone, just thought I&rsquo;d share a quick mixin I created for this website while doing the new social media buttons.</p>

<pre><code class="scss">@import &#39;sprites/*.png&#39;;
@mixin svg-background($img) {
  .no-svg &amp; {
    @include sprites-sprite($img);
    background-size: auto auto;
  }
  background-image: inline-image($img + &quot;.svg&quot;);
  background-size: sprites-sprite-width($img) sprites-sprite-height($img);
}
</code></pre>

<p>So what does this little baby do? Well, it sets up a background image that is either an inline SVG image, or a segment
of a PNG sprite depending on the capabilities of your browser. All images live separately for easy editing and all
sizing is done automatically to the size of the png. This allows your master SVG image to be any size you wish. Compass
automatically handles stitching together a PNG sprite for us and also tackles inlining and encoding the SVG asset for
us as well.</p>

<p>This technique does rely on having something like <a href="http://modernizr.com/">Modernizr</a> available and doing at the very least SVG
detection so that we can automatically switch methods in CSS. Unfortunately this is required as some of the properties
conflict with each other such as <code>background-size</code> and <code>background-position</code>.</p>

<p><strong>Example usage:</strong></p>

<pre><code class="scss">a {
  width: 32px;
  height: 32px;
  display: block;
}

@each $site in github, bitbucket, google-plus, linkedin, stackoverflow, twitter {
  a.#{$site} {
    @include svg-background(quote($site));
  }
}
</code></pre>

<p><strong>Produces:</strong></p>

<pre><code class="css">.no-svg section#social a.github,
.no-svg section#social a.bitbucket,
.no-svg section#social a.google-plus,
.no-svg section#social a.linkedin,
.no-svg section#social a.stackoverflow,
.no-svg section#social a.twitter {
  background-image: url(&#39;/images/sprites-sfa80a12e72.png&#39;); background-repeat: no-repeat;
}

section#social a {
  width: 32px;
  height: 32px;
  display: block;
}
section#social a.github {
  background-image: url(&#39;data:image/svg+xml;base64,&lt;base64 string&gt;&#39;);
  background-size: 32px 32px;
}
.no-svg section#social a.github {
  background-position: 0 -32px;
  background-size: auto auto;
}
section#social a.bitbucket {
  background-image: url(&#39;data:image/svg+xml;base64,&lt;base64 string&gt;&#39;);
  background-size: 32px 32px;
}
.no-svg section#social a.bitbucket {
  background-position: 0 0px;
  background-size: auto auto;
}
/* etc... */
</code></pre>

<p>Thoughts? Comments? Leave them below. And now I have pretty social media links on the right hand side of the screen, so
please feel free to contact me there as well.</p>
]]></content></entry><entry><title>How to access your friends tweets on Twitter via RSS</title><link href="https://matt.scharley.me/2012/08/howto-access-rss-feed-your-friends-tweets-twitter.html?utm_source=atom&amp;amp;utm_medium=rss&amp;amp;utm_campaign=atom" /><updated>2012-08-14T01:19:00Z</updated><id>https://matt.scharley.me./src/posts/2012/howto-access-rss-feed-your-friends-tweets-twitter.markdown</id><content type="html"><![CDATA[<p>This is a quick note to get some information back out in the public that
was lost when I moved my website. Hopefully that won&rsquo;t happen again now.</p>

<p>Quite a while back now Twitter disabled simple authentication. Apparently 
there were lots of people using the Twitter API directly in a basic RSS 
reader and requiring OAuth broke those peoples use-case for the API.</p>

<p>I created a web application in PHP which handles the OAuth for you and
exposes a set of obfuscated URL&rsquo;s that you can access without any 
authentication from any device. Sadly I&rsquo;m not able to host a copy of this
any more, but <a href="https://bitbucket.org/mscharley/twitter-rss">the code is still freely available</a> and it 
doesn&rsquo;t take much to host it yourself.</p>
]]></content></entry><entry><title>How to find the path to git's workdir</title><link href="https://matt.scharley.me/2012/06/how-to-find-the-path-to-gits-workdir.html?utm_source=atom&amp;amp;utm_medium=rss&amp;amp;utm_campaign=atom" /><updated>2012-06-22T04:30:00Z</updated><id>https://matt.scharley.me./src/posts/2012/how-to-find-the-path-to-gits-workdir.markdown</id><content type="html"><![CDATA[<p>For a while now, I&rsquo;ve wanted to add git&rsquo;s working directory to my prompt. My work is such
that I have many similar git repositories on my PC (multiple installations of <a href="http://drupal.org/">Drupal</a>).
Often, I find myself wading through at least two of them at once which quickly leads to
confusion about which windows are in which project. Since forever, I&rsquo;ve had my projects
laid out in reasonable folders like <code>~/htdocs/project</code>, however I was lacking a good way
to get at that project name.</p>

<p><strong>Update:</strong> Since I wrote this post, I&rsquo;ve found a built-in command to do this. I now have both
methods aliased, since sometimes you don&rsquo;t want/need an error and you always want a folder name.</p>

<h2>The solution</h2>

<pre><code class="console">$ git config &#39;alias.workdir&#39; &#39;rev-parse --show-toplevel&#39;
$ git config &#39;alias.workdir-or-cwd&#39; &#39;!echo $PWD&#39;
$ git workdir
$ git workdir | xargs basename     # only get project name
</code></pre>

<p>Yep, it&rsquo;s that stupidly straightforward. Aliases are always run from the root of your
workdir so this will always work perfectly. Unfortunately, you can&rsquo;t simply try to read
<code>core.workdir</code> because that will only return something if it is explicitly set in 
<code>.git/config</code>. Hopefully this will help someone else out.</p>
]]></content></entry><entry><title>Logical equivalences and the Drupal States API</title><link href="https://matt.scharley.me/2012/05/logical-equivalences-and-the-drupal-states-api.html?utm_source=atom&amp;amp;utm_medium=rss&amp;amp;utm_campaign=atom" /><updated>2012-05-14T14:34:33Z</updated><id>https://matt.scharley.me./src/posts/2012/logical-equivalences-and-the-drupal-states-api.markdown</id><content type="html"><![CDATA[<p>We recently ran into a bug in our code with relation to the States API. We had
the following code:</p>

<pre><code class="php">&lt;?php
$form[&#39;field_activity_pymt_dets&#39;][&#39;#states&#39;] = array(
  &#39;visible&#39; =&gt; array(
    &#39;.form-item-field-activity-cost-und input[type=checkbox]:not(:first)&#39; =&gt; array(&#39;checked&#39; =&gt; true)
  ),
  &#39;required&#39; =&gt; array(
    &#39;.form-item-field-activity-cost-und input[type=checkbox]:not(:first)&#39; =&gt; array(&#39;checked&#39; =&gt; true)
  )
);
</code></pre>

<p>The problem with this code is rather simple. It&rsquo;s asking the States API to look at
many checkboxes and show/require the current field if any single one of these is
checked. Due to a limitation of jQuery, and by extension the States API, this doesn&rsquo;t
actually work out. When this code is used on the client side the selector will be
executed, but only the value for the first element will be used when retrieving values
as per normal jQuery results.</p>

<p>So, how to convert this so that it works? We have two related issues here:</p>

<ol>
<li> Each checkbox must be addressed individually</li>
<li> The States API only provides an <code>AND</code> relationship, there is no way to specify that
you want an <code>OR</code> style comparison. This means that we can&rsquo;t simply expand the 
selector given; that would require all checkboxes to be checked, not any single one.</li>
</ol>

<p>Well, the solution is to invert the logic so that there is an <code>AND</code> relationship in
effect. Hence, the following resultant code:</p>

<pre><code class="php">&lt;?php
$options_lang = $form[&#39;field_activity_cost&#39;][&#39;#language&#39;];
$options = array_keys($form[&#39;field_activity_cost&#39;][$options_lang][&#39;#options&#39;]);
array_shift($options); // Drop the first option on the floor because we don&#39;t care about it (free).

foreach ($options as $id) {
  $selector = &#39;:input#edit-field-activity-cost-&#39;.$options_lang.&#39;-&#39;.$id;
  $form[&#39;field_activity_pymt_dets&#39;][&#39;#states&#39;][&#39;invisible&#39;][$selector] = array(&#39;unchecked&#39; =&gt; true);
  $form[&#39;field_activity_pymt_dets&#39;][&#39;#states&#39;][&#39;optional&#39;][$selector] = array(&#39;unchecked&#39; =&gt; true);
}
</code></pre>

<p>This does the same thing, but works slightly more counterintuitively. <code>Make visible if any
one of these is checked</code> is the same as <code>Make invisible if all of these are unchecked</code>.</p>
]]></content></entry><entry><title>Using PulseAudio and multiple sound devices</title><link href="https://matt.scharley.me/2012/03/pulseaudio-and-multiple-sound-devices.html?utm_source=atom&amp;amp;utm_medium=rss&amp;amp;utm_campaign=atom" /><updated>2012-04-11T05:44:02Z</updated><id>https://matt.scharley.me./src/posts/2012/pulseaudio-and-multiple-sound-devices.markdown</id><content type="html"><![CDATA[<p><strong>DISCLAIMER</strong>: Most of this post was cobbled together from this <a href="http://superuser.com/q/182149/5313">related question on Super User</a>,
but I had some extra flavour of my own to add. If you found this useful, you should
jump over there and vote them up too.</p>

<p>PulseAudio does support using multiple devices at the same time, but when I bought my
speakers the other day, I had trouble finding documentation that said much more than
that it was supported.</p>

<h2>The Problem</h2>

<p>I have a nice set of 2.1 speakers that I wish to use for almost everything, but I use
Skype and Mumble for VOIP with various people, and I want to use my headset with those
applications. Skype in particular will only let you chose &ldquo;PulseAudio&rdquo; if it detects
that PulseAudio is available.</p>

<h2>The Solution</h2>

<p>PulseAudio allows you to control input and output devices on a per-application basis,
but as far as I&rsquo;ve found, it only lets you control these through setting environment
variables; <code>PULSE_SINK</code> and <code>PULSE_SOURCE</code>. You can get values for these variables
from the following command lines:</p>

<pre><code class="console">$ LANG=C pactl list | grep -A2 &#39;Source #&#39; | grep &#39;Name: &#39; | cut -d&quot; &quot; -f2
$ LANG=C pactl list | grep -A2 &#39;Sink #&#39; | grep &#39;Name: &#39; | cut -d&quot; &quot; -f2
</code></pre>

<p>Using the info from the above commands, I made the following script:</p>

<pre><code class="sh">#!/bin/sh
# ~/bin/pa-headphones

export PULSE_SINK=&quot;alsa_output.usb-045e_Microsoft_LifeChat_LX-3000-00-LX3000.iec958-stereo&quot;
export PULSE_SOURCE=&quot;alsa_output.usb-045e_Microsoft_LifeChat_LX-3000-00-LX3000.iec958-stereo.monitor&quot;

# Export a normalish PATH so `which` doesn&#39;t pick up this script
export PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin

exec $(which $(basename $0)) $*
</code></pre>

<p>I can then create as many symlinks to this script in my <code>~/bin</code> directory as I like
and they will all use my headset for sound input and output. So, for instance:</p>

<pre><code class="console">$ cd ~/bin
$ ln -s pa-headphones skype
</code></pre>

<p>And now, whenever skype is run it will use my headphones. This will also work for
<code>.desktop</code> shortcuts, as long as they don&rsquo;t use absolute paths to find their
executables. Most system-installed ones don&rsquo;t seem to, on Gentoo at least.</p>
]]></content></entry><entry><title>Debugging UNIX sockets with socat</title><link href="https://matt.scharley.me/2012/03/debugging-application-interactions-with-socat.html?utm_source=atom&amp;amp;utm_medium=rss&amp;amp;utm_campaign=atom" /><updated>2012-03-23T03:41:01Z</updated><id>https://matt.scharley.me./src/posts/2012/debugging-application-interactions-with-socat.markdown</id><content type="html"><![CDATA[<p>A while ago, I came across an interesting problem: how do you listen in on
UNIX sockets? For IP, there are tools like wireshark that will display in
great detail all the network traffic that go through your system, but these
tools can&rsquo;t listen in on UNIX sockets.</p>

<h2>Introducing socat</h2>

<p>So, what is <code>socat</code>?</p>

<blockquote>
<p><strong>Socat</strong> is a command line based utility that establishes two bidirectional
byte streams and transfers data between them. Because the streams can be
constructed from a large set of different types of data sinks and sources
(see address types), and because lots of address options may be applied to
the streams, socat can be used for many different purposes.</p>

<p><cite><a href="http://www.dest-unreach.org/socat/doc/socat.html">socat manpage</a></cite></p>
</blockquote>

<p>In other words, socat sits in the middle of two different sources of IPC
and passes data between them. I use the term IPC because <code>socat</code> understands
so many different formats that it is a little rediculous. It can process and
translate between the following formats (not even close to 
<a href="http://www.dest-unreach.org/socat/doc/socat.html#ADDRESS_CREAT">a comprehensive list</a>):</p>

<ul>
<li>TCP with or without SSL</li>
<li>UNIX sockets</li>
<li>regular files</li>
<li>stdin/stdout of another process</li>
</ul>

<p>As you can see, it&rsquo;s very flexible. It also supports logging all traffic that
flows through it. Which brings us back to our original point.</p>

<h2>Debugging UNIX sockets</h2>

<p>UNIX sockets are great for all sorts of reasons, including ensuring that they
are only available locally. However, this also means that they are hard to
listen in on and debug. So, enter <code>socat</code>:</p>

<pre><code class="console">$ socat -v UNIX-LISTEN:/tmp/socat-listen UNIX-CONNECT:/path/to/real.socket
</code></pre>

<p>Now, point the client application at <code>/tmp/socat-listen</code> instead of the real
socket and enjoy the conversation.</p>

<p>Or, if you wish to provide your own test data rather than simply listening in:</p>

<pre><code class="console">$ socat -v READLINE UNIX-CONNECT:/path/to/real.socket
</code></pre>

<p>With this, <code>socat</code> will use readline to get data from the console, and print
back any replies.</p>

<h2>In closing</h2>

<p>Obviously, this is only one way to use <code>socat</code>. It&rsquo;s a very powerful application,
and can be put to lots of good uses. This is just one of the more obscure things
you can do with it. You could even use it as a telnet replacement if you really
wanted to with the second example. You should explore the <a href="http://www.dest-unreach.org/socat/doc/socat.html">man page</a>
to get other cool ideas.</p>
]]></content></entry><entry><title>Using script elements for JavaScript config</title><link href="https://matt.scharley.me/2012/03/using-script-elements-for-javascript-config.html?utm_source=atom&amp;amp;utm_medium=rss&amp;amp;utm_campaign=atom" /><updated>2012-03-15T04:56:52Z</updated><id>https://matt.scharley.me./src/posts/2012/using-script-elements-for-javascript-config.markdown</id><content type="html"><![CDATA[<p>Just a few words to get something interesting out there that I saw today.</p>

<p>The following sparked some ideas in me. I&rsquo;ll probably post up a few things about
how to actually use this sort of thing in your own scripts, after I figure it out
myself. For now, I wanted to get this out there, because it&rsquo;s kind of cool.</p>

<pre><code class="html">&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
  tex2jax: {inlineMath: [[&#39;$&#39;,&#39;$&#39;], [&#39;\\(&#39;,&#39;\\)&#39;]]}
});
&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;path-to-mathjax/MathJax.js?config=TeX-AMS-MML_HTMLorMML&quot;&gt;&lt;/script&gt;
</code></pre>
]]></content></entry><entry><title>Windows, Cygwin and Jekyll</title><link href="https://matt.scharley.me/2012/03/windows-cygwin-and-jekyll.html?utm_source=atom&amp;amp;utm_medium=rss&amp;amp;utm_campaign=atom" /><updated>2014-03-10T13:56:00Z</updated><id>https://matt.scharley.me./src/posts/2012/windows-cygwin-and-jekyll.markdown</id><content type="html"><![CDATA[<h2>A bit of background</h2>

<p>My main computer is a dual-boot Gentoo/Windows 7 box. I use Linux for work, and most
of my every day stuff. Windows is mainly just for games and certain other members of
the household.  I&rsquo;ve also recently reformatted, so both are near-clean slates.</p>

<h2>Enter the Jekyll blog</h2>

<p>Jekyll is a great system. It fits well into that &ldquo;just enough&rdquo; category. My last blog 
was a Drupal blog, but I used Markdown to write all my posts. It always struck me as
a very elegant way to edit HTML. With a good text editor that has some color coding
for formatting, you barely notice the difference&hellip; except you can&rsquo;t screw up the tags.
As someone who works in the web industry, I regularly see and use CKEditor, and also
regularly see it chew up code from <a href="http://en.wikipedia.org/wiki/Microsoft_Word">a certain Microsoft product</a> that clients
love and spit out HTML that wreaks havoc on designs. Markdown and similar systems like
Textile always produce very predictable results, and you can tell at a glance what
those results will be.</p>

<p>And so, tonight I got onto my computer, and it was booted into Windows. I wanted to
hack on my blog for a bit. So I did what every Linux guy does first in Windows: 
<a href="http://www.cygwin.com/">Cygwin</a> and ConEmu. Now, before I go any further, please don&rsquo;t misunderstand;
I love Cygwin. In much the same way that I love beating my head against a wall, because 
it&rsquo;s often much the same feeling. However I do have a great respect for the people behind
this project, because it&rsquo;s a great project, and when it&rsquo;s setup and working, it
really is a wonderful things to have around.</p>

<h2>How to get Jekyll working on Cygwin</h2>

<p>First, a list of things you will need, in order. If you can follow this list on your
own, then the rest of this article should be redundant.</p>

<ul>
<li>  <a href="http://www.cygwin.com/">Cygwin</a>, optionally <a href="https://github.com/Maximus5/ConEmu#readme">ConEmu</a> or <a href="http://sourceforge.net/projects/console/">Console2</a>

<ul>
<li>  Devel

<ul>
<li>gcc4</li>
<li>gcc4-g++</li>
<li>git</li>
<li>make</li>
</ul></li>
<li>  Libs

<ul>
<li>libiconv</li>
<li>libiconv2</li>
<li>zlib</li>
</ul></li>
<li>  Net

<ul>
<li>curl</li>
</ul></li>
<li>  Python

<ul>
<li>python (only if you need/want Pygments)</li>
</ul></li>
</ul></li>
<li>  <a href="http://rvm.io/">RVM</a>

<ul>
<li>ruby-2.*</li>
</ul></li>
<li>  jekyll gem - from rubygems</li>
<li>  Python <a href="http://peak.telecommunity.com/dist/ez_setup.py">setuptools</a></li>
<li>  <a href="http://pygments.org/download/">Pygments</a></li>
</ul>

<p>First, install Cygwin with the above packages by using the <code>setup.exe</code> executable
available on their homepage. It&rsquo;s important to get both <code>iconv</code> <em>and</em> <code>iconv2</code>. If
you don&rsquo;t, then RVM will happily and silently compile ruby without iconv support, and
then Jekyll will happily install but promptly fall on it&rsquo;s face when you try to run
it.</p>

<p>Oops.</p>

<p>Next on the list is <a href="http://rvm.io/">RVM</a>. There&rsquo;s installation instructions on their homepage,
but it boils down to the following:</p>

<pre><code class="console">$ curl -L https://get.rvm.io | bash -s stable --ruby
$ source ~/.rvm/scripts/rvm
</code></pre>

<p>From here you can happily <code>gem install jekyll</code>, and it should just fall into place. There used to be issues with the
<code>posix-spawn</code> gem which necessitated it being installed from source, but that fix finally made it&rsquo;s way into a rubygems
release. At this point you should have a working Jekyll installation. If you want or need pygments support, then
installing it is simple, you just need to install setuputils manually first.</p>

<pre><code class="console">$ curl -L http://peak.telecommunity.com/dist/ez_setup.py | python
$ easy_install Pygments
</code></pre>

<p>And we&rsquo;re done at this point. Congratulations! You can now edit your Jekyll blog on
Windows using the latest version of Jekyll.</p>
]]></content></entry><entry><title>[JS] HOWTO: Monkey patch IE for support for Function.name</title><link href="https://matt.scharley.me/2012/03/monkey-patch-name-ie.html?utm_source=atom&amp;amp;utm_medium=rss&amp;amp;utm_campaign=atom" /><updated>2012-06-08T12:49:00Z</updated><id>https://matt.scharley.me./src/posts/2012/monkey-patch-name-ie.markdown</id><content type="html"><![CDATA[<p>One of the better <a href="https://stackoverflow.com/a/332429/15537">ways of detecting an object&rsquo;s type name in Javascript</a>
is <code>obj.constructor.name</code>. It&rsquo;s also the way that the Drupal states API does it.
Unfortunately, Internet Explorer doesn&rsquo;t support the non-standardised, though
rather standard <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/name"><code>Function.name</code></a> property.</p>

<p>So, here&rsquo;s how to monkey patch it into IE9 and above. IE8 doesn&rsquo;t support
<a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object/defineProperty"><code>defineProperty</code></a> properly and earlier versions don&rsquo;t support 
it at all so those versions are still unsupported by this method.</p>

<pre><code class="javascript">/**
 * Hack in support for Function.name for browsers that don&#39;t support it.
 * IE, I&#39;m looking at you.
**/
if (Function.prototype.name === undefined &amp;&amp; Object.defineProperty !== undefined) {
    Object.defineProperty(Function.prototype, &#39;name&#39;, {
        get: function() {
            var funcNameRegex = /function\s([^(]{1,})\(/;
            var results = (funcNameRegex).exec((this).toString());
            return (results &amp;&amp; results.length &gt; 1) ? results[1].trim() : &quot;&quot;;
        },
        set: function(value) {}
    });
}
</code></pre>
]]></content></entry><entry><title>Hello World!</title><link href="https://matt.scharley.me/2012/03/initial-post.html?utm_source=atom&amp;amp;utm_medium=rss&amp;amp;utm_campaign=atom" /><updated>2012-03-07T14:00:00Z</updated><id>https://matt.scharley.me./src/posts/2012/initial-post.markdown</id><content type="html"><![CDATA[<p>Everyone writes one of these, right? Welcome, welcome, yada yada, all that sort of thing.</p>

<p>First up, I want to get into what this blog will be about. This site will mostly be a
coding blog; things I&rsquo;ve done, discovered or otherwise cool stuff to do with the 
inside of a computer. However, I am also human! Shocking, I know. Every now and then 
I will almost certainly deviate into other things; gaming, other hobbies I have, the 
local flora, etc.</p>

<p>Secondly, welcome! Feel free to pull apart the <a href="https://github.com/mscharley/mscharley.github.io">buildings of this blog</a>. All
content I have written is CC-BY-NC-SA, and all the code is released under the MIT
license. That includes the system I&rsquo;ve written on top of Jekyll for writing this blog,
the CSS, the HTML, and any code snippets released as part of this blog. Go forth, fork
and enjoy.</p>

<p>I intend to prod Disqus with a 10&quot; pole and perhaps get that integrated into this site.</p>

<p>Or perhaps not (looks like I did though).</p>

<p>Better navigation and more features will be forthcoming, but I wanted to get a v1.0 up
as soon as possible so I can get back into this. I really enjoyed it last time around,
and hopefully you&rsquo;ll find something of use here.</p>
]]></content></entry></feed>
