<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">

 <title>Fayland and Programming</title>
 
 <link href="http://fayland.me" />
 <updated>2013-04-27T10:01:36+08:00</updated>
 <id>http://fayland.me</id>
 <author>
   <name>Fayland Lam</name>
   <email>fayland@gmail.com</email>
 </author>

 
    
 <feedburner:info uri="fayland" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://www.fayland.org/atom.xml" /><feedburner:browserFriendly>This is an XML content feed. It is intended to be viewed in a newsreader or syndicated to another site, subject to copyright and fair use.</feedburner:browserFriendly><entry>
   <title>mojo tt2 defaults layout patch</title>
   <link href="http://fayland.me/perl/2013/04/27/mojo-tt2-defaults-layout-patch" />
   <updated>2013-04-27T00:00:00+08:00</updated>
   <id>http://fayland.me/perl/2013/04/27/mojo-tt2-defaults-layout-patch</id>
   <content type="html">&lt;p&gt;You wrote code with open source like CPAN. You meet problems with them. You investigate, write tests then provide patches. Your patches are accepeted.&lt;/p&gt;

&lt;p&gt;I really enjoy the way it moves.&lt;/p&gt;

&lt;p&gt;Here is &lt;a href='https://github.com/fayland/mojox-renderer-tt/commit/95d9ee5c356fa3f398b2deed9611ba47b69a890b'&gt;another patch&lt;/a&gt; for &lt;a href='https://github.com/plicease/mojox-renderer-tt'&gt;Mojolicious::Plugin::TtRenderer&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;the issue is that &lt;code&gt;$self-&amp;gt;defaults(layout =&amp;gt; &amp;#39;wrapper&amp;#39;);&lt;/code&gt; is always dropping the &lt;code&gt;[% content %]&lt;/code&gt; without reason. and with debug I see the content is really in &lt;code&gt;$c-&amp;gt;stash-&amp;gt;{&amp;#39;mojo.content&amp;#39;}&lt;/code&gt;. so a simple patch is that just &lt;code&gt;$c-&amp;gt;stash-&amp;gt;{content} ||= $c-&amp;gt;stash-&amp;gt;{&amp;#39;mojo.content&amp;#39;}-&amp;gt;{content};&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;recently I&amp;#8217;m writing another new app with bitcoin &amp;lt;-&amp;gt; litecoin and other virtual coins exchange. and I have a wrapper.html.tt for the whole site. but I do not want to use it in the email TT2 render.&lt;/p&gt;

&lt;p&gt;if I put &lt;code&gt;WRAPPER =&amp;gt; &amp;#39;layouts/wrapper.html.tt&amp;#39;,&lt;/code&gt; in the TT2 options, it will also apply to the mail render. a better approach is to use defaults layout. then in email render, set the layout as empty or actually we need use &lt;code&gt;partial =&amp;gt; 1&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;MainApp.pm&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$self-&amp;gt;plugin(&amp;#39;tt_renderer&amp;#39;);
$self-&amp;gt;defaults(layout =&amp;gt; &amp;#39;wrapper&amp;#39;);
$self-&amp;gt;renderer-&amp;gt;default_handler( &amp;#39;tt&amp;#39; );&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;OtherController.pm&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;my $body = $c-&amp;gt;render(
    template =&amp;gt; &amp;#39;emails/forgot_pass&amp;#39;, format =&amp;gt; &amp;#39;mail&amp;#39;,
    other_stash =&amp;gt; $var,
    partial =&amp;gt; 1
);&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;partial =&amp;gt; 1 will set layout as null. so it will give us what we want.&lt;/p&gt;

&lt;p&gt;Have fun!&lt;/p&gt;</content>
 </entry>
    
 
    
 <entry>
   <title>Mojolicious TT2 patch</title>
   <link href="http://fayland.me/perl/2013/04/12/mojo-tt2-patch" />
   <updated>2013-04-12T00:00:00+08:00</updated>
   <id>http://fayland.me/perl/2013/04/12/mojo-tt2-patch</id>
   <content type="html">&lt;p&gt;I am kindy busy with &lt;a href='https://github.com/fayland/findmjob.com/commits/master'&gt;adding new features&lt;/a&gt; to my &lt;a href='http://findmjob.com/'&gt;job site&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;but it&amp;#8217;s very boring to restart the app on template updates. TT2 should be able to pick up the changes automatically. it works under Dancer or Catalyst, but not Mojolicious.&lt;/p&gt;

&lt;p&gt;I thought I should spend some time on investigating why before writing more stuff. and after a while, I have &lt;a href='https://github.com/fayland/mojox-renderer-tt/commit/d15192619713b044878301c6f911df4c27aa0d84'&gt;a patch&lt;/a&gt; for &lt;a href='https://github.com/plicease/mojox-renderer-tt'&gt;Mojolicious::Plugin::TtRenderer&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;it dues to the Provider in TtRender always return 1 instead of &lt;em&gt;mtime&lt;/em&gt; on &lt;code&gt;_template_modified&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;plicease accepts it quite fast with slight changes but I&amp;#8217;m waiting for a CPAN release. :-)&lt;/p&gt;

&lt;p&gt;here is few changes on &lt;a href='http://findmjob.com/'&gt;http://findmjob.com/&lt;/a&gt; recently.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;tag view is splitted with &lt;a href='http://findmjob.com/tag/OOm8jHZ84RGjYrDhKQ5yzw/+job/perl.html'&gt;job&lt;/a&gt; and &lt;a href='http://findmjob.com/tag/OOm8jHZ84RGjYrDhKQ5yzw/+freelance/perl.html'&gt;freelance&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Location link is added like: &lt;a href='http://findmjob.com/location/wM4xraui4hGi3+CgdEa_Ag/San-Francisco-CA.html'&gt;San Francisco, CA&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Happy hacking!&lt;/p&gt;</content>
 </entry>
    
 
    
 <entry>
   <title>Dancer to Mojolicious</title>
   <link href="http://fayland.me/perl/2013/04/10/dancer-to-mojolicious" />
   <updated>2013-04-10T00:00:00+08:00</updated>
   <id>http://fayland.me/perl/2013/04/10/dancer-to-mojolicious</id>
   <content type="html">&lt;p&gt;The progress went smoothly because all of them are just Perl code.&lt;/p&gt;

&lt;p&gt;old &lt;a href='http://www.perldancer.org/'&gt;Dancer&lt;/a&gt; code: &lt;a href='https://github.com/fayland/findmjob.com/blob/3368b812b72d11cbd1534d2cb870ad0f331a0bf7/www/lib/FindmJob/WWW.pm'&gt;FindmJob::WWW&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;new &lt;a href='http://mojolicio.us/'&gt;Mojolicious&lt;/a&gt; code: &lt;a href='https://github.com/fayland/findmjob.com/blob/5727a9f68cca0d18bf7acb26b7ccaa9ab05663b1/lib/FindmJob/WWW.pm'&gt;FindmJob::WWW&lt;/a&gt;, &lt;a href='https://github.com/fayland/findmjob.com/blob/5727a9f68cca0d18bf7acb26b7ccaa9ab05663b1/lib/FindmJob/WWW/Root.pm'&gt;FindmJob::WWW::Root&lt;/a&gt; and &lt;a href='https://github.com/fayland/findmjob.com/tree/5727a9f68cca0d18bf7acb26b7ccaa9ab05663b1/lib/FindmJob/WWW'&gt;others&lt;/a&gt;&lt;/p&gt;

&lt;h3 id='few_notes'&gt;Few notes&lt;/h3&gt;

&lt;h4 id='hooks'&gt;hooks&lt;/h4&gt;

&lt;p&gt;from &lt;code&gt;before_template_render&lt;/code&gt; to &lt;code&gt;before_render&lt;/code&gt;&lt;/p&gt;

&lt;h4 id='dancer__vs_mojolicious_'&gt;Dancer &lt;code&gt;forward&lt;/code&gt; VS Mojolicious &lt;code&gt;before_dispatch&lt;/code&gt;&lt;/h4&gt;

&lt;p&gt;we can modify the req-&amp;gt;url-&amp;gt;path in &lt;code&gt;before_dispatch&lt;/code&gt; with assigning stash.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;# feed.(rss|atom) and /p.2/
$self-&amp;gt;hook( before_dispatch =&amp;gt; sub {
    my $self = shift;

    my $p = $self-&amp;gt;req-&amp;gt;url-&amp;gt;path;
    if ($p =~ s{/feed\.(rss|atom)$}{}) {
        $self-&amp;gt;stash(&amp;#39;is_feed&amp;#39; =&amp;gt; $1);
    }
    if ($p =~ s{/p\.(\d+)(/|$)}{$2}) {
        $self-&amp;gt;stash(&amp;#39;page&amp;#39; =&amp;gt; $1);
    }
    $self-&amp;gt;req-&amp;gt;url-&amp;gt;path($p);
});&lt;/code&gt;&lt;/pre&gt;

&lt;h4 id='supervise'&gt;supervise&lt;/h4&gt;

&lt;p&gt;Dancer:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;plackup -E production -s Starman --workers=3 -l /tmp/findmjob.sock -a /findmjob.com/www/bin/app.pl&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Mojolicious:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;hypnotoad -f /findmjob.com/bin/www.pl&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Note &lt;code&gt;-f&lt;/code&gt; is important here, or supervise will keep restarting the script.&lt;/p&gt;

&lt;p&gt;above plackup using sock and hypnotoad use port. so we need update the ngnix config a bit.&lt;/p&gt;

&lt;p&gt;and it looks like hypnotoad is working better than plackup Starman&lt;/p&gt;

&lt;h4 id='template_name_conversation'&gt;Template name conversation&lt;/h4&gt;

&lt;p&gt;there is no rule in Dancer for the Template name. but in Mojolicious, we have to do it with $name.$format.$handler&lt;/p&gt;

&lt;p&gt;in this case we have to rename index.tt2 to index.html.tt&lt;/p&gt;

&lt;h3 id='conclusion'&gt;Conclusion&lt;/h3&gt;

&lt;p&gt;well, I&amp;#8217;m not saying that Dancer is worse than Mojolicous or any other words. both of them are great.&lt;/p&gt;

&lt;p&gt;but Dancer is a bit messy with Dancer and Dancer2. actually I love Moo a lot, but I don&amp;#8217;t want to spend time on upgrading Dancer to Dancer2 (there seems some more difference than expected.)&lt;/p&gt;

&lt;p&gt;in the other hand, Mojolicious looks amazing, sri improves it every week and I admire/trust his professional knowledge.&lt;/p&gt;

&lt;p&gt;Have fun.&lt;/p&gt;</content>
 </entry>
    
 
    
 <entry>
   <title>Two new CPAN modules</title>
   <link href="http://fayland.me/perl/2013/03/30/two-new-cpan-modules" />
   <updated>2013-03-30T00:00:00+08:00</updated>
   <id>http://fayland.me/perl/2013/03/30/two-new-cpan-modules</id>
   <content type="html">&lt;p&gt;I got two new CPAN modules uploaded today.&lt;/p&gt;

&lt;h3 id='wwwspinnerchief'&gt;&lt;a href='https://metacpan.org/module/WWW::SpinnerChief'&gt;WWW::SpinnerChief&lt;/a&gt;&lt;/h3&gt;

&lt;p&gt;I wrote this based on the &lt;a href='https://github.com/niteoweb/spinnerchief/blob/master/src/spinnerchief/__init__.py'&gt;Python code&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;it&amp;#8217;s pretty good that you know how to read the Python.&lt;/p&gt;

&lt;h3 id='businesspaypoint'&gt;&lt;a href='https://metacpan.org/module/Business::PayPoint'&gt;Business::PayPoint&lt;/a&gt;&lt;/h3&gt;

&lt;p&gt;aka tips to write SOAP module in Perl.&lt;/p&gt;

&lt;p&gt;the PHP SOAP lib is pretty good while the Perl one is a little suck.&lt;/p&gt;

&lt;p&gt;so usually if I can&amp;#8217;t write it at the first try in Perl, I would use PHP to find the sending request/response&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$client = new SoapClient(&amp;#39;https://www.example.com/Test?wsdl&amp;#39;, array(
    &amp;#39;trace&amp;#39; =&amp;gt; 1,
) );
$client-&amp;gt;__call(&amp;#39;TestAction&amp;#39;, $params);
echo &amp;quot;RESPONSE:\n&amp;quot; . $client-&amp;gt;__getLastResponse() . &amp;quot;\n&amp;quot;;
echo &amp;quot;REQUEST HEADER:\n&amp;quot; . $client-&amp;gt;__getLastRequestHeaders() . &amp;quot;\n&amp;quot;;
echo &amp;quot;REQUEST:\n&amp;quot; . $client-&amp;gt;__getLastRequest() . &amp;quot;\n&amp;quot;;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;After I got the correct sample request, I&amp;#8217;ll try to use Perl library to send the same XML with trace on.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;use SOAP::Lite +trace =&amp;gt; &amp;#39;all&amp;#39;;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;well, you even can&amp;#8217;t write correct one sometimes (maybe I am a little stupid).&lt;/p&gt;

&lt;p&gt;but I have a final trick for it. use XML::Write to genereate the request XML. then use&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;my $som = $soap-&amp;gt;call($method, SOAP::Data-&amp;gt;type(&amp;#39;xml&amp;#39; =&amp;gt; $xml));&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;you won&amp;#8217;t be wrong in this case. :)&lt;/p&gt;

&lt;p&gt;Have fun.&lt;/p&gt;</content>
 </entry>
    
 
    
 <entry>
   <title>Net::Telnet with bitflu</title>
   <link href="http://fayland.me/perl/2013/03/18/nettelnet-with-bitflu" />
   <updated>2013-03-18T00:00:00+08:00</updated>
   <id>http://fayland.me/perl/2013/03/18/nettelnet-with-bitflu</id>
   <content type="html">&lt;p&gt;Even &lt;a href='https://metacpan.org/module/Net::Telnet'&gt;Net::Telnet&lt;/a&gt; is quite old, it&amp;#8217;s still very powerful and simple to use.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;use strict;
use warnings;
use Net::Telnet ();
use Data::Dumper;

my $host = &amp;#39;0&amp;#39;;
my $port = 4001;

my $telnet = Net::Telnet-&amp;gt;new();
unless ($telnet-&amp;gt;open( Host =&amp;gt; $host, Port =&amp;gt; $port, Timeout =&amp;gt; 30 )) {
    die &amp;quot;Can&amp;#39;t connect to $host:$port\n&amp;quot;;
}

$telnet-&amp;gt;waitfor(&amp;#39;/bitflu&amp;gt; /&amp;#39;);

my @messages = map { chomp; $_ } $telnet-&amp;gt;cmd(String =&amp;gt; &amp;#39;ls&amp;#39;);
pop @messages if $messages[-1] eq &amp;#39;bitflu&amp;#39;;
print Dumper(\@messages);

$telnet-&amp;gt;close();&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;there are some tips:&lt;/p&gt;

&lt;h4 id='remove_ansi_color'&gt;remove ANSI color&lt;/h4&gt;

&lt;pre&gt;&lt;code&gt;foreach my $msg (@messages) {
    # if you do not remove this, your regex with /^\[/ may break
    $msg =~ s/\e\[[\d;]*[a-zA-Z]//g;
}&lt;/code&gt;&lt;/pre&gt;

&lt;h4 id='change_window_size'&gt;Change Window Size&lt;/h4&gt;

&lt;p&gt;if you use term to do bitflu&amp;gt; ls, you&amp;#8217;ll see full torrent name. but with the code above, you can only see few chars. here is the note to change the Window Size:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;my $telnet = Net::Telnet-&amp;gt;new();

$telnet-&amp;gt;option_callback( sub { return; } );
$telnet-&amp;gt;option_accept(Do =&amp;gt; 31);

unless ($telnet-&amp;gt;open( Host =&amp;gt; $host, Port =&amp;gt; $port, Timeout =&amp;gt; 60 )) {
    die &amp;quot;Can&amp;#39;t connect to $host:$port\n&amp;quot;;
}
$telnet-&amp;gt;waitfor(&amp;#39;/bitflu&amp;gt; /&amp;#39;);

## copied from http://blog.webdir.bg/perl-apache-realtime-output-from-script/
## Many Thanks!
$telnet-&amp;gt;telnetmode(0);
$telnet-&amp;gt;put(pack(&amp;quot;C9&amp;quot;,
                  255,                  # TELNET_IAC
                  250,                  # TELNET_SB
                  31, 0, 200, 0, 0,     # TELOPT_NAWS
                  255,                  # TELNET_IAC
                  240));                # TELNET_SE
$telnet-&amp;gt;telnetmode(1);&lt;/code&gt;&lt;/pre&gt;</content>
 </entry>
    
 
    
 <entry>
   <title>Learn Python Note 1</title>
   <link href="http://fayland.me/python/2013/03/11/learn-python-note-1" />
   <updated>2013-03-11T00:00:00+08:00</updated>
   <id>http://fayland.me/python/2013/03/11/learn-python-note-1</id>
   <content type="html">&lt;p&gt;I&amp;#8217;m starting learning Python a bit.&lt;/p&gt;

&lt;h3 id='argparse'&gt;argparse&lt;/h3&gt;

&lt;p&gt;if you have args setup in different modules, like you want setup &lt;code&gt;--log&lt;/code&gt; on logging, setup &lt;code&gt;--tor&lt;/code&gt; &lt;code&gt;--skip-tor&lt;/code&gt; on requesting, the combination of &lt;em&gt;add_help=False&lt;/em&gt; and &lt;em&gt;parse_known_args&lt;/em&gt; is pretty cool.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;import argparse
parent_argparse = argparse.ArgumentParser(add_help=False)
parent_argparse.add_argument(&amp;#39;--log&amp;#39;, action=&amp;#39;store&amp;#39;, default=&amp;#39;ERROR&amp;#39;, dest=&amp;#39;log&amp;#39;, help=&amp;#39;logging level: DEBUG, INFO, WARNING, ERROR, CRITICAL&amp;#39;)
_args, _args_unknown = parent_argparse.parse_known_args()&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;afterwards, in real place, do&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;parser = argparse.ArgumentParser(description=&amp;#39;Some real CLI&amp;#39;, parents=[parent_argparse])&lt;/code&gt;&lt;/pre&gt;

&lt;h3 id='initpy_and_as'&gt;&lt;strong&gt;init&lt;/strong&gt;.py and as&lt;/h3&gt;

&lt;p&gt;actually it&amp;#8217;s a very cool feature. you can put some common code for all sub-modules in &lt;code&gt;__init__.py&lt;/code&gt; like config code (to avoid write another file)&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;import ConfigParser
try:
    cfg = ConfigParser.ConfigParser()
    cfg.read([&amp;#39;/somwhere/conf/project.ini&amp;#39;, &amp;#39;/somwhere/conf/project_local.ini&amp;#39;])
except ConfigParser.Error, e:
    logger.critical(&amp;#39;Cannot read configuration file, reason [%s]&amp;#39; % e)&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;and &lt;code&gt;as&lt;/code&gt; is pretty amazing.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;from modulename import cfg as project_config&lt;/code&gt;&lt;/pre&gt;

&lt;h3 id='beautifulsoup_is_another_htmltreebuilder'&gt;BeautifulSoup is another HTML::TreeBuilder&lt;/h3&gt;

&lt;p&gt;BeautifulSoup works like Perl HTML::TreeBuilder.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;from bs4 import BeautifulSoup
soup = BeautifulSoup(text)

for tag in soup.find_all(&amp;#39;span&amp;#39;, attrs={&amp;#39;id&amp;#39;: re.compile(&amp;#39;^ctl00_contentPageContent_lbl(.*?)Value$&amp;#39;)}):
    id = tag[&amp;#39;id&amp;#39;]
    id = id.replace(&amp;#39;ctl00_contentPageContent_lbl&amp;#39;, &amp;#39;&amp;#39;).replace(&amp;#39;Value&amp;#39;, &amp;#39;&amp;#39;)
    data[id] = tag.get_text()&lt;/code&gt;&lt;/pre&gt;

&lt;h3 id='something_i_do_like_in_python'&gt;something I do like in Python&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;def&lt;/code&gt; with args and default values. (Perl &lt;code&gt;sub&lt;/code&gt; was developed too many years ago.)&lt;/p&gt;

&lt;p&gt;you don&amp;#8217;t need type so many &lt;code&gt;{}&lt;/code&gt; or &lt;code&gt;()&lt;/code&gt;.&lt;/p&gt;

&lt;h3 id='something_i_do_not_like_in_python'&gt;something I do not like in Python&lt;/h3&gt;

&lt;p&gt;string interpolation is quite inconvenience. there are &lt;code&gt;%&lt;/code&gt;, &lt;code&gt;format&lt;/code&gt; and Template. but I really miss the $ with Perl.&lt;/p&gt;

&lt;p&gt;I miss Perl regexp a lot. the &lt;code&gt;re.compile&lt;/code&gt;, &lt;code&gt;re.sub&lt;/code&gt;, &lt;code&gt;re.I&lt;/code&gt; is too much typing.&lt;/p&gt;

&lt;h3 id='disclaim'&gt;Disclaim&lt;/h3&gt;

&lt;p&gt;I&amp;#8217;m still a newbie. so parden me if anything is wrong. I&amp;#8217;ll write more when I learn more. and I admit it&amp;#8217;s pretty fun to learn Python.&lt;/p&gt;</content>
 </entry>
    
 
    
 <entry>
   <title>Blogger local file  &gt; Jekyll migrator</title>
   <link href="http://fayland.me/perl/2013/03/07/blogger-local-file---jekyll-migrator" />
   <updated>2013-03-07T00:00:00+08:00</updated>
   <id>http://fayland.me/perl/2013/03/07/blogger-local-file---jekyll-migrator</id>
   <content type="html">&lt;p&gt;I have an &lt;a href='http://fayland.org/blog/'&gt;old Blogger&lt;/a&gt; before I move to MT5, it contains my posts from 2006 to 2009. some are quite old, broken, useless and even not worth reading. but some are still very useful and it&amp;#8217;s a part of my memory and life. (Sorry that comments are dropped that I can&amp;#8217;t import it into Disqus.)&lt;/p&gt;

&lt;p&gt;so I wrote a simple Perl script to convert the local HTML files into Jekyll here. the source code can be found in &lt;a href='https://github.com/fayland/p5-jekyll-scripts/blob/master/blogger/migrator.pl'&gt;github&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;it&amp;#8217;s quite simple and maybe just fit for my need. but feel free to change it if you have same demand.&lt;/p&gt;

&lt;p&gt;Have fun.&lt;/p&gt;</content>
 </entry>
    
 
    
 <entry>
   <title>add alert note for old posts in Jekyll</title>
   <link href="http://fayland.me/note/2013/03/07/add-alert-note-for-old-posts-in-jekyll" />
   <updated>2013-03-07T00:00:00+08:00</updated>
   <id>http://fayland.me/note/2013/03/07/add-alert-note-for-old-posts-in-jekyll</id>
   <content type="html">&lt;h2 id='add_alert_note_for_old_posts'&gt;add alert note for old posts&lt;/h2&gt;

&lt;p&gt;For Jekyll Bootstrap, it&amp;#8217;s quite simple as we can do something like below:&lt;/p&gt;

&lt;p&gt;edit &lt;em&gt;_includes/themes/twitter/post.html&lt;/em&gt;, add&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;{% assign page_year = page.date | date: &amp;quot;%Y&amp;quot; %}
{% if page_year &amp;lt; &amp;#39;2010&amp;#39; %}
&amp;lt;div class=&amp;#39;alert alert-info&amp;#39;&amp;gt;This post may be outdated due to it was written on {{ page_year }}. The links may be broken. The code may be not working anymore. Leave comments if needed.&amp;lt;/div&amp;gt;
{% endif %}&lt;/code&gt;&lt;/pre&gt;

&lt;h2 id='20_items_in_rssatom'&gt;20 items in rss/atom&lt;/h2&gt;

&lt;p&gt;I have another if in the {% for post in site.posts %} for rss.xml and atom.xml&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;{% if forloop.index &amp;lt; 20 %}
...
{% endif %}&lt;/code&gt;&lt;/pre&gt;

&lt;h2 id='paginate'&gt;paginate&lt;/h2&gt;

&lt;p&gt;edit &lt;em&gt;_config.yml&lt;/em&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;paginate: 10
paginate_path: &amp;#39;page/:num&amp;#39;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Have fun.&lt;/p&gt;</content>
 </entry>
    
 
    
 <entry>
   <title>MT  &gt; Jekyll perl migrator</title>
   <link href="http://fayland.me/perl/2013/03/06/mt---jekyll-perl-migrator" />
   <updated>2013-03-06T00:00:00+08:00</updated>
   <id>http://fayland.me/perl/2013/03/06/mt---jekyll-perl-migrator</id>
   <content type="html">&lt;p&gt;I bought a new domain &lt;a href='http://fayland.me/'&gt;fayland.me&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I picked &lt;a href='https://github.com/mojombo/jekyll'&gt;Jekyll&lt;/a&gt; as the blog engine.&lt;/p&gt;

&lt;p&gt;I wrote a simple Perl script to convert my old Movable Type 5 blogs to Jekyll Bootstrap.&lt;/p&gt;

&lt;p&gt;&lt;a href='https://github.com/fayland/p5-jekyll-scripts/blob/master/mt/migrator.pl'&gt;Github code&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;the difference between this one and the &lt;a href='https://github.com/mojombo/jekyll/wiki/blog-migrations'&gt;Jekyll::MT&lt;/a&gt; is that it supports tags and it&amp;#8217;s for &lt;a href='http://jekyllbootstrap.com/'&gt;Jekyll Bootstrap&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;at last, using&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;rsync -arv --delete _site fay:/srv/www/fayland.me/&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;to rsync the site.&lt;/p&gt;

&lt;p&gt;Have fun.&lt;/p&gt;</content>
 </entry>
    
 
    
 <entry>
   <title>Net-Amazon-DynamoDB</title>
   <link href="http://fayland.me/perl/2012/11/22/net-amazon-dynamodb" />
   <updated>2012-11-22T00:00:00+08:00</updated>
   <id>http://fayland.me/perl/2012/11/22/net-amazon-dynamodb</id>
   <content type="html">

I have been playing with&amp;nbsp;&lt;a href="https://metacpan.org/module/Net::Amazon::DynamoDB"&gt;Net::Amazon::DynamoDB&lt;/a&gt;&amp;nbsp;a lot recently. this article is not to comment on that service. it's just a few notes for Perl guys who're using it.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;1. Moo based instead of Moose.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;well, if you're not using Moose in your system, Moose may be too much for your speed. I am maintain a new branch on that which converted Moose to Moo. changes can be found at&amp;nbsp;&lt;a href="https://github.com/fayland/Net-Amazon-DynamoDB/commit/0b3b9a493e92c85461353ef1fc1da422e4d0bb48"&gt;https://github.com/fayland/Net-Amazon-DynamoDB/commit/0b3b9a493e92c85461353ef1fc1da422e4d0bb48&lt;/a&gt;&amp;nbsp;and I'll update when the Moose version is updated.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;2. custom Cache module supports.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I removed the isa =&amp;gt; 'Cache' in the Moo version, instead, I'm using&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;has cache =&amp;gt; ( isa =&amp;gt; sub {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;die "thaw/freeze/remove must be supported in cache" unless $_[0]-&amp;gt;can('thaw') and $_[0]-&amp;gt;can('freeze') and $_[0]-&amp;gt;can('remove')&lt;/div&gt;&lt;div&gt;}, is =&amp;gt; 'rw', predicate =&amp;gt; 'has_cache' );&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;so that we can use custom layer like&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;"&gt;&lt;div&gt;&lt;div&gt;package My::Dummy::Cache::FastMmap;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;use Moo;&lt;/div&gt;&lt;div&gt;use Cache::FastMmap;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;has 'cache' =&amp;gt; (is =&amp;gt; 'lazy');&lt;/div&gt;&lt;div&gt;sub _build_cache { Cache::FastMmap-&amp;gt;new(share_file =&amp;gt; '/tmp/mycache_fastmmap', unlink_on_exit =&amp;gt; 0) }&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;# Cache::FastMmap do not have thaw/freeze sub&lt;/div&gt;&lt;div&gt;sub thaw {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; my $self = shift;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; $self-&amp;gt;cache-&amp;gt;get(@_);&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;div&gt;sub freeze {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; my $self = shift;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; $self-&amp;gt;cache-&amp;gt;set(@_);&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;div&gt;sub remove {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; my $self = shift;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; $self-&amp;gt;cache-&amp;gt;remove(@_);&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;1;&lt;/div&gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I have fixed some bugs for the cache system like not set while return is undef, delete on batch_write etc. but it is still not perfect b/c it's not supported inside batch_get_items yet. I may write patch for it later.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;3. set is not array.&lt;/div&gt;&lt;div&gt;well, for SS or NS. it's set. it's not array. it means there is not an order inside.&lt;/div&gt;&lt;div&gt;if you want something like order, we can join it as string and save it. after get, split back.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Thanks.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;</content>
 </entry>
    
 
    
 <entry>
   <title>reCaptcha and lightbox and ajaxPost</title>
   <link href="http://fayland.me/javascript/2012/09/14/recaptcha-and-lightbox-and-ajaxpost" />
   <updated>2012-09-14T00:00:00+08:00</updated>
   <id>http://fayland.me/javascript/2012/09/14/recaptcha-and-lightbox-and-ajaxpost</id>
   <content type="html">

sometimes, you want to do lightbox for Email Us or Contact Us page.&lt;div&gt;in this case, you don't want to include the recaptcha js in every page, you want to include it in the popup lightbox but here we have an issue that $(document).ready would be called while the google recaptcha js is not loaded. b/c document ready is just checking the original page instead of the lightbox. in this case, here is a common solution for every js loading (wait until that js loaded.)&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;"&gt;&lt;div&gt;&amp;lt;script type="text/javascript" src="https://www.google.com/recaptcha/api/js/recaptcha_ajax.js"&amp;gt;&amp;lt;/script&amp;gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;div&gt;&lt;blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;"&gt;&lt;div&gt;&lt;div&gt;&amp;lt;script type="text/javascript"&amp;gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; $(document).ready(function(){&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var reCaptcha_timer;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; reCaptcha_timer = setInterval(function(){&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (typeof(Recaptcha) != 'undefined') {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;clearInterval(reCaptcha_timer);&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;CreateReCaptcha();&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }, 50);&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; });&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; function CreateReCaptcha() {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Recaptcha.create("public_key_blabla", 'captcha-placeholder', {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; theme: "white",&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; callback: Recaptcha.focus_response_field&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; });&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;div&gt;&amp;lt;/script&amp;gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/blockquote&gt;see we have a tricky that keep check if Recaptcha is inited (which will be done when recatpcha_ajax.js is loaded).&lt;/div&gt;&lt;div&gt;and only after it's loaded, we clear the check, and create the catpcha.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;the trick works pretty good. but here is another issue, when the lightbox is loaded and user submits the form, and if some elements are wrong or captcha is wrong, that we need show captcha once again. it will be broken. b/c Recaptcha js variable is already defined, and Recaptcha.create will not working fine b/c it has something stored for previous captcha.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;in this case, another tricky is much more simpler.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;"&gt;&lt;div&gt;&lt;div&gt;&amp;lt;script type="text/javascript"&amp;gt;&lt;/div&gt;&lt;div&gt;// so that we can reload it&lt;/div&gt;&lt;div&gt;if (typeof(Recaptcha) != 'undefined') Recaptcha = undefined;&lt;/div&gt;&lt;div&gt;&amp;lt;/script&amp;gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&amp;lt;script type="text/javascript" src="https://www.google.com/recaptcha/api/js/recaptcha_ajax.js"&amp;gt;&amp;lt;/script&amp;gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/blockquote&gt;before load the js, we reset it so it works like it's the first time we are trying to create reCaptcha.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;those issue only happens on ajax lightbox load reCaptcha and ajaxPost the reCaptcha form.&lt;/div&gt;&lt;div&gt;stupid but works.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Thanks.&lt;/div&gt;</content>
 </entry>
    
 
    
 <entry>
   <title>MacOSx homebrew postgresql issue note</title>
   <link href="http://fayland.me/macosx/2012/09/12/macosx-homebrew-postgresql-issue-note" />
   <updated>2012-09-12T00:00:00+08:00</updated>
   <id>http://fayland.me/macosx/2012/09/12/macosx-homebrew-postgresql-issue-note</id>
   <content type="html">

after brew install postgresql&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;then run "initdb /usr/local/var/postgres -E utf8", may got:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;"&gt;&lt;div&gt;&lt;div&gt;selecting default shared_buffers ... 400kB&lt;/div&gt;&lt;div&gt;creating configuration files ... ok&lt;/div&gt;&lt;div&gt;creating template1 database in /usr/local/var/postgres/base/1 ... FATAL: &amp;nbsp;could not create shared memory segment: Cannot allocate memory&lt;/div&gt;&lt;div&gt;DETAIL: &amp;nbsp;Failed system call was shmget(key=1, size=2138112, 03600).&lt;/div&gt;&lt;div&gt;HINT: &amp;nbsp;This error usually means that PostgreSQL's request for a shared memory segment exceeded available memory or swap space, or exceeded your kernel's SHMALL parameter. &amp;nbsp;You can either reduce the request size or reconfigure the kernel with larger SHMALL. &amp;nbsp;To reduce the request size (currently 2138112 bytes), reduce PostgreSQL's shared memory usage, perhaps by reducing shared_buffers or max_connections.&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;	&lt;/span&gt;The PostgreSQL documentation contains more information about shared memory configuration.&lt;/div&gt;&lt;div&gt;child process exited with exit code 1&lt;/div&gt;&lt;div&gt;initdb: removing data directory "/usr/local/var/postgres"&lt;/div&gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;fixes as:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&amp;nbsp;~ &amp;nbsp;sudo sysctl -w kern.sysv.shmall=1024000&lt;/div&gt;&lt;div&gt;kern.sysv.shmall:&amp;nbsp;8192&amp;nbsp;-&amp;gt; 1024000&lt;/div&gt;&lt;div&gt;&amp;nbsp;~ &amp;nbsp;initdb /usr/local/var/postgres -E utf8&amp;nbsp;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;then everything will move smoothly.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;just for note.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;</content>
 </entry>
    
 
    
 <entry>
   <title>MongoDB and Perl</title>
   <link href="http://fayland.me/perl/2012/04/26/mongodb-and-perl" />
   <updated>2012-04-26T00:00:00+08:00</updated>
   <id>http://fayland.me/perl/2012/04/26/mongodb-and-perl</id>
   <content type="html">

it's really a pain to work with MongoDB in Perl. Perl has no 'type' so when you get INT value from DBI, it might be really "1" instead of int 1.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I got some data dumped from MySQL to MongoDB and found all the 'time' field is wrapped as "1335350669" instead of&amp;nbsp;1335350669.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;and when you insert it from code like { time =&amp;gt; time() }, you really have&amp;nbsp;1335350670 instead of "1335350670". it breaks the sort. it breaks the deletion. it breaks everything.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;blabla, to fix that, we just need update it in mongodb like below.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;"&gt;&lt;div&gt;&lt;div&gt;PRIMARY&amp;gt; db.jobs.find().forEach(&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; function(job) {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; job.time = parseInt(job.time);&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; db.jobs.save(job);&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; });&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;/div&gt;&lt;div&gt;but it's still a pain. I didn't check MongoDBx::Class or&amp;nbsp;Mongoose yet, but Moose's type should be able to fix it I think.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Thanks&lt;/div&gt;</content>
 </entry>
    
 
    
 <entry>
   <title>api and android app</title>
   <link href="http://fayland.me/perl/2012/04/14/api-and-android-app" />
   <updated>2012-04-14T00:00:00+08:00</updated>
   <id>http://fayland.me/perl/2012/04/14/api-and-android-app</id>
   <content type="html">

I'm a fan of Android. even I like my iPad and MBP very much too.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I'd like to write an App for Android. and here is all the story.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;first of all, I need write an API which supports JSONP. since it would be very simple, I don't want to mix it up with Dancer. at last, I wrote something based on &lt;a href="https://github.com/stevan/webmachine-perl"&gt;webmachine-perl&lt;/a&gt;. I like the idea behind the webmachine. the chain design looks pretty nice. even I don't use that too much.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;the code is at&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;a href="https://github.com/fayland/findmjob.com/blob/master/api/app.psgi"&gt;https://github.com/fayland/findmjob.com/blob/master/api/app.psgi&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;a href="https://github.com/fayland/findmjob.com/blob/master/api/lib/FindmJob/Resource.pm"&gt;https://github.com/fayland/findmjob.com/blob/master/api/lib/FindmJob/Resource.pm&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;and live demo as&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;a href="http://api.findmjob.com/search?callback=jQuery171016797792096622288_1334322201618&amp;amp;q=perl&amp;amp;loc=&amp;amp;_=1334322214418"&gt;http://api.findmjob.com/search?callback=jQuery171016797792096622288_1334322201618&amp;amp;q=perl&amp;amp;loc=&amp;amp;_=1334322214418&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;after API is done. now comes the android app part. Sorry that I don't know much about Java. and I failed to download appmobi/jqmobi (the download never ends here). so at last I picked up&amp;nbsp;&lt;a href="http://phonegap.com/"&gt;phonegap&lt;/a&gt;.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;the progress went pretty smooth. mixed with jQuery Mobile, I have it out after few hours.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;you can download it for fun from&amp;nbsp;&lt;a href="http://static.findmjob.com/FindmJob.apk"&gt;http://static.findmjob.com/FindmJob.apk&lt;/a&gt;&lt;/div&gt;&lt;div&gt;it's pretty simple, just with one JSONP request and not much different than the demo.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;even there, I'd like to share the code with you:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;a href="https://github.com/fayland/findmjob.com/blob/master/mobile/android/assets/www/index.html"&gt;https://github.com/fayland/findmjob.com/blob/master/mobile/android/assets/www/index.html&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;a href="https://github.com/fayland/findmjob.com/blob/master/mobile/android/assets/www/mobile.coffee"&gt;https://github.com/fayland/findmjob.com/blob/master/mobile/android/assets/www/mobile.coffee&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;it's very cool and I'm excited! (badly Google costs 25$ for submitting it and I don't want to do it for now)&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Thanks.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;</content>
 </entry>
    
 
    
 <entry>
   <title>sphinx search with varchar primary key</title>
   <link href="http://fayland.me/sphinx/2012/04/08/sphinx-search-with-varchar-primary-key" />
   <updated>2012-04-08T00:00:00+08:00</updated>
   <id>http://fayland.me/sphinx/2012/04/08/sphinx-search-with-varchar-primary-key</id>
   <content type="html">

usually when you index the mysql data into sphinx, you'll use id int/bigint for the primary key. but it's broken for me on &lt;a href="http://findmjob.com/"&gt;http://findmjob.com/&lt;/a&gt;, we use uuid everywhere for the primary key.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;here is the solution for it. use&amp;nbsp;@id := @id + 1 for the indexer, and use&amp;nbsp;sql_field_string to get the real id when matched. &lt;a href="https://github.com/fayland/findmjob.com/blob/master/etc/sphinx.conf"&gt;sample code&lt;/a&gt; below:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;"&gt;&lt;div&gt;&lt;div&gt;sql_query_pre = SET NAMES utf8&lt;/div&gt;&lt;div&gt;sql_query_pre = SET @id := 1;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;sql_query&lt;span class="Apple-tab-span" style="white-space: pre; "&gt;		&lt;/span&gt;= \&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; SELECT @id := @id + 1 AS tid, id, title, description, location, contact, inserted_at FROM job ORDER BY inserted_at DESC LIMIT 10000&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;sql_field_string = id&lt;/div&gt;&lt;/blockquote&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;it requires latest sphinx to support&amp;nbsp;sql_field_string. and the latest CPAN module too.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;and Perl code for it will be normal like before. and instead you use -&amp;gt;{doc}, you need use the attribtues -&amp;gt;{id} like&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;"&gt;&lt;div&gt;my @jobids = map { $_-&amp;gt;{id} } @{$ret-&amp;gt;{matches}};&lt;/div&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;so now we have sphinx search supports in my new site, eg:&amp;nbsp;&lt;a href="http://findmjob.com/search/Perl.html?q=Perl"&gt;http://findmjob.com/search/Perl.html?q=Perl&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Thanks.&lt;/div&gt;</content>
 </entry>
    
 
    
 <entry>
   <title>DBIx::Class with Moose has</title>
   <link href="http://fayland.me/perl/2012/04/04/dbixclass-with-moose-has" />
   <updated>2012-04-04T00:00:00+08:00</updated>
   <id>http://fayland.me/perl/2012/04/04/dbixclass-with-moose-has</id>
   <content type="html">

well, I don't know how to name it.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;a href="https://metacpan.org/release/DBIx-Class"&gt;DBIx::Class&lt;/a&gt; is one of my&amp;nbsp;favorite modules. for its structure, with DBIx::Class you can make all your code very well&amp;nbsp;organized and clean. writing code with DBIx::Class means you can use it in framework like Catalyst or Mojo or Dancer, and you can use it in any perl script (cron usually). for me, DBIx::Class is the right model, TT2 is the right template, and framework is just for URL dispatch.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;a href="https://metacpan.org/release/Moose"&gt;Moose&lt;/a&gt; is another module I like. Role, and clean OO.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;by using&amp;nbsp;DBIx::Class::Schema::Loader&amp;nbsp;make_schema_at, with&amp;nbsp;use_moose =&amp;gt; 1 on (eg:&amp;nbsp;&lt;a href="https://github.com/fayland/findmjob.com/blob/master/script/make_schema_at.pl"&gt;https://github.com/fayland/findmjob.com/blob/master/script/make_schema_at.pl&lt;/a&gt;), we can generate very clean Result module with Moose.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;sometimes you want make assessor based on the table column. like for each job in table, we all have a URL which is based on the id and title in the table, it's so related to those two fields, so we'd better to put it in the Result.&lt;/div&gt;&lt;div&gt;with DBIx::Class, it's very simple. (&lt;a href="https://github.com/fayland/findmjob.com/blob/master/lib/FindmJob/Schema/Result/Job.pm"&gt;sample code&lt;/a&gt;)&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;"&gt;&lt;div&gt;&lt;div&gt;package FindmJob::Schema::Result::Job;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;....&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;use FindmJob::Utils 'seo_title';&lt;/div&gt;&lt;div&gt;has 'url' =&amp;gt; ( is =&amp;gt; 'ro', isa =&amp;gt; 'Str', lazy_build =&amp;gt; 1 );&lt;/div&gt;&lt;div&gt;sub _build_url {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; my ($self) = @_;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; return "/job/" . $self-&amp;gt;id . "/" . seo_title($self-&amp;gt;title) . ".html";&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;after that, we can always call $job-&amp;gt;url after we -&amp;gt;search for -&amp;gt;find it. very neat. live demo like:&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;a href="http://findmjob.com/job/Il2bUdB74RGuDaqxKQ5yzw/Senior-Perl-Developer.html"&gt;http://findmjob.com/job/Il2bUdB74RGuDaqxKQ5yzw/Senior-Perl-Developer.html&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;have fun. Thanks&lt;/div&gt;</content>
 </entry>
    
 
    
 <entry>
   <title>findmjob.com</title>
   <link href="http://fayland.me/perl/2012/04/02/findmjobcom" />
   <updated>2012-04-02T00:00:00+08:00</updated>
   <id>http://fayland.me/perl/2012/04/02/findmjobcom</id>
   <content type="html">

maybe to earn some money (not for fun this time), I decided to write a new website &lt;a href="http://findmjob.com/"&gt;http://findmjob.com/&lt;/a&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I sit front of my computer and coded it for 2 days and here is it. it's out.&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;it's very simple and without much stuff yet. and the final goal is undecided. but there it is. I'm very pleased to see it in public.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;since there is no reason to keep it private, I opened source it in github:&amp;nbsp;&lt;a href="https://github.com/fayland/findmjob.com"&gt;https://github.com/fayland/findmjob.com&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;for programmer, it's very simple to write website. but it's very hard to make it a success. so suggestions are welcome.&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Thanks.&lt;/div&gt;</content>
 </entry>
    
 
    
 <entry>
   <title>better pagination url design in Dancer</title>
   <link href="http://fayland.me/perl/2012/04/02/better-pagination-url-design-in-dancer" />
   <updated>2012-04-02T00:00:00+08:00</updated>
   <id>http://fayland.me/perl/2012/04/02/better-pagination-url-design-in-dancer</id>
   <content type="html">

usually People do param for pager like ?page=1 or ?p=1, it maybe not that good for search engine because they may not go scrape inside. so we may come out a solution with /page=1/ or /p=1/ or even /p.1/ etc.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;in &lt;a href="http://search.cpan.org/perldoc?Dancer"&gt;Dancer&lt;/a&gt;, it's very tricky to do add pagination regex in all URLs. and thank God, we have 'forward' and with code like below, it becomes very simple and easy to use.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Perl code:&lt;/div&gt;&lt;div&gt;&lt;blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;"&gt;&lt;div&gt;&lt;div&gt;get qr'.*?/p\.(\d+).*?' =&amp;gt; sub {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; my $uri = request-&amp;gt;uri;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; $uri =~ s'/p\.(\d+)'';&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; var page =&amp;gt; $1;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; $uri =~ s/\/$//;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; forward $uri;&lt;/div&gt;&lt;div&gt;};&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;get '/' =&amp;gt; sub {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; my $p = vars-&amp;gt;{page} || 1; $p = 1 unless $p =~ /^\d+$/;&lt;/div&gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;we use regex to get the page stuff, then remove it from the request uri then using &lt;b&gt;forward&lt;/b&gt;&amp;nbsp;to do a internal request.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;the TT2 pager code can check at&amp;nbsp;&lt;a href="https://github.com/fayland/findmjob.com/blob/master/templates/pager.tt"&gt;https://github.com/fayland/findmjob.com/blob/master/templates/pager.tt&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;live demo as:&amp;nbsp;&lt;a href="http://findmjob.com/tag/perl/"&gt;http://findmjob.com/tag/perl&lt;/a&gt;/ and&amp;nbsp;&lt;a href="http://findmjob.com/tag/perl/p.2/"&gt;http://findmjob.com/tag/perl/p.2/&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;have fun.&lt;/div&gt;</content>
 </entry>
    
 
    
 <entry>
   <title>Net-GitHub-0.43_01</title>
   <link href="http://fayland.me/perl/2012/03/30/net-github-043-01" />
   <updated>2012-03-30T00:00:00+08:00</updated>
   <id>http://fayland.me/perl/2012/03/30/net-github-043-01</id>
   <content type="html">

Github is &lt;a href="https://github.com/blog/1090-github-api-moving-on"&gt;moving on with their API&lt;/a&gt; that "We will terminate API v1 and API v2 in 1 month on May 1st, 2012.".&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I know lots of people are preferring that they want token instead of writing user/pass in the config or code.&lt;/div&gt;&lt;div&gt;and now we have the choice with create access_token with code instead of web flow.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;it's time to kick Net::GitHub default to V3 now. so here comes the beta release. and tests/patches are welcome.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;a href="http://fayland.org/CPAN/Net-GitHub-0.43_01.tar.gz"&gt;http://fayland.org/CPAN/Net-GitHub-0.43_01.tar.gz&lt;/a&gt;&amp;nbsp;(it will be on CPAN soon too)&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Tips to create access_token with script:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;"&gt;&lt;div&gt;&lt;div&gt;use Net::GitHub;&lt;/div&gt;&lt;div&gt;my $gh = Net::GitHub-&amp;gt;new( login =&amp;gt; 'fayland', pass =&amp;gt; 'secret' );&lt;/div&gt;&lt;div&gt;my $oauth = $gh-&amp;gt;oauth;&lt;/div&gt;&lt;div&gt;my $o = $oauth-&amp;gt;create_authorization( {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; scopes =&amp;gt; ['user', 'public_repo', 'repo', 'gist'], # just ['public_repo']&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; note &amp;nbsp; =&amp;gt; 'test purpose',&lt;/div&gt;&lt;div&gt;} );&lt;/div&gt;&lt;div&gt;print $o-&amp;gt;{token};&lt;/div&gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;record the token down, and later on we can always use that token without writing down user/pass.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;"&gt;&lt;div&gt;&lt;div&gt;my $github = Net::GitHub-&amp;gt;new(&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; access_token =&amp;gt; $token, # from above&lt;/div&gt;&lt;div&gt;);&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/blockquote&gt;Thanks.&lt;/div&gt;</content>
 </entry>
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 
    
 

</feed>
