<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><atom:link rel="hub" href="http://tumblr.superfeedr.com/" xmlns:atom="http://www.w3.org/2005/Atom"/><description>This space is for content related to Javascript, NodeJS, Ubuntu, Browsers, GIS and other programming stuff that does not fit in a tweet.
Twitter |
GitHub |
LinkedIn
</description><title>@wavded</title><generator>Tumblr (3.0; @wavded)</generator><link>http://wavded.tumblr.com/</link><item><title>Moving...</title><description>&lt;p&gt;Tumblr has been a great service.  Out of all of the hosted solutions out there, I liked it the best.  However it wasn&amp;#8217;t meeting my needs and was definitely more time consuming to get up code examples using their editor.  What I really wanted was GitHub-flavored markdown in a blog format and thankfully, that is available now and nice&amp;#8230; so I&amp;#8217;m moving to &lt;a href="http://wavded.com"&gt;wavded.com&lt;/a&gt;.  I&amp;#8217;ll leave my posts up here since some have been helpful to others but won&amp;#8217;t be posting here anymore.  Come on over and join me on the new &lt;a href="http://wavded.com"&gt;blog&lt;/a&gt;.&lt;/p&gt;</description><link>http://wavded.tumblr.com/post/8542846087</link><guid>http://wavded.tumblr.com/post/8542846087</guid><pubDate>Fri, 05 Aug 2011 23:33:47 -0400</pubDate></item><item><title>Installing git on CentOS 5</title><description>&lt;p&gt;Here&amp;#8217;s a quick simple one that hopefully will make it easier for others.  CentOS 5 doesn&amp;#8217;t have git in its repositories, the jerks :)  But its pretty easy to get it up anyway.&lt;/p&gt;
&lt;pre class="brush: bash"&gt;rpm -Uvh 'http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm'
yum install git
&lt;/pre&gt;</description><link>http://wavded.tumblr.com/post/2418868605</link><guid>http://wavded.tumblr.com/post/2418868605</guid><pubDate>Wed, 22 Dec 2010 14:24:00 -0500</pubDate></item><item><title>Introduction to NodeJS - Slides</title><description>&lt;p&gt;Here are some slides from a recent talk I did introducing NodeJS.  Tumblr won&amp;#8217;t let me embed so here&amp;#8217;s the &lt;a href="https://docs.google.com/present/view?id=dzg6rkg_75g3j8qg8n"&gt;link&lt;/a&gt;.&lt;/p&gt;</description><link>http://wavded.tumblr.com/post/2177595595</link><guid>http://wavded.tumblr.com/post/2177595595</guid><pubDate>Sat, 11 Dec 2010 16:01:02 -0500</pubDate></item><item><title>Influenced by Perl</title><description>&lt;p&gt;I have become particularly more interested in various language paradigms, syntax, and behavior.  Other languages help me rethink about JavaScript and how I write code.  I just inherited a Perl project at work and I have never worked with Perl before so if you are a Perl programmer reading this, please clarify any of my misunderstandings :-).&lt;/p&gt;
&lt;h2&gt;Perl Subroutines&lt;/h2&gt;
&lt;p&gt;One particular thing about Perl that was interesting to me was how function (subroutines) don&amp;#8217;t have argument lists like most C-style languages.  Instead you have to &amp;#8220;shift&amp;#8221; off the arguments within the body of the subroutine, for example:&lt;/p&gt;
&lt;pre class="brush: perl"&gt;sub hash2item {
    my $self=shift;
    my $hash=shift;
    ...
}&lt;/pre&gt;
&lt;p&gt;So in this example &lt;code&gt;$hash&lt;/code&gt; is one of the arguments.&lt;/p&gt;
&lt;p&gt;What also was interesting to me is the first argument that is shifted off when dealing with a &amp;#8220;class-like&amp;#8221; structures is a reference to the object itself (&lt;code&gt;$self&lt;/code&gt;), sorta like &lt;code&gt;this&lt;/code&gt; in other languages.&lt;/p&gt;
&lt;h2&gt;Using $self in JavaScript functions&lt;/h2&gt;
&lt;p&gt;The $self concept made me think about plain (non-constructor, no new operator) functions in JavaScript.  Although they don&amp;#8217;t have a helpful &lt;code&gt;this&lt;/code&gt; reference (points to the global object), you can use something like $self in Perl. Take this example:&lt;/p&gt;
&lt;pre class="brush: js"&gt;function renderElement(hash) {&lt;br/&gt;&lt;br/&gt;    var self = renderElement,&lt;br/&gt;        element = null;&lt;br/&gt;&lt;br/&gt;    if(!self.renderedEl){&lt;br/&gt;        element = document.createElement("div");&lt;br/&gt;        element.className = "my-element";&lt;br/&gt;        document.body.appendChild(element);&lt;br/&gt;        self.renderedEl = element;&lt;br/&gt;    }&lt;br/&gt;&lt;br/&gt;    self.renderedEl.style.display = "block";&lt;br/&gt;}&lt;br/&gt;&lt;/pre&gt;
&lt;p&gt;Whenever renderElement is called after its first time, it has information about the element so it doesn&amp;#8217;t have to create it again because the state is stored in the function object and made available even after it has returned.&lt;/p&gt;
&lt;p&gt;This example really helps clean up the parent scope &amp;#8220;var&amp;#8221; clutter found in examples like:&lt;/p&gt;
&lt;pre class="brush: js"&gt;var renderedEl; //outside var doesn't feel like it's part of the function&lt;br/&gt;&lt;br/&gt;function renderElement(hash) {&lt;br/&gt;    var element;&lt;br/&gt;&lt;br/&gt;    if(!renderedEl){&lt;br/&gt;        element = document.createElement("div");&lt;br/&gt;        element.className = "my-element";&lt;br/&gt;        document.body.appendChild(element);&lt;br/&gt;        renderedEl = element;&lt;br/&gt;    }&lt;br/&gt;&lt;br/&gt;    renderedEl.style.display = "block";&lt;br/&gt;}&lt;br/&gt;&lt;/pre&gt;
&lt;p&gt;Of course, you may have uses for this second example, like if you need it easily accessible by many functions but I think it enforces clean code to keep this information stored within the function if its only to be used by the function.  What are your thoughts?&lt;/p&gt;</description><link>http://wavded.tumblr.com/post/1412144903</link><guid>http://wavded.tumblr.com/post/1412144903</guid><pubDate>Tue, 26 Oct 2010 23:29:00 -0400</pubDate><category>javascript</category><category>perl</category></item><item><title>Installing MapProxy on CentOS</title><description>&lt;p&gt;&lt;a href="http://mapproxy.org/"&gt;MapProxy&lt;/a&gt; is an excellent tool for doing map tile caches and the like.  I&amp;#8217;m still diving into all of what it has to offer but spend a bit of time getting it to work on CentOS 5, so I thought I&amp;#8217;d share what I ended up doing to hopefully save you some time:&lt;/p&gt;
&lt;p&gt;First you will need an updated Python 2.5 or greater plus some development packages in order to use all the MapProxy features:&lt;/p&gt;
&lt;pre class="brush: bash"&gt;rpm -Uvh 'http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarch.rpm'
yum install libffi
rpm -Uvh 'http://yum.chrislea.com/centos/5/i386/chl-release-5-3.noarch.rpm'
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CHL
yum install make gcc gcc-c++ python26 python26-devel zlib-devel freetype freetype-devel libjpeg-devel
&lt;/pre&gt;
&lt;p&gt;Next you setup your virtual environment:&lt;/p&gt;
&lt;pre class="brush: bash"&gt;wget 'http://bitbucket.org/ianb/virtualenv/raw/1.4.8/virtualenv.py'
python26 virtualenv.py --distribute ~/venv/mapproxy
source ~/venv/mapproxy/bin/activate
&lt;/pre&gt;
&lt;p&gt;Then you actually install MapProxy:&lt;/p&gt;
&lt;pre class="brush: bash"&gt;pip install MapProxy
&lt;/pre&gt;
&lt;p&gt;Lastly you setup an MapProxy instance:&lt;/p&gt;
&lt;pre class="brush: bash"&gt;paster create -t mapproxy_conf mymapproxy
&lt;/pre&gt;
&lt;p&gt;Follow more details from here using the MapProxy documentation at &lt;a href="http://mapproxy.org/docs/latest/install.html#create-a-configuration"&gt;&lt;a href="http://mapproxy.org/docs/latest/install.html#create-a-configuration"&gt;http://mapproxy.org/docs/latest/install.html#create-a-configuration&lt;/a&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Enjoy!&lt;/p&gt;</description><link>http://wavded.tumblr.com/post/1488399841</link><guid>http://wavded.tumblr.com/post/1488399841</guid><pubDate>Fri, 09 Jul 2010 00:00:00 -0400</pubDate></item><item><title>Cycling through an Array using the Comma Operator</title><description>&lt;p&gt;The &lt;a href="http://en.wikipedia.org/wiki/Comma_operator"&gt;comma operator&lt;/a&gt; in JavaScript was a long time a mystery to me but once I started using it I found it can be quite handy in certain situations.  In this example, picking the next color out of the available six.&lt;/p&gt;
&lt;pre class="brush: jscript"&gt;var colorIndex = 0, 
    colors = ["FF0000", "008000", "FF0086", "A2FF00", "0000FF", "800080"]; 

