Skip to content

Instantly share code, notes, and snippets.

View nathggns's full-sized avatar

Nate Higgins nathggns

View GitHub Profile
@nathggns
nathggns / replace.php
Created July 1, 2013 12:54
Convert Short Tags to open tags (Respect whitespace)
<?php
define('DS', DIRECTORY_SEPARATOR);
/**
* Recursive glob
*/
function recursive_glob($pattern, $flags = 0) {
$files = glob($pattern, $flags);
foreach (glob(dirname($pattern) . DS . '*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir) {
@nathggns
nathggns / latest.sh
Created July 1, 2013 10:57
Get the SHA1 of your latest git commit
git log -n 1 | grep commit | awk ' { print $2 } '| tr -s " "
@nathggns
nathggns / dabblet.css
Created June 21, 2013 13:08
Untitled
.container { width: 140px; height: 140px; background: green; position: relative; }
.circle { border-radius: 100%; }
.circle.o--hidden {
-webkit-mask-image: -webkit-radial-gradient(circle, white, black);
}
.size-of-parent { width: 100%; height: 100%; }
.shadow {
box-shadow: 0 0 200px rgba(0, 0, 0, .5) inset, 0 0 20px rgba(0, 0, 0, .5) inset;
}
.on-top {
@nathggns
nathggns / in_viewport.js
Created June 21, 2013 09:44
Is element visible in the viewport?
(function(window, $) {
$.fn.in_viewport = function(parent) {
if (typeof parent === 'undefined') parent = window;
var $child = this;
if (!$child.is(':visible')) return false;
var $parent = $(parent);
@nathggns
nathggns / regex
Last active December 18, 2015 05:39
This can be used to parse command line arguments
/
(?: # start parameter
(?: # start key value section
(?<keys> # start key
(?: # start long key
--[^=\s]+ # long key
) # end long key
|
(?: # start short key
-[^=] # short key
@nathggns
nathggns / question.md
Last active December 15, 2015 20:08
Question about lazy-loaded models.

Question

In a lazy-loaded model, should all data be loaded from the database when asking for a value (SELECT * FROM ...), so there is only one db query, or just the value you asked for (SELECT value FROM...), so there is a db query for every value you ask for (cached).

Effiency, speed, and database load should all be considered.

Example Comparison:

All data:

@nathggns
nathggns / README.md
Last active December 15, 2015 18:48
Refined version of @andrewhathaway and @dannylepage's site module pattern.
@nathggns
nathggns / namespacing.md
Created January 7, 2013 04:35
What's so bad about PHP namespacing?

What's bad about Namespacing?

Nearly everything about PHP namespacing is absolutely terrible.

Standard Library

If you use PHP namespacing and you want to use a class from the standard library, you have to use a fully qualified class name.

php
@nathggns
nathggns / echo.php
Created January 2, 2013 22:00
Correct way of echoing HTML via PHP
<?php
if (/* condition */):
?><a href="#">...</a><?php
endif;
@nathggns
nathggns / merge.php
Created December 27, 2012 15:04
PHP recursively merge arrays while overwriting non-array values.
<?php
/**
* Recursively merge arrays, overwriting non-array values.
*
* @param array $first First array
* @param array $second Second array
* ...
*/
function array_merge_recursive_overwrite() {
// Get all of our arguments