<?xml version='1.0'?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel><title>Peter Stuifzand weblog</title>
<link>http://peterstuifzand.nl</link>
<atom:link href="http://peterstuifzand.nl/rss.xml" rel="self" type="application/rss+xml" />
<description>Programming, internet, vim, cooking and making video's</description>
<cloud domain='cloud.stuifzand.eu' port='5337' path='/rsscloud/pleaseNotify' registerProcedure='' protocol='http-post' />
<item>
<guid>http://peterstuifzand.nl/2013/06/09/create-your-own-youtube-playlists.html</guid>
<title>Create your own YouTube playlists</title>
<description>&lt;p&gt;A few days ago Mindcrack Ultra Hardcore season 11 started. In Ultra Hardcore the play
by special rules, that are different from vanilla Minecraft. The biggest
difference is that players don't regenerate health automatically. They need to
eat golden apples to increaes their health. These apples are harder to make,
because you need golden ingots instead of golden nuggets.&lt;/p&gt;

&lt;p&gt;Each season players record videos of their perspective of the match and post
these videos to their YouTube channel. This season these videos are posted
every other day around 22:00 UTC. This is mostly to give viewers the
opportunity to watch multiple perspectives. The total running time for the
first episode was about 7 hours. That's a lot of video to watch.&lt;/p&gt;

&lt;p&gt;At the moment the best way to watch these videos is to subscribe to a channel
and follow along whenever a video is posted. The problem (for me) is that these
players post many other videos of games that I don't like to watch. There also
isn't a place where these videos are linked in one place. To remedy this
problem I wrote a few programs that create the playlists automatically.&lt;/p&gt;

&lt;p&gt;Let's start with the output. The program created a few playlists on YouTube
from the videos that I gathered from the channel. I created two views into the
videos.&lt;/p&gt;

&lt;p&gt;The first view is the list of videos for &lt;strong&gt;each player&lt;/strong&gt;. Each player has
a playlist with all the videos in episode order. For example the playlist for
&lt;a href=&quot;https://www.youtube.com/playlist?list=PLXPnuCeTMV5Fkf3YaMygDbPEGanz-8OBE&quot;&gt;Zisteau&lt;/a&gt;. There is also a playlist for the other players.&lt;/p&gt;

&lt;p&gt;The second view is a list of all videos in &lt;strong&gt;each episode&lt;/strong&gt;. This means that
the videos happened around the same 20 minutes of play time. For example all
videos from &lt;a href=&quot;https://www.youtube.com/playlist?list=PLXPnuCeTMV5EC83O7S55fg4Lx6Sk2Li6S&quot;&gt;episode 1&lt;/a&gt;. The other episodes are also available.&lt;/p&gt;

&lt;p&gt;To create these playlists I wrote three Perl scripts. The first one gets the
latest episodes for each players. This way I get a list of the last videos of
the channel. This list contains all videos, also videos that I don't want to
add to the playlist.&lt;/p&gt;

&lt;p&gt;In the next step (with the other two scripts) I parse the titles of the videos
and find the videos that match the regular expressions for UHC or Ultra
Hardcore and Season 11. Here I also try to find the episode number of the
video.&lt;/p&gt;

&lt;p&gt;Next I create a playlist or find the playlist_id of the episode (or player) and
add all the videos that haven't been added yet.&lt;/p&gt;