function selectNextColor(){
    return colors[colorIndex++] || colors[colorIndex = 0, colorIndex++];
}
&lt;/pre&gt;
&lt;p&gt;&lt;span&gt;&lt;span&gt; &lt;/span&gt;So what&amp;#8217;s this all about:&lt;/span&gt;&lt;/p&gt;
&lt;pre class="brush: jscript"&gt;return colors[colorIndex++] || colors[colorIndex = 0, colorIndex++];&lt;/pre&gt;
&lt;p&gt;So if the current index exists in the array use that and if not, reset the array to 0 and then grab the current index (which is now 0).  The mystery of the comma operator is that only the last value gets accessed by the array and I&amp;#8217;m using the first value to perform an assignment.  So what do you think?  Bad practice?  Handy?  Have some of your own examples to share?&lt;/p&gt;</description><link>http://wavded.tumblr.com/post/579521097</link><guid>http://wavded.tumblr.com/post/579521097</guid><pubDate>Fri, 07 May 2010 16:46:00 -0400</pubDate><category>javascript</category></item><item><title>Hosting NodeJS Apps on CentOS 5</title><description>&lt;p&gt;I recently enjoyed a great article by Alex Young from DailyJS, called &amp;#8220;Hosting Node Apps&amp;#8221; (&lt;a&gt;&lt;a href="http://dailyjs.com/2010/03/15/hosting-nodejs-apps/"&gt;http://dailyjs.com/2010/03/15/hosting-nodejs-apps/&lt;/a&gt;&lt;/a&gt;).  However, my server runs on CentOS so setting it up was a little bit different.  Here&amp;#8217;s what I did to setup, hopefully it helps you out as well.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Grab Core Dependencies&lt;/strong&gt;&lt;/p&gt;
&lt;pre class="brush: bash"&gt;yum install sudo nginx unzip gcc-c++ screen git-core monit
&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Install NodeJS&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Clone,&lt;/p&gt;
&lt;pre class="brush: bash"&gt;git clone git://github.com/joyent/node.git
&lt;/pre&gt;
&lt;p&gt;then Build&lt;/p&gt;
&lt;pre class="brush: bash"&gt;./configure
make
make install
&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Configure nginx Web Server&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Edit the virtual host configuration file at:&lt;/p&gt;
&lt;pre class="brush: bash"&gt;/etc/nginx/conf.d/virtual.conf
&lt;/pre&gt;
&lt;p&gt;Add the following to the end of the file:&lt;/p&gt;
&lt;pre class="brush: plain"&gt;upstream app_cluster_1 {
        server 127.0.0.1:8000;
}

