Skip to content

Instantly share code, notes, and snippets.

View mikegioia's full-sized avatar

Mike Gioia mikegioia

View GitHub Profile
@mikegioia
mikegioia / javascript_module_pattern.md
Created March 31, 2016 21:57
JavaScript Module Pattern Quick Overview

Global Import

JavaScript has a feature known as implied globals. Whenever a name is used, the interpreter walks the scope chain backwards looking for a var statement for that name. If none is found, that variable is assumed to be global. If it’s used in an assignment, the global is created if it doesn’t already exist. This means that using or creating global variables in an anonymous closure is easy. Unfortunately, this leads to hard-to-manage code, as it’s not obvious (to humans) which variables are global in a given file.

Luckily, our anonymous function provides an easy alternative. By passing globals as parameters to our anonymous function, we import them into our code, which is both clearer and faster than implied globals. Here’s an example:

(function ($, YAHOO) {
	// now have access to globals jQuery (as $) and YAHOO in this code
}(jQuery, YAHOO));
@mikegioia
mikegioia / imap_fetchheader_test.php
Created December 13, 2015 08:17
Memory allocation leak in imap_fetchheader
<?php
$email = "youremail@gmail.com";
$password = "password123"
$folder = "INBOX";
$imapStream = imap_open(
"{imap.gmail.com:993/imap/ssl}$folder",
$email,
$password );
@mikegioia
mikegioia / clndr_weekends.html
Created July 22, 2015 20:21
Example of a CLNDR template with options to show/hide weekends
<div class="clndr-controls">
<div class="clndr-previous-button">&lsaquo;</div>
<div class="month font-mono"><%= intervalStart.format( 'M/DD' ) + ' &mdash; ' + intervalEnd.format( 'M/DD' ) %></div>
<div class="clndr-next-button">&rsaquo;</div>
</div>
<div class="days-of-the-week font-mono clearfix">
<% i = 0; %>
<% _.each( daysOfTheWeek, function ( day ) { %>
<% if ( extras.show_weekends || ! ( i % 7 === 0 || i % 7 === 6 ) ) { %>
<div class="header-day"><%= day %></div>

Keybase proof

I hereby claim:

  • I am mikegioia on github.
  • I am mikegioia (https://keybase.io/mikegioia) on keybase.
  • I have a public key whose fingerprint is 3F05 8150 9190 DC80 0EA6 FC6A C886 8A2A 4B50 820B

To claim this, I am signing this object:

@mikegioia
mikegioia / phalcon_di_reset.php
Created January 21, 2014 19:20
Testing the DI overwriting and reset methods
<?php
use Phalcon\DI as DI;
class Dummy {
private $test;
function getTest() {
return $this->test;
}
@mikegioia
mikegioia / password_hash.php
Created January 6, 2014 21:15
Functions to hash and verify a password in PHP.
/**
* Hash the password using bcrypt algorithm. This function takes
* in a plaintext password, generates a strong and random salt,
* and returns the crypted password to be stored for the user.
*
* @param string $password
* @return string | false
*/
public static function passwordHash( $password, $options = array() )
{