&lt;p&gt;Now we're done. I used the &lt;a href=&quot;https://metacpan.org/module/WebService::GData::YouTube&quot;&gt;WebService::GData::Youtube&lt;/a&gt; module for calling
the YouTube API, as it removes most of the dirty work.&lt;/p&gt;</description>
<link>http://peterstuifzand.nl/2013/06/09/create-your-own-youtube-playlists.html?utm_campaign=rss&amp;utm_source=rss&amp;utm_medium=rss</link>
<pubDate>Sun, 09 Jun 2013 14:40:00 +0100</pubDate>
</item>
<item>
<guid>http://peterstuifzand.nl/2013/06/03/20130603111548.html</guid>
<description>&lt;p&gt;&lt;a href=&quot;http://waterpigs.co.uk/notes/1480&quot;&gt;Barnaby Walters&lt;/a&gt; wrote:&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;build stuff which kills your own FB usage before trying to kill facebook.&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;That seems to be a good way to build software that fills a real need.&lt;/p&gt;</description>
<link>http://peterstuifzand.nl/2013/06/03/20130603111548.html?utm_campaign=rss&amp;utm_source=rss&amp;utm_medium=rss</link>
<pubDate>Mon, 03 Jun 2013 11:15:00 +0100</pubDate>
</item>
<item>
<guid>http://peterstuifzand.nl/2013/05/06/load-firefox-search-in-background-tab.html</guid>
<title>Load Firefox search in background tab</title>
<description>&lt;p&gt;Today I noticed something that bothered me. When I search in Firefox through
the right-click context menu the search results open in a new tab and
Firefox switches automatically to the new page. I remembered there is option
that makes Firefox open new links in the background and I thought that maybe
this option was disabled. The option was enabled as it should be.&lt;/p&gt;

&lt;p&gt;I opened a few links and it behaved as expected. The search results however
still opened in a new tab in the foreground. This was unexpected. For me it
seems that links and searches should open in a new tab in the background.&lt;/p&gt;

&lt;p&gt;So I started a search for this behaviour. I found a bug from the Mozilla
Bugzilla database &lt;a href=&quot;https://bugzilla.mozilla.org/show_bug.cgi?id=695482&quot;&gt;Bug 695482&lt;/a&gt; that seemed to call for the
reverse of what I expected. There seem to be some strong arguments for this
behaviour. There are even some that tests the suggest that the majority of
people click on the new tab within 5 seconds of starting the search. I don't
think this a what I do. I am lucky that some people some disagree with this
behaviour. These people created &lt;a href=&quot;https://bugzilla.mozilla.org/show_bug.cgi?id=727131&quot;&gt;Bug 727131&lt;/a&gt; that calls for the
about:config option &lt;code&gt;browser.search.context.loadInBackground&lt;/code&gt; that makes
searches open in a background tab.&lt;/p&gt;

&lt;p&gt;I enabled the option now and will try it some.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://bugzilla.mozilla.org/show_bug.cgi?id=695482&quot;&gt;Bug 695482 - &quot;Search Google for &lt;selection&gt;&quot; should open in the foreground,
not be governed by loadInBackground preference&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://bugzilla.mozilla.org/show_bug.cgi?id=727131&quot;&gt;Bug 727131 - Pref needed to allow &quot;Search Google for&quot; tabs to open in
background&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</description>
<link>http://peterstuifzand.nl/2013/05/06/load-firefox-search-in-background-tab.html?utm_campaign=rss&amp;utm_source=rss&amp;utm_medium=rss</link>
<pubDate>Mon, 06 May 2013 13:53:00 +0100</pubDate>
</item>
<item>
<guid>http://peterstuifzand.nl/2013/04/22/a-universal-subscribe-button.html</guid>
<title>A universal subscribe button</title>
<description>&lt;p&gt;&lt;a href=&quot;https://www.subtome.com/&quot;&gt;SubToMe&lt;/a&gt; is a universal subscribe button that you can add to your
weblog. You just add small bit of HTML that shows a subscribe button. The
software is written in Javascript and runs in your browser. It doesn't need a
central server. Take a look and add it to your weblog.&lt;/p&gt;</description>
<link>http://peterstuifzand.nl/2013/04/22/a-universal-subscribe-button.html?utm_campaign=rss&amp;utm_source=rss&amp;utm_medium=rss</link>
<pubDate>Mon, 22 Apr 2013 17:24:00 +0100</pubDate>
</item>
<item>
<guid>http://peterstuifzand.nl/2013/04/22/changes-to-the-heredoc-parser-example.html</guid>
<title>Changes to the heredoc parser example</title>
<description>&lt;p&gt;Jeffrey Kegler, the author of Marpa, was kind enough to suggest a few changes to the
parser from the &lt;a href=&quot;http://peterstuifzand.nl/2013/04/19/parse-a-heredoc-with-marpa.html&quot;&gt;previous blog post&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Two of the three regular expressions were replaced with calls to the Marpa
recognizer. The first one was replaced with a call to the &lt;code&gt;pause_span&lt;/code&gt; method,
which returns the start and length of the lexeme that caused the pause. Passing
these two values to the &lt;code&gt;literal&lt;/code&gt; method which returns the substring from the
input string. This removes the need to mess around with the &lt;code&gt;pos()&lt;/code&gt; from the
input string.&lt;/p&gt;