server {
        listen 0.0.0.0:80;
        server_name nodetest.local nodetest;
        access_log /var/log/nginx/nodetest.log;

        location / {
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header Host $http_host;
          proxy_set_header X-NginX-Proxy true;

          proxy_pass http://app_cluster_1/;
          proxy_redirect off;
        }
}
&lt;/pre&gt;
&lt;p&gt;Save and reload nginx:&lt;/p&gt;
&lt;pre class="brush: bash"&gt;service nginx reload
&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Create a Node App&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Make a quick sample app at:&lt;/p&gt;
&lt;pre class="brush: bash"&gt;/var/www/apps/hello_world/example.js
&lt;/pre&gt;
&lt;p&gt;Putting in the following contents:&lt;/p&gt;
&lt;pre class="brush: js"&gt;var sys = require("sys"),
   http = require("http");
http.createServer(function (request, response) {
  response.writeHead(200, {"Content-Type": "text/plain"});
  response.end("Hello World");
}).listen(8000);
sys.puts("Server running at 127.0.0.1:8000");
&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Set up Monit&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Create a new configuration file for monit at:&lt;/p&gt;
&lt;pre class="brush: bash"&gt;/etc/monit.d/hello_world
&lt;/pre&gt;
&lt;p&gt;Putting in the following contents:&lt;/p&gt;
&lt;pre class="brush: plain"&gt;check host hello_world with address 127.0.0.1
    start program = "/usr/local/bin/node /var/www/apps/hello_world/example.js"
    stop program  = "/usr/bin/pkill -f 'node /var/www/apps/hello_world/example.js'"
    if failed port 8000 protocol HTTP
        request /
        with timeout 10 seconds
        then restart
