<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Webmaster-Source &#187; Coding</title>
	<atom:link href="https://www.webmaster-source.com/category/coding/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.webmaster-source.com</link>
	<description>Useful Resources For Webmasters</description>
	<lastBuildDate>Thu, 24 Aug 2017 02:01:18 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.1.42</generator>
	<item>
		<title>Node.js the Right Way</title>
		<link>https://www.webmaster-source.com/2014/01/08/node-js-the-right-way/</link>
		<comments>https://www.webmaster-source.com/2014/01/08/node-js-the-right-way/#comments</comments>
		<pubDate>Wed, 08 Jan 2014 11:29:12 +0000</pubDate>
		<dc:creator><![CDATA[Matt]]></dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[Node.js]]></category>

		<guid isPermaLink="false">http://www.webmaster-source.com/?p=5271</guid>
		<description><![CDATA[Looking to quickly get started with Node.js without learning bad habits? Node.js the Right Way is a short and concise—100 pages—book that you can easily read in an afternoon (maybe two if you&#8217;re following along with the examples), promising a focused, tutorial-based experience. The book makes the assumption that you&#8217;re already somewhat familiar with programming [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><img style=' float: right; padding: 4px; margin: 0 0 2px 7px;'  class="alignright size-full wp-image-5272" alt="Node.js The Right Way" src="//www.webmaster-source.com/wp-content/uploads/2014/01/nodejs-right-way.png" width="160" height="197" />Looking to quickly get started with Node.js without learning bad habits? <em>Node.js the Right Way</em> is a short and concise—100 pages—book that you can easily read in an afternoon (maybe two if you&#8217;re following along with the examples), promising a focused, tutorial-based experience.</p>
<p>The book makes the assumption that you&#8217;re already somewhat familiar with programming and the JavaScript language in particular. Instead of wasting time with absolute basics, it dives right in to Node. The first two chapters explain what exactly Node is, and how the the event loop works. It covers the differences between synchronous and asynchronous tasks, illustrating the reason you want to avoid blocking I/O. The next two chapters deal with sockets, serializing data and message queues. Other sections deal with databases (using CouchDB as an example), unit tests, building and consuming RESTful APIs and single-page web apps.</p>
<p>If you work your way through the examples in the book, you&#8217;ll end up building a reasonably complex web app and batch-importing a bunch of data from Project Gutenberg.</p>
<p><em>Node.js the Right Way</em> is the best introduction to Node that I&#8217;ve seen so far. It&#8217;s concise enough it won&#8217;t take up a lot of your time, covers things more thorougly than a 500-word blog post or hour-long screencast, and there&#8217;s no magic &#8220;just copy and paste this, I&#8217;m not going to bother explaining it.&#8221; You should come out of it knowing where to go to keep learning. It&#8217;s easy enough to think &#8220;I used <a href="expressjs.com">Express</a> for this, and <a href="http://gruntjs.com/">Grunt</a> for that. Maybe I should search for more information about those tools.&#8221;</p>
]]></content:encoded>
			<wfw:commentRss>https://www.webmaster-source.com/2014/01/08/node-js-the-right-way/feed/</wfw:commentRss>
		<slash:comments>158</slash:comments>
		</item>
		<item>
		<title>Illustrating Keyboard Shortcuts with the &lt;kbd&gt; Tag and a Bit of CSS</title>
		<link>https://www.webmaster-source.com/2013/12/27/illustrating-keyboard-shortcuts-kbd-tag/</link>
		<comments>https://www.webmaster-source.com/2013/12/27/illustrating-keyboard-shortcuts-kbd-tag/#comments</comments>
		<pubDate>Fri, 27 Dec 2013 13:16:27 +0000</pubDate>
		<dc:creator><![CDATA[Matt]]></dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[(x)html]]></category>
		<category><![CDATA[HTML5]]></category>

		<guid isPermaLink="false">http://www.webmaster-source.com/?p=5259</guid>
		<description><![CDATA[The HTML spec has long had a (much underutilized) tag called kbd, which is intended to be used for marking up user input. For example, you could write something like this: The browser (by default) renders the kbd tags in a monotype font, just like code and pre. But if you&#8217;re already going to mark [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>The HTML spec has long had a (much underutilized) tag called <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/kbd">kbd</a>, which is intended to be used for marking up user input. For example, you could write something like this:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;p&gt;The most famous keyboard shortcut is probably &lt;kbd&gt;ctrl&lt;/kbd&gt;+&lt;kbd&gt;alt&lt;/kbd&gt;+&lt;kbd&gt;del&lt;/kbd&gt;.&lt;/p&gt;
</pre>
<p>The browser (by default) renders the <code>kbd</code> tags in a monotype font, just like <code>code</code> and <code>pre</code>. But if you&#8217;re already going to mark up keys like that for semantic reasons, why not apply a little styling and make it fancy? (I&#8217;ve seen a few sites do this, Stack Overflow being one of them.)</p>
<p><img style=' display: block; margin-right: auto; margin-left: auto;'  src="//www.webmaster-source.com/wp-content/uploads/2013/12/kbd-tag.png" alt=" Tag" width="491" height="44" class="aligncenter size-full wp-image-5260" /></p>
<pre class="brush: css; title: ; notranslate">
kbd {
	display: inline-block;
	border: 1px solid #ccc;
	border-radius: 3px;
	padding: 0.1em 0.5em;
	margin: 0 0.2em;
	box-shadow: 0 1px 0px rgba(0, 0, 0, 0.2), 0 0 0 2px #ffffff inset;
	background-color: #f7f7f7;
}

</pre>
<p>While the tag isn&#8217;t solely meant for this use case—it can also be used for any user input, such as something you intend the reader to search on Google—I think it&#8217;s a great use. The <code>code</code> element tends to be used for the latter case more often, whether it&#8217;s considered appropriate or not, so styling it like so shouldn&#8217;t get in the way in most cases.</p>
<p>If you have need to display keyboard shortcuts periodically, it&#8217;s definitely a nice touch.</p>
]]></content:encoded>
			<wfw:commentRss>https://www.webmaster-source.com/2013/12/27/illustrating-keyboard-shortcuts-kbd-tag/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Finding a Website&#8217;s Favicon with Ruby</title>
		<link>https://www.webmaster-source.com/2013/09/25/finding-a-websites-favicon-with-ruby/</link>
		<comments>https://www.webmaster-source.com/2013/09/25/finding-a-websites-favicon-with-ruby/#comments</comments>
		<pubDate>Wed, 25 Sep 2013 11:46:02 +0000</pubDate>
		<dc:creator><![CDATA[Matt]]></dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[favicon]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.webmaster-source.com/?p=5187</guid>
		<description><![CDATA[For a project I&#8217;ve been working on, I wanted to to have my Sidekiq worker (which is part of an RSS crawler) discover the favicon for a web site and cache it for later display. It was fun figuring out a way to do this, so I just had to share. A Brief History of [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>For a project I&#8217;ve been working on, I wanted to to have my <a href="http://sidekiq.org/">Sidekiq</a> worker (which is part of an RSS crawler) discover the favicon for a web site and cache it for later display. It was fun figuring out a way to do this, so I just had to share.</p>
<h3>A Brief History of Favicons</h3>
<p><a href="http://en.wikipedia.org/wiki/Favicon">Favicons</a>, or &#8220;shortcut icons,&#8221; can be defined in multiple ways. Like all too many things in web design, browsers handle them in slightly different and mildly incompatible ways, meaning there&#8217;s plenty of redundancy. Favicons came to be when Microsoft added them to Internet Explorer 5 in 1999, implementing a feature where the browser would check the server for a file named <code>favicon.ico</code> and display it in certain parts of the UI. The following year, the W3C published a standard method for defining a favicon. Rather than simply having the browser look for a file in the root directory, an HTML document should specify a file in the header with a <code>&lt;link&gt;</code> tag, just like with stylesheets.<span id="more-5187"></span></p>
<p>Fast forward to the present, and you have a bit of screwiness.</p>
<ul>
<li>All major web browsers check for the link tag first, and fall back to <code>favicon.ico</code> if it&#8217;s not found.</li>
<li>You can define multiple icons in the HTML header. You can have ICO/PNG/GIF formats, as well as different sizes.</li>
<li>Some browsers support larger 32&#215;32 favicons, while others will only use the 16&#215;16 ones. Chrome for Mac prefers the 32&#215;32 ones, and scales them down to 16&#215;16 on Macs without Retina displays.</li>
<li>Big Bad Internet Explorer only supports ICO files for favicons, not PNGs.</li>
</ul>
<p>The most compatible way to set up your favicon is to define both 32&#215;32 and 16&#215;16 icons in your header, using the PNG format, and make a 16&#215;16 ICO formatted one to name &#8220;favicon.ico&#8221; and drop into your web root. Browsers that play nicely will use the PNG ones in whatever dimensions they prefer, and IE will fall back to the ICO file.</p>
<h3>Writing the Class</h3>
<p>Now that the history lesson is out of way, you can see why there&#8217;s a little bit of a challenge here. Depending on how badly you want to find and display that icon, you may have to write logic for the different methods. For this tutorial, I will focus on two. The simplest, which is looking to see if there&#8217;s a <code>favicon.ico</code>, and a basic implementation of checking for a link tag defining a shortcut icon.</p>
<p>Before we do anything else, we need to install a few dependencies. Either add them to your Gemfile and do a <code>bundle install</code>, or use the <code>gem install</code> command to install them manually.</p>
<ul>
<li><a href="http://johnnunemaker.com/httparty/">HTTParty</a> (<code>gem install httparty</code>)</li>
<li><a href="http://nokogiri.org/">Nokogiri</a> (<code>gem install nokogiri</code>)</li>
</ul>
<p>Now require the necessary libraries at the top of a new Ruby file and we can get going.</p>
<pre class="brush: ruby; title: ; notranslate">
require &quot;httparty&quot;
require &quot;nokogiri&quot;
require &quot;base64&quot;
</pre>
<p>We can define a class to make a nice, clean interface for this to keep it modular and easier to reuse. As you can see below, I&#8217;ve made a <code>Favicon</code> class and added some accessors for instance variables, as well as an <code>initialize</code> method that assigns the parameter it receives to the <code>@host</code> instance variable before calling the method we will be defining next.</p>
<pre class="brush: ruby; title: ; notranslate">
require &quot;httparty&quot;
require &quot;nokogiri&quot;
require &quot;base64&quot;


class Favicon


  attr_reader :host
  attr_reader :uri
  attr_reader :base64


  def initialize(host)
    @host = host
    check_for_ico_file
  end


end
</pre>
<p>We&#8217;ll be implementing the simplest part first. The <code>check_for_ico_file</code> method will send an HTTP GET request to <code>/favicon.ico</code> on the server specified in @host and check to see if a file exists. (The server will send a <code>200 OK</code> response if it does, and a <code>404 Not Found</code> error otherwise.) If it does, the URL will be saved to an instance variable and the icon file&#8217;s contents will be base64 encoded before being saved to an instance variable as well.</p>
<p>The HTTParty gem is great for this, since it drastically simplifies simple HTTP requests like this.</p>
<pre class="brush: ruby; title: ; notranslate">
# Check /favicon.ico
def check_for_ico_file
  uri = URI::HTTP.build({:host =&gt; @host, :path =&gt; '/favicon.ico'}).to_s
  res = HTTParty.get(uri)
  if res.code == 200
    @base64 = Base64.encode64(res.body)
    @uri = uri
  end
end
</pre>
<p>If you want, you could go ahead and instantiate the class to try out what we have so far. If you pass it the domain name of a site that uses the <code>/favicon.ico</code> convention, the object should find it without issue.</p>
<pre class="brush: ruby; title: ; notranslate">
favicon = Favicon.new(&quot;arstechnica.com&quot;)

puts favicon.uri
#Outputs http://arstechnica.com/favicon.ico

puts favicon.base64
#Outputs a bunch of base64-encoded gibberish. More on this later

puts puts favicon.host
#Outputs arstechnica.com
</pre>
<p>Now let&#8217;s handle link tags! The process for that is a little bit more in-depth. First we need to request a web page from the server, such as the index page, and parse it for tags that resemble <code>&lt;link rel="shortcut icon" href="..." /&gt;</code>. Then we have to evaluate the contents of <code>href</code> to make sure it&#8217;s an absolute URL, and prepend the domain name if it is not. After that, we can finally make a request to get the icon itself and save it.</p>
<p>Still with me? Excellent, now here&#8217;s the code to do that. I&#8217;ll comment it a little more thoroughly, since it looks messier at a glance.</p>
<pre class="brush: ruby; title: ; notranslate">
# Check &quot;shortcut icon&quot; tag
def check_for_html_tag

  # Load the index page with HTTParty and pass the contents to Nokogiri for parsing
  uri = URI::HTTP.build({:host =&gt; @host, :path =&gt; '/'}).to_s
  res = HTTParty.get(uri)
  doc = Nokogiri::HTML(res)

  # Use an xpath expression to tell Nokogiri what to look for.
  doc.xpath('//link[@rel=&quot;shortcut icon&quot;]').each do |tag|

    # This is the contents of the &quot;href&quot; attribute, which we pass to Ruby's URI module for analysis
    taguri = URI(tag['href'])

    unless taguri.host.to_s.length &lt; 1
      # There is a domain name in taguri, so we're good
      iconuri = taguri.to_s
    else
      # There is no domain name in taguri. It's a relative URI!
      # So we have to join it with the index URL we built at the beginning of the method
      iconuri = URI.join(uri, taguri).to_s
    end

    # Grab the icon and set the instance variables
    res = HTTParty.get(iconuri)
    if res.code == 200
      @base64 = Base64.encode64(res.body)
      @uri = iconuri
    end
    
  end

end
</pre>
<p>Now there&#8217;s one more thing to do before we&#8217;re done. The initialize method needs to be tweaked so it calls our newest method:</p>
<pre class="brush: ruby; title: ; notranslate">
def initialize(host)
  @host = host
  check_for_ico_file
  check_for_html_tag
end
</pre>
<p>Now the class will check for the <code>favicon.ico</code> file first, then the HTML tag. If the HTML tag is present, it will take precedence.</p>
<p class="alertbubble"><strong>Available as a Gist!</strong> For your convenience, the results of this tutorial are <a href="https://gist.github.com/redwallhp/6692349">available as a GitHub Gist.</a></p>
<p></p>
<h3>Using the Class</h3>
<p>Now all you have to do is include the class with a require statement, and grab favicons.</p>
<pre class="brush: ruby; title: ; notranslate">
require &quot;favicon&quot;

favicon = Favicon.new(&quot;arstechnica.com&quot;)

puts favicon.uri
#Outputs http://static.arstechnica.net/favicon.ico

puts favicon.base64
#Outputs a bunch of base64-encoded gibberish. More on this later

puts puts favicon.host
#Outputs arstechnica.com
</pre>
<p>Now&#8230;what of that &#8220;base64-encoded gibberish?&#8221; It&#8217;s the perfect format for a little trick called Data URIs, which you can <a href="http://css-tricks.com/data-uris/">read all about over at CSS-Tricks</a>. If you cache that base64 string somewhere, probably in a database, you can output it like so:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;img width=&quot;16&quot; height=&quot;16&quot; alt=&quot;favicon&quot; src=&quot;data:image/gif;base64,BLAHBBLAHGIBBERISHGOESHERE&quot; /&gt;
</pre>
<p>It will display like any other image, but won&#8217;t use an additional HTTP request, because the image data is already embedded on the page. This makes it perfect for a list of web sites with icons beside them. Instead of kicking off several HTTP requests for individual tiny images, you just embed them right in the page.</p>
<p>If you&#8217;re unfortunate enough that you must support antique versions of Internet Explorer (version seven or prior) then you can&#8217;t use Data URIs, as they were not supported. However, all is not lost. You could conceivably adapt the class and have it write the image data to files on the server instead of base64-encoding them.</p>
]]></content:encoded>
			<wfw:commentRss>https://www.webmaster-source.com/2013/09/25/finding-a-websites-favicon-with-ruby/feed/</wfw:commentRss>
		<slash:comments>101</slash:comments>
		</item>
		<item>
		<title>JavaScript is the Most Popular Language on GitHub, with Ruby Coming in Second</title>
		<link>https://www.webmaster-source.com/2013/08/14/javascript-is-the-most-popular-language-on-github-with-ruby-coming-in-second/</link>
		<comments>https://www.webmaster-source.com/2013/08/14/javascript-is-the-most-popular-language-on-github-with-ruby-coming-in-second/#comments</comments>
		<pubDate>Wed, 14 Aug 2013 11:45:32 +0000</pubDate>
		<dc:creator><![CDATA[Matt]]></dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[GitHub]]></category>

		<guid isPermaLink="false">http://www.webmaster-source.com/?p=5157</guid>
		<description><![CDATA[On a whim, I decided to browse through GitHub&#8217;s Explore section recently. I don&#8217;t know whether users go there often or not (I certainly don&#8217;t), but there are some intriguing statistics there that tell a thing or two about what&#8217;s popular and who&#8217;s using GitHub these days. Some are a little surprising. JavaScript is the [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><img style=' float: right; padding: 4px; margin: 0 0 2px 7px;'  class="alignright size-full wp-image-4687" alt="github-icon" src="//www.webmaster-source.com/wp-content/uploads/2012/01/github-icon.png" width="128" height="128" />On a whim, I decided to browse through GitHub&#8217;s <a href="https://github.com/explore">Explore</a> section recently. I don&#8217;t know whether users go there often or not (I certainly don&#8217;t), but there are some intriguing statistics there that tell a thing or two about what&#8217;s popular and who&#8217;s using GitHub these days. Some are a little surprising.</p>
<p><strong>JavaScript is the Most Popular Language, with Ruby Coming in Second</strong></p>
<p>I was surprised at first, as I had initially assumed the graph was referring to Node.js. Then I <a href="http://i.imgur.com/tKwJzRX.jpg">facepalmed</a> when I realized that, obviously, most of that is client-side JavaScript.</p>
<p>Ruby is well ahead of Python, which is way down in the #5 slot, below Java and shell scripts. Considering how many times Redditors have tried to tell me that Python has a larger and more active community, despite my previous observations, I found it amusing. (I&#8217;m a fairly recent adopter of the Ruby language, which I chose to invest time in learning—over Python—partially because of its large, thriving community of developers.)</p>
<p>PHP, strangely, is even lower on the list than Python. PHP is definitely used more widely than either Ruby or Python, yet its found in comparatively few repositories on GitHub. There are a few points of speculation I take away from this:</p>
<ul>
<li>There isn&#8217;t too much overlap between Git users and PHP users. One could argue that since a large portion of PHP users are beginner developers, they haven&#8217;t picked up source control yet.</li>
<li>The average PHP developer could be working on closed source projects for one reason or another. Either for work reasons or because they haven&#8217;t been bitten by the FOSS bug yet. Or they&#8217;re working on a hobby project that&#8217;s going to be The Next Big Thing, and they want to keep it closed.</li>
<li>There&#8217;s a difference between active developers creating unique projects, and end users dropping in a pre-made script to run. Sure, PHP definitely has the widest install base. It&#8217;s astronomical. But how many developers out there choose to work with it to create open source projects?</li>
</ul>
<p><img style=' display: block; margin-right: auto; margin-left: auto;'  class="aligncenter size-full wp-image-5158" alt="The most popular languages on GitHub" src="//www.webmaster-source.com/wp-content/uploads/2013/08/githubstats-languages.png" width="600" height="245" /></p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>https://www.webmaster-source.com/2013/08/14/javascript-is-the-most-popular-language-on-github-with-ruby-coming-in-second/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Custom JavaScript Twitter Widgets in an API 1.1 World</title>
		<link>https://www.webmaster-source.com/2013/07/03/custom-javascript-twitter-widgets-in-an-api-1-1-world/</link>
		<comments>https://www.webmaster-source.com/2013/07/03/custom-javascript-twitter-widgets-in-an-api-1-1-world/#comments</comments>
		<pubDate>Wed, 03 Jul 2013 11:46:27 +0000</pubDate>
		<dc:creator><![CDATA[Matt]]></dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.webmaster-source.com/?p=5131</guid>
		<description><![CDATA[Continuing their gradual shutdown of old APIs (following the launch of version 1.1 of their API), Twitter recently pulled the plug on their old-style widgets and the unauthenticated search API. This means if you had a fancy custom-designed JavaScript widget to show off your latest tweets, it&#8217;s not going to work anymore. The only officially [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><a href="http://matt.harzewski.com/"><img style=' float: right; padding: 4px; margin: 0 0 2px 7px;'  class="alignright size-full wp-image-5132" alt="My Twitter Widget" src="//www.webmaster-source.com/wp-content/uploads/2013/06/mvhtwitterwidget.png" width="200" height="382" /></a>Continuing their gradual shutdown of old APIs (following the launch of version 1.1 of their API), Twitter recently pulled the plug on their old-style widgets and the unauthenticated search API. This means if you had a fancy custom-designed JavaScript widget to show off your latest tweets, it&#8217;s not going to work anymore. The only officially supported options are the <a href="https://twitter.com/settings/widgets">new widgets</a> or a server-side solution with OAuth authentication.</p>
<p>What can you do if you don&#8217;t like either option?</p>
<p><a href="http://jasonmayes.com/projects/twitterApi/">Jason Mayes</a> hacked together <a href="http://codepen.io/jasonmayes/pen/Ioype">a clever bit of JavaScript</a> that loads up one of the new Twitter widgets, scrapes the content out, and reformats it into nicer unstyled HTML. Then you can style it however you want in your stylesheet.</p>
<p>I&#8217;m using this right now on <a href="http://matt.harzewski.com/">my personal blog</a>, since Twitter&#8217;s new widgets don&#8217;t look very good when they&#8217;re crammed into a narrow sidebar.</p>
]]></content:encoded>
			<wfw:commentRss>https://www.webmaster-source.com/2013/07/03/custom-javascript-twitter-widgets-in-an-api-1-1-world/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Find the Number of Lines in a Git Repository</title>
		<link>https://www.webmaster-source.com/2013/05/29/find-the-number-of-lines-in-a-git-repository/</link>
		<comments>https://www.webmaster-source.com/2013/05/29/find-the-number-of-lines-in-a-git-repository/#comments</comments>
		<pubDate>Wed, 29 May 2013 11:07:09 +0000</pubDate>
		<dc:creator><![CDATA[Matt]]></dc:creator>
				<category><![CDATA[Coding]]></category>

		<guid isPermaLink="false">http://www.webmaster-source.com/?p=5082</guid>
		<description><![CDATA[Want to figure out how many lines of code are in your Git repository? I&#8217;ve had an alias in my .bashrc file for ages that does just that. It uses git ls-files to generate a list of files, which it then passes it to the wc command, which generates word and character count statistics (the [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Want to figure out how many lines of code are in your Git repository? I&#8217;ve had an alias in my <code>.bashrc</code> file for ages that does just that.</p>
<pre class="brush: bash; title: ; notranslate">git ls-files | xargs wc -l</pre>
<p>It uses <code>git ls-files</code> to generate a list of files, which it then passes it to the wc command, which generates word and character count statistics (the &#8220;l&#8221; flag makes it count lines).</p>
<p>Obviously the line is a bit of a mouthful (handful?). So you can create an easier alias, like &#8220;gitlines&#8221; and put it in your <code>.bashrc</code> file.</p>
<pre class="brush: bash; title: ; notranslate">alias gitlines=&quot;git ls-files | xargs wc -l&quot;</pre>
]]></content:encoded>
			<wfw:commentRss>https://www.webmaster-source.com/2013/05/29/find-the-number-of-lines-in-a-git-repository/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How Amazon Solved the Dropdown Delay Problem</title>
		<link>https://www.webmaster-source.com/2013/03/20/how-amazon-solved-the-dropdown-delay-problem/</link>
		<comments>https://www.webmaster-source.com/2013/03/20/how-amazon-solved-the-dropdown-delay-problem/#comments</comments>
		<pubDate>Wed, 20 Mar 2013 11:24:51 +0000</pubDate>
		<dc:creator><![CDATA[Matt]]></dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Amazon]]></category>
		<category><![CDATA[menus]]></category>
		<category><![CDATA[UI]]></category>

		<guid isPermaLink="false">http://www.webmaster-source.com/?p=5035</guid>
		<description><![CDATA[If you&#8217;ve ever made a dropdown menu, you&#8217;re probably familiar with the &#8220;hover delay problem,&#8221; where a user tries to diagonally move the mouse from a submenu trigger to the menu that pops out, which causes the menu to snap closed when it loses focus. A common remedy is to add a delay, so the [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>If you&#8217;ve ever made a dropdown menu, you&#8217;re probably familiar with the &#8220;hover delay problem,&#8221; where a user tries to diagonally move the mouse from a submenu trigger to the menu that pops out, which causes the menu to snap closed when it loses focus. A common remedy is to add a delay, so the user has time to get their cursor from point A to point B without the menu closing or changing. Unfortunately, this makes menus seem sluggish, as there&#8217;s a small (but noticeable) delay before menus open or change.</p>
<p>Amazon, however, uses a more advanced trick, which cleverly solves the problem while enabling the menu to be snappy and delay-free. They track the cursor movement to determine the user&#8217;s intent. If it&#8217;s moving diagonally toward the submenu, the menu stays open. If it&#8217;s moving down the list, the submenu instantly changes. No delays making it seem sluggish, and no irritations from glitchy menus.</p>
<p>Ben Kamens, lead developer at Khan Academy, <a href="http://bjk5.com/post/44698559168/breaking-down-amazons-mega-dropdown">described this behavior in an interesting blog post</a> and released a jQuery plugin that replicates it.</p>
<p><img style=' display: block; margin-right: auto; margin-left: auto;'  class="aligncenter size-full wp-image-5036" alt="Amazon Menu Triangle" src="//www.webmaster-source.com/wp-content/uploads/2013/03/amazon-menu-intent.png" width="600" height="413" /></p>
<p>As it turns out, Apple has been using the same principle for their OS&#8217;s menus for a long time. At least since the early 1990s, perhaps earlier, though I&#8217;m not familiar enough with Apple&#8217;s history to pinpoint exactly when. It&#8217;s funny how often the wheel is reinvented&#8230;</p>
<p><a href="http://bjk5.com/post/44698559168/breaking-down-amazons-mega-dropdown">Breaking down Amazon’s mega dropdown</a> [Ben Kamens]</p>
]]></content:encoded>
			<wfw:commentRss>https://www.webmaster-source.com/2013/03/20/how-amazon-solved-the-dropdown-delay-problem/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Method Chaining in PHP</title>
		<link>https://www.webmaster-source.com/2013/03/13/method-chaining-in-php/</link>
		<comments>https://www.webmaster-source.com/2013/03/13/method-chaining-in-php/#comments</comments>
		<pubDate>Wed, 13 Mar 2013 10:40:50 +0000</pubDate>
		<dc:creator><![CDATA[Matt]]></dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.webmaster-source.com/?p=5027</guid>
		<description><![CDATA[Have you ever come across a PHP class that connects methods together in a single line to achieve some goal? (If you haven&#8217;t, Guzzle and SwiftMail are a couple of examples.) jQuery also operates in a similar manner, using the same principle. The technique is called method chaining, and is quite useful in cases where [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Have you ever come across a PHP class that connects methods together in a single line to achieve some goal? (If you haven&#8217;t, <a href="http://guzzlephp.org/">Guzzle</a> and <a href="http://swiftmailer.org/docs/messages.html">SwiftMail</a> are a couple of examples.)</p>
<pre class="brush: php; title: ; notranslate">
//Example from http://guzzlephp.org/
$client = new Client($url);
$request = $client-&gt;get('/user')-&gt;setAuth('user', 'pass');
$response = $request-&gt;send();
</pre>
<p>jQuery also operates in a similar manner, using the same principle. The technique is called <em>method chaining</em>, and is quite useful in cases where a class has many public methods that could be called upon with each others&#8217; output.</p>
<p>If you wanted, the above example could conceivably be rewritten like this:</p>
<pre class="brush: php; title: ; notranslate">
$client = new Client($url);
$path = $client-&gt;get('/user');
$request = $path-&gt;setAuth('user', 'pass');
$response = $request-&gt;send();
</pre>
<p>This works because of the way chainable methods are set up. The secret to making it work is that <strong>every method must return the entire object.</strong> What you&#8217;re doing when you chain Method A with Method B (<code>$object->methodA()->methodB</code>) is calling Method B from the object returned by Method A, which it returned from the object that called it to begin with.</p>
<p>Here&#8217;s an example class that permits chaining, since there&#8217;s no way that code could be more syntactically awkward than that sentence:</p>
<pre class="brush: php; title: ; notranslate">
class MyClass {

	function __construct() {
		$this-&gt;thing = &quot;a&quot;;
	}

	function addB() {
		$this-&gt;thing .= &quot;b&quot;;
		return $this;
	}

	function addC() {
		$this-&gt;thing .= &quot;c&quot;;
		return $this;
	}

	function __tostring() {
		return $this-&gt;thing;
	}

}

$obj = new MyClass();
echo $obj-&gt;addB()-&gt;addC(); //outputs &quot;abc&quot;
echo $obj-&gt;addB(); //outputs &quot;ab&quot;
echo $obj-&gt;addC(); //outputs &quot;ac&quot;
echo $obj; //outputs &quot;a&quot;
</pre>
<p>When you initialize the object, the constructor sets the <code>thing</code> property to be <code>a</code>. Each one of the methods returns <code>$this</code>, which of course is the entire object. So if you call <code>addB()</code>, it adds <code>b</code> to the string and then returns <code>$this</code>. So you can chain the <code>addC()</code> method, which is basically calling it on the <code>$this</code> that <code>addB()</code> returned.</p>
<p>I hope this helps you understand method chaining. It took me a little while to figure it out, and explaining it clearly is about as easy as reading this probably is. <img src="https://www.webmaster-source.com/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley" /></p>
]]></content:encoded>
			<wfw:commentRss>https://www.webmaster-source.com/2013/03/13/method-chaining-in-php/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Generating a Software License Key String with PHP</title>
		<link>https://www.webmaster-source.com/2013/02/13/generating-a-software-license-key-string-with-php/</link>
		<comments>https://www.webmaster-source.com/2013/02/13/generating-a-software-license-key-string-with-php/#comments</comments>
		<pubDate>Wed, 13 Feb 2013 11:20:38 +0000</pubDate>
		<dc:creator><![CDATA[Matt]]></dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.webmaster-source.com/?p=4998</guid>
		<description><![CDATA[I was working on a project recently that required unique API keys to be generated for clients connecting to the server. For various reasons, I settled on the style of license key you commonly see for software packages. You know, the kind you always had to read off the back of a CD case and [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>I was working on a project recently that required unique API keys to be generated for clients connecting to the server. For various reasons, I settled on the style of license key you commonly see for software packages. You know, the kind you always had to read off the back of a CD case and type in when installing the application. Like <code>H8OV7-HNTB5-JLLOH-W8FG2</code>.</p>
<p>It&#8217;s fairly easy to write such a function. The basic idea is to loop around four times—once for each segment—and have a nested loop that runs five times, picking a random character each time. Here&#8217;s what I came up with:</p>
<pre class="brush: php; title: ; notranslate">
function generate_key_string() {

	$tokens = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
	$segment_chars = 5;
	$num_segments = 4;
	$key_string = '';

	for ($i = 0; $i &lt; $num_segments; $i++) {

		$segment = '';

		for ($j = 0; $j &lt; $segment_chars; $j++) {
    			$segment .= $tokens[rand(0, 35)];
		}

		$key_string .= $segment;

		if ($i &lt; ($num_segments - 1)) {
    			$key_string .= '-';
		}

	}

	return $key_string;

}
</pre>
<p>The <code>$tokens</code> string contains the characters that are valid in the key, so the loop can pick from it. The <code>$segment_chars</code> and <code>$num_segments</code> variables are the number of characters in a segment and the number of segments in the key, respectively. <code>$key_string</code> is an empty string that the loop will add the characters into.</p>
<p>The first for loop runs four times, assuming the desired result is four segments in the key. The inner loop picks a character out of <code>$tokens</code> at random each time it goes around. (PHP strings are also arrays, with the each character having its own numerical offset.) The characters are tacked onto the <code>$segment</code> string.</p>
<p>Then the segment is joined with the <code>$key_string</code>, and a dash character is applied if the loop isn&#8217;t on the final segment yet. End result: something like <code>H8OV7-HNTB5-JLLOH-W8FG2</code>.</p>
<p>Now how can you make sure the key is unique when it&#8217;s generated?</p>
<pre class="brush: php; title: ; notranslate">
do {
	$key_string = generate_key_string();
	$result = $db-&gt;query(&quot;SELECT license_key FROM my_license_key_table WHERE license_key = '$key_string'&quot;);
	//$db is a PDO object. If you're not familiar with PDO, check out http://www.webmaster-source.com/2011/08/05/getting-your-feet-wet-with-pdo-and-migrating-old-mysql-code/
} while ($result != false);
</pre>
<p>You generate a new key string with the function, check to see if it exists in your database, and lather/rinse/repeat until that is no longer the case. Usually you won&#8217;t have collisions too often, so it will only need to run once. I&#8217;m too lazy to figure out the probability, but considering there are 52,521,875 possible combinations for <em>one</em> 5-character segment&#8230;you&#8217;re probably not going to run into performance issues anytime soon. And if you do, just add another segment onto your key strings.</p>
]]></content:encoded>
			<wfw:commentRss>https://www.webmaster-source.com/2013/02/13/generating-a-software-license-key-string-with-php/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>PHP: The Right Way</title>
		<link>https://www.webmaster-source.com/2013/01/23/php-the-right-way/</link>
		<comments>https://www.webmaster-source.com/2013/01/23/php-the-right-way/#comments</comments>
		<pubDate>Wed, 23 Jan 2013 11:42:30 +0000</pubDate>
		<dc:creator><![CDATA[Matt]]></dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.webmaster-source.com/?p=4980</guid>
		<description><![CDATA[There’s a lot of outdated information on the Web that leads new PHP users astray, propagating bad practices and bad code. This must stop. PHP: The Right Way is an easy-to-read, quick reference for PHP best practices, accepted coding standards, and links to authoritative tutorials around the Web. PHP: The Right Way is a useful [&#8230;]]]></description>
				<content:encoded><![CDATA[<blockquote><p>There’s a lot of outdated information on the Web that leads new PHP users astray, propagating bad practices and bad code. This must stop. <a href="http://www.phptherightway.com/"><em>PHP: The Right Way</em></a> is an easy-to-read, quick reference for PHP best practices, accepted coding standards, and links to authoritative tutorials around the Web.</p></blockquote>
<p><a href="http://www.phptherightway.com/"><em>PHP: The Right Way</em></a> is a useful guide to how to write PHP that won&#8217;t make other developers cringe in horror. It starts off with some tips on how to manage your development environment and then gets to the good part: what not to do. Advice is featured on matters such as database access, password hashing, and other security issues.</p>
<p>The site is an excellent central resource that gives a good overview of things that every beginning PHP developer should be aware of.</p>
]]></content:encoded>
			<wfw:commentRss>https://www.webmaster-source.com/2013/01/23/php-the-right-way/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/


Served from: www.webmaster-source.com @ 2026-04-14 03:54:59 by W3 Total Cache
-->