&lt;p&gt;The second regular expression that was replaced is the one that matches the
newline. There is no need to match with this regex, because we already know at
which lexeme the parser was paused with a call to the &lt;code&gt;pause_lexeme&lt;/code&gt; method.
This method will return 'newline' when that parser found a newline. We only
need to &lt;code&gt;resume&lt;/code&gt; the parser in the right position.&lt;/p&gt;

&lt;p&gt;These two changes makes the code simpler, because we don't have to change the
&lt;code&gt;pos()&lt;/code&gt; for the input string every time we want to match with the regexes.&lt;/p&gt;</description>
<link>http://peterstuifzand.nl/2013/04/22/changes-to-the-heredoc-parser-example.html?utm_campaign=rss&amp;utm_source=rss&amp;utm_medium=rss</link>
<pubDate>Mon, 22 Apr 2013 16:31:00 +0100</pubDate>
</item>
<item>
<guid>http://peterstuifzand.nl/2013/04/19/parse-a-heredoc-with-marpa.html</guid>
<title>Parse a heredoc with Marpa</title>
<description>&lt;p&gt;I already wrote that I'm quite interested in the things Marpa can do for
writing parsers. &lt;a href=&quot;https://metacpan.org/release/Marpa-R2&quot;&gt;The latest release of Marpa&lt;/a&gt; includes an addition that makes
parsing strange languages even more possible. The new functionality allows you
to control the parser from your own code while it doesn't stop you from using
the internal scanner.&lt;/p&gt;

&lt;p&gt;To try out this new functionality in Marpa I tried to write a parser for a
small language with just one function and heredocs. I choose this language,
because it can't be parsed with just the internal scanner. The scanner needs to
find the end marker with the same name as the begin marker of the heredoc. The
parser doesn't know about the name of the marker, just that it looks like a
marker.&lt;/p&gt;

&lt;p&gt;The code is in a &lt;a href=&quot;http://github.com/pstuifzand/demo-heredoc-parser&quot;&gt;repository&lt;/a&gt;
on github. I will talk about the &lt;a href=&quot;https://github.com/pstuifzand/demo-heredoc-parser/blob/master/lib/Demo/Heredoc/Parser.pm#L25,L36&quot;&gt;lines&lt;/a&gt; containing the expression,
heredoc and lexemes. The comments in the file explain what happens. The tests
in the &lt;code&gt;t&lt;/code&gt; directory show a few ways in which we can combine the heredocs in
statements and expressions.&lt;/p&gt;

&lt;p&gt;The moment the parser finds a beginning of a heredoc it pauses and passes
control to the parser. Where the parser is paused can be controlled by the
&lt;code&gt;:lexeme&lt;/code&gt; rule and the &lt;code&gt;pause&lt;/code&gt; adverb.&lt;/p&gt;