&lt;/pre&gt;
&lt;p&gt;Then restart monit for the configuration to take place:&lt;/p&gt;
&lt;pre class="brush: bash"&gt;monit start all &amp;amp;&amp;amp; service monit restart
&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;All set!&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Go ahead and point your browser to &lt;a href="http://nodetest.local"&gt;http://nodetest.local&lt;/a&gt; to see a &amp;#8220;Hello World&amp;#8221; page (if everything worked!).  For more details on the how and why and for additional resources, check out Alex&amp;#8217;s article.  This is just intended to give a quick start for CentOS 5 users since some of the commands and packages are different.&lt;/p&gt;</description><link>http://wavded.tumblr.com/post/475957278</link><guid>http://wavded.tumblr.com/post/475957278</guid><pubDate>Fri, 26 Mar 2010 22:11:00 -0400</pubDate><category>nodejs</category><category>centos</category></item><item><title>Adventures in NodeJS - CSV to SQL VALUES</title><description>&lt;p&gt;Been recently getting into &lt;a title="NodeJS" href="http://nodejs.org/"&gt;NodeJS&lt;/a&gt;, server side evented-IO JavaScript goodness.  Here is a little app I wrote today to convert CSV files into SQL VALUES statements to use when dumping one schema to another.  Its not complete but was able to help me in my use case:&lt;/p&gt;
&lt;pre class="brush: js"&gt;var sys = require("sys"),
    fs = require("fs"),
    argv_length = process.argv.length,
    csv = process.argv[argv_length-1];