&lt;p&gt;The external scanner first finds the end of the line where the beginning of the
heredoc was found. This is the position where the text of the heredoc will
begin. Then it will find the name of the marker. If it found the name it will
try to find the marker at the beginning of one of the following lines. The
marker and the literal will be send to the parser with the two calls to the
&lt;code&gt;lexeme_read&lt;/code&gt; method. Then it moves the &lt;code&gt;$last_heredoc_end&lt;/code&gt; to the end of the
line of text and the position of the input string to the position after the
beginning of the marker and passes control back to the parser with a call to
the &lt;code&gt;resume&lt;/code&gt; method.&lt;/p&gt;

&lt;p&gt;The program will do this until the parser pauses again at the end of the line.
Then it moves the position of the parser to the end of the possibly multiple
heredocs. The repeats until the end of the input is reached.&lt;/p&gt;

&lt;p&gt;I was impressed with how short the code is and how easy it was to parse
heredocs and pass control back and forth between the internal and external
scanner. This allows for many new ways to parse text for all kinds of
languages.&lt;/p&gt;</description>
<link>http://peterstuifzand.nl/2013/04/19/parse-a-heredoc-with-marpa.html?utm_campaign=rss&amp;utm_source=rss&amp;utm_medium=rss</link>
<pubDate>Fri, 19 Apr 2013 18:13:00 +0100</pubDate>
</item>
<item>
<guid>http://peterstuifzand.nl/2013/04/08/apps-that-share.html</guid>
<title>Apps that share</title>
<description>&lt;p&gt;On my phone I can share stuff between apps. It's like pipes. I write something
in one app and send it to another app that posts it to my weblog. The apps in
question are Draft and WordPress. It shows how easy it is to send stuff between
apps. The apps don't even have to know the other app exist. Why is this easier
on my phone than on my PC?&lt;/p&gt;</description>
<link>http://peterstuifzand.nl/2013/04/08/apps-that-share.html?utm_campaign=rss&amp;utm_source=rss&amp;utm_medium=rss</link>
<pubDate>Mon, 08 Apr 2013 12:27:00 +0100</pubDate>
</item>
<item>
<guid>http://peterstuifzand.nl/2013/03/11/grok.html</guid>
<title>Grok</title>
<description>&lt;p&gt;In this video &lt;a href=&quot;http://www.youtube.com/watch?v=KTJs-0EInW8&quot;&gt;Steve Yegge talks about a
project&lt;/a&gt; he's working on called
Grok. I seems ambitious and useful.&lt;/p&gt;

&lt;p&gt;I worked on a few parsers in the last few months and it seems that most of the
work still has to be done even if you've got a parse tree of a language.&lt;/p&gt;

&lt;p&gt;Yegge explains that they don't write the parsers themselves, but use the work
compiler builders have done. This is a good idea, because writing a parser
isn't easy, even if you have a really good tools to build a parser with.&lt;/p&gt;

&lt;p&gt;After you have a parse tree you still need to generate code or evaluate the
tree to do the actual work.&lt;/p&gt;

&lt;p&gt;It's the same problem you have when you're parsing HTML: why would you write
that code (badly) when someone else already did it for you?&lt;/p&gt;

&lt;p&gt;You have a piece of HTML you want to use some part of. You start with regexes
and &lt;a href=&quot;http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454&quot;&gt;people start yelling&lt;/a&gt; at you for using the wrong tool for
the job. So you move on to a better tool.&lt;/p&gt;

&lt;p&gt;That's all well and good when you want to parse HTML (I would use
&lt;a href=&quot;https://metacpan.org/module/Marpa::R2::HTML&quot;&gt;Marpa::R2::HTML&lt;/a&gt;), but what if you would like to parse C,
Javascript or my language of choice, Perl. It would be the same (but better)
madness to write a grammar and parser for those languages.&lt;/p&gt;

&lt;p&gt;If I need to &lt;a href=&quot;https://github.com/pstuifzand/go-marpa-thin/tree/master/perl&quot;&gt;parse a few lines of C function declarations&lt;/a&gt;, I
would start with a small regex, fail and move on to a combination of regexes,
an ad-hoc state machine and an actual parser. When you have an actual parser in
your toolbox you can take on more problems. It's not always the right tool. But
I will try it first the next time I need to mangle and transmute text, even
before I start with the regexes.&lt;/p&gt;

&lt;p&gt;There is a need for parse Javascript and C and general tools to work with them.
Parse a Javascript file and list the function names.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;use Parse::Javascript;
my $file = Parse::Javascript-&amp;gt;parse($js_file);
say $_-&amp;gt;name for $file-&amp;gt;functions;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Or the same for C.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;use Parse::C;
my $file = Parse::C-&amp;gt;parse($c_file);
say $_-&amp;gt;name for $file-&amp;gt;functions;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Or change all function calls the match one thing and change them to another thing.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;use Refactor 'refactor';
my $refactored_file = refactor($file, 'compare(@a, @b) == 0', 'equal(@a, @b)');
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Or how about this create C code from a Javascript AST?&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;my $c_file = Serialize::C-&amp;gt;serialize($js_ast);
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Or as Steve Yegge says creating a parser (with semantics), code generator,
tools and all that is a life's work. Maybe we should try to make that easier?&lt;/p&gt;</description>
<link>http://peterstuifzand.nl/2013/03/11/grok.html?utm_campaign=rss&amp;utm_source=rss&amp;utm_medium=rss</link>
<pubDate>Mon, 11 Mar 2013 13:02:00 +0100</pubDate>
</item>
<item>
<guid>http://peterstuifzand.nl/2013/01/29/diy-refactoring.html</guid>
<title>DIY refactoring</title>
<description>&lt;p&gt;Yesterday I released a &lt;a href=&quot;https://gist.github.com/4659225&quot;&gt;piece of code&lt;/a&gt; the includes a parser,
a rewriter and serializer for a small expression language.&lt;/p&gt;

&lt;p&gt;The code is an example how you can parse source code and build a tree, rewrite
the tree using two expressions and serialize the tree back to a piece of 'code'.&lt;/p&gt;

&lt;p&gt;The idea that I used here was to improve the language by adding a way to
specify structural variables. The variables start with a colon &lt;code&gt;:&lt;/code&gt;, but are
otherwise like variables.&lt;/p&gt;

&lt;p&gt;The actual source code shouldn't contain these structural variables. You should
only use them in the transformation specification. I wrote a function
&lt;code&gt;replace(source, from, to)&lt;/code&gt; that find and replaces the structure &lt;code&gt;from&lt;/code&gt; in
&lt;code&gt;source&lt;/code&gt; to the structure &lt;code&gt;to&lt;/code&gt;.  Let's start with an example.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;my $source = &amp;lt;&amp;lt;'SOURCE';
print(power(10, 2));
print(power(10, 3))
SOURCE

print replace($source, 'power(:b, 2)', 'twice(:b)') . &quot;\n&quot;;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;In this example we replace the &lt;code&gt;power&lt;/code&gt; function with the &lt;code&gt;twice&lt;/code&gt; function, but
only if the exponent equals &lt;code&gt;2&lt;/code&gt;. The power call with exponent &lt;code&gt;3&lt;/code&gt; is not
replaced.&lt;/p&gt;

&lt;p&gt;The function &lt;code&gt;replace&lt;/code&gt; parses all three arguments &lt;code&gt;$source&lt;/code&gt;, &lt;code&gt;$from&lt;/code&gt; and &lt;code&gt;$to&lt;/code&gt;.
It searches for the &lt;code&gt;$from&lt;/code&gt; structure using the &lt;code&gt;_expr_match&lt;/code&gt; function, which
returns the matching structural variables in the third parameter.&lt;/p&gt;