fs.readFile(csv,function(err,data){
    if(err) throw err;

    var split_regex = /,$|("[^"]+(?:"),)|([^,]+(?:,))|,|[^,]+/g,
        records = data.split("\n");

    function csvRowToArray(row){
        var csvArray = [],
            matches = row.match(split_regex);
        if(matches != null){
            matches.forEach(function(cell){
                csvArray.push(
                    cell.replace(/^"|",$|,$|"$/g,"")
                );
            });
        }
        if(row.match(/,$/)){
            csvArray.push("");
        }
        return csvArray;
    }

    for(var i = 1, len = records.length; i &amp;lt; len; i++){
        var record = csvRowToArray(records[i]);
        sys.puts("(\""+record.join("\",\"") + "\"),");
    }
});
&lt;/pre&gt;
&lt;p&gt;To run it, first install Node (see link above) on your machine and from the command line type:&lt;/p&gt;
&lt;pre class="brush: bash"&gt;node file.js mycsv.csv
&lt;/pre&gt;
&lt;p&gt;Where &amp;#8216;file.js&amp;#8217; is whatever you call the snippet above and the first argument being the name of the .csv you want to have converted.  It will output it to the terminal but you could easy write it to a file with:&lt;/p&gt;
&lt;pre class="brush: bash"&gt;node file.js mycsv.csv &amp;gt; output.txt
&lt;/pre&gt;
&lt;p&gt;Enjoy!&lt;/p&gt;</description><link>http://wavded.tumblr.com/post/435506238</link><guid>http://wavded.tumblr.com/post/435506238</guid><pubDate>Mon, 08 Mar 2010 18:35:00 -0500</pubDate><category>nodejs</category><category>javascript</category></item><item><title>CSS Refresh Update</title><description>&lt;p&gt;&lt;img src="http://media.tumblr.com/tumblr_kyxbn0kiTf1qao14p.png"/&gt;&lt;/p&gt;
&lt;p&gt;CSS Refresh extension has also been ported to Chrome.  I honestly think this kinda stuff should be inside full scale debug tools like Firebug or Web Inspector but until then this works for me.  Hopefully it will help you out too.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://chrome.google.com/extensions/detail/ojcnooebgeenefpfngjfifjcnhlkbbdd"&gt;&lt;a href="https://chrome.google.com/extensions/detail/ojcnooebgeenefpfngjfifjcnhlkbbdd"&gt;https://chrome.google.com/extensions/detail/ojcnooebgeenefpfngjfifjcnhlkbbdd&lt;/a&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The Jetpack one for Firefox is still available as well:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://jetpackgallery.mozillalabs.com/jetpacks/225"&gt;&lt;a href="http://jetpackgallery.mozillalabs.com/jetpacks/225"&gt;http://jetpackgallery.mozillalabs.com/jetpacks/225&lt;/a&gt;&lt;/a&gt;&lt;/p&gt;</description><link>http://wavded.tumblr.com/post/432735498</link><guid>http://wavded.tumblr.com/post/432735498</guid><pubDate>Sun, 07 Mar 2010 13:06:00 -0500</pubDate><category>chrome</category><category>extension</category></item><item><title>CSS Refresh Jetpack</title><description>&lt;p&gt;It has been very helpful to me to be able to use scripts to reload CSS without reloading the whole page.  Unfortunately the Firefox addon (&lt;a href="https://addons.mozilla.org/en-US/firefox/addon/7465"&gt;https://addons.mozilla.org/en-US/firefox/addon/7465&lt;/a&gt;) seems to have ceased being developed and bookmarklets don&amp;#8217;t work well with my work flow.  So I made my first &lt;a&gt;Jetpack&lt;/a&gt;.  Feel free to try it out and let me know what you think.&lt;br/&gt;&lt;br/&gt;&lt;a&gt;&lt;a href="http://rs1.adc4gis.com/browser/jetpack/cssrefresh.html"&gt;http://rs1.adc4gis.com/browser/jetpack/cssrefresh.html&lt;/a&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Update - CSS Refresh is now part of the Jetpack Gallery, check it out here:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="http://jetpackgallery.mozillalabs.com/jetpacks/225"&gt;&lt;a href="http://jetpackgallery.mozillalabs.com/jetpacks/225"&gt;http://jetpackgallery.mozillalabs.com/jetpacks/225&lt;/a&gt;&lt;/a&gt;&lt;br/&gt;&lt;/strong&gt;&lt;/p&gt;</description><link>http://wavded.tumblr.com/post/258714441</link><guid>http://wavded.tumblr.com/post/258714441</guid><pubDate>Thu, 26 Nov 2009 17:15:00 -0500</pubDate><category>css</category><category>firefox</category><category>jetpack</category></item><item><title>Installing Tomcat 6 on CentOS 5</title><description>&lt;p&gt;May be a niche post but after some fighting with my virtual server running CentOS 5 it boiled down to a really simple solution:&lt;/p&gt;
&lt;pre class="brush: bash"&gt;cd /etc/yum.repos.d
wget 'http://www.jpackage.org/jpackage50.repo'
yum update
yum install tomcat6 tomcat6-webapps tomcat6-admin-webapps
service tomcat6 start
&lt;/pre&gt;
&lt;p&gt;If you have problems accessing the server from another machine you may need to do the following:&lt;/p&gt;
&lt;pre class="brush: bash"&gt;setup
"Firewall configuration"
"Customize"
"Other ports" 8080:tcp
"Ok"
service tomcat6 restart
&lt;/pre&gt;
&lt;p&gt;UPDATE:&lt;/p&gt;
&lt;p&gt;If you get a dependency error try this:&lt;/p&gt;
&lt;pre class="brush: bash"&gt;rpm -Uvh 'http://plone.lucidsolutions.co.nz/linux/centos/images/jpackage-utils-compat-el5-0.0.1-1.noarch.rpm'
&lt;/pre&gt;
&lt;p&gt;More info:&lt;a href="http://plone.lucidsolutions.co.nz/linux/centos/jpackage-jpackage-utils-compatibility-for-centos-5.x"&gt;&lt;a href="http://plone.lucidsolutions.co.nz/linux/centos/jpackage-jpackage-utils-compatibility-for-centos-5.x"&gt;http://plone.lucidsolutions.co.nz/linux/centos/jpackage-jpackage-utils-compatibility-for-centos-5.x&lt;/a&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;(update provided by Tony, thanks)&lt;/p&gt;</description><link>http://wavded.tumblr.com/post/258713913</link><guid>http://wavded.tumblr.com/post/258713913</guid><pubDate>Thu, 26 Nov 2009 17:14:00 -0500</pubDate><category>tomcat</category><category>centos</category></item><item><title>Should be simple.</title><description>&lt;p&gt;Trying out this tumblr thing.  Hopefully it will make blogs a breeze.&lt;/p&gt;</description><link>http://wavded.tumblr.com/post/258711587</link><guid>http://wavded.tumblr.com/post/258711587</guid><pubDate>Thu, 26 Nov 2009 17:12:13 -0500</pubDate></item></channel></rss>