&lt;p&gt;To play with this you should &lt;code&gt;git clone&lt;/code&gt; the gist and run the &lt;code&gt;test.pl&lt;/code&gt; program.
Changing the &lt;code&gt;$source&lt;/code&gt;, &lt;code&gt;$from&lt;/code&gt; and &lt;code&gt;$to&lt;/code&gt; allows you to try different things.&lt;/p&gt;</description>
<link>http://peterstuifzand.nl/2013/01/29/diy-refactoring.html?utm_campaign=rss&amp;utm_source=rss&amp;utm_medium=rss</link>
<pubDate>Tue, 29 Jan 2013 21:52:00 +0100</pubDate>
</item>
<item>
<guid>http://peterstuifzand.nl/2013/01/20/generate-a-list-of-the-same-thing.html</guid>
<title>Generate a list of the same thing</title>
<description>&lt;p&gt;Last year I wrote about how we can build an extended syntax for Marpa on top of
the basic interface.&lt;/p&gt;

&lt;p&gt;For the counted rule &lt;code&gt;lhs ::= rhs{5}&lt;/code&gt; where you want to match the right hand
side multiple times, we can just generate the &lt;code&gt;rhs&lt;/code&gt; item &lt;code&gt;5&lt;/code&gt; times.&lt;/p&gt;

&lt;p&gt;This isn't the right thing. Jeffrey &lt;a href=&quot;https://gist.github.com/2324781&quot;&gt;pointed out&lt;/a&gt;
that you can build these &lt;code&gt;{min,max}&lt;/code&gt; rules up out of blocks.&lt;/p&gt;

&lt;p&gt;Then I remembered a piece of code from Elements of Programming which explained
that it's possible to generate the Fibonacci series in O(log n) time. The same
should be possible for the counted rules.&lt;/p&gt;

&lt;p&gt;So I wrote this code that generated these rules, not in O(log n) time, but with
more rules and less items in the rules. This scales better for big &lt;code&gt;n&lt;/code&gt;.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ ./counted_rule.pl lhs rhs 5 action
_rhs_block_5  ::= _rhs_block_4 _rhs_block_1    action =&amp;gt; do_flatten_list
_rhs_block_4  ::= _rhs_block_2 _rhs_block_2    action =&amp;gt; do_flatten_list
_rhs_block_2  ::= rhs rhs                      action =&amp;gt; do_flatten_list
_rhs_block_1  ::= rhs                          action =&amp;gt; do_flatten_list
lhs           ::= _rhs_block_5                 action =&amp;gt; action

$ ./counted_rule.pl lhs rhs 50 action
_rhs_block_50 ::= _rhs_block_48 _rhs_block_2   action =&amp;gt; do_flatten_list
_rhs_block_48 ::= _rhs_block_32 _rhs_block_16  action =&amp;gt; do_flatten_list
_rhs_block_32 ::= _rhs_block_16 _rhs_block_16  action =&amp;gt; do_flatten_list
_rhs_block_16 ::= _rhs_block_8 _rhs_block_8    action =&amp;gt; do_flatten_list
_rhs_block_8  ::= _rhs_block_4 _rhs_block_4    action =&amp;gt; do_flatten_list
_rhs_block_4  ::= _rhs_block_2 _rhs_block_2    action =&amp;gt; do_flatten_list
_rhs_block_2  ::= rhs rhs                      action =&amp;gt; do_flatten_list
lhs           ::= _rhs_block_50                action =&amp;gt; action
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The number of rules scales logarithmically.&lt;/p&gt;

&lt;p&gt;The code for &lt;a href=&quot;https://gist.github.com/2326798&quot;&gt;counted-rule.pl&lt;/a&gt; is on GitHub.&lt;/p&gt;</description>
<link>http://peterstuifzand.nl/2013/01/20/generate-a-list-of-the-same-thing.html?utm_campaign=rss&amp;utm_source=rss&amp;utm_medium=rss</link>
<pubDate>Sun, 20 Jan 2013 12:12:00 +0100</pubDate>
</item>
</channel></rss>
