Skip to content

Instantly share code, notes, and snippets.

View nathggns's full-sized avatar

Nate Higgins nathggns

View GitHub Profile
@nathggns
nathggns / example.php
Created December 27, 2012 02:23
Is defining an array before appending to it strictly necessary.
<?php
// Make sure there is an array to append to.
if (!isset($this->handlers[$type])) {
$this->handlers[$type] = [];
}
// Append the error handler
$this->handlers[$type][] = $handler;
@nathggns
nathggns / object.js
Created December 21, 2012 16:46
Javascript Object Model
var Obj = (function() {
// Private Methods
var private = {};
// Instance Variables
var variables = {};
// Public Methods
var methods = {};
@nathggns
nathggns / contains_null.php
Created December 18, 2012 17:47
Check if an array just contains null
<?php
function contains_null($value) {
$all_null = true;
foreach ($value as $val) {
if (!is_null($val)) {
$all_null = false;
break;
}
}
@nathggns
nathggns / account.php
Created November 21, 2012 22:56
Status and Account
<?php
class Account extends AppModel {
var $hasOne = array(
'Status' => array(
'foreignKey' => false,
'conditions' => array(
'Account.store = Status.store'
)
@nathggns
nathggns / duplicates.sql
Created November 21, 2012 19:43
Find duplicates in a table based on a hash generated from the row.
SELECT *, count(*) as num, count(hash) FROM table GROUP BY hash HAVING num > 1
@nathggns
nathggns / store.js
Created November 2, 2012 22:59
Reliable replacement for {} dicts.
// Store object
var Store = (function() {
var id = 0;
var getObjectId = function(obj) {
if (!obj) obj = this;
if (this !== obj) return getObjectId.call(obj);
if (typeof this.__objectId === 'undefined') {
@nathggns
nathggns / README.md
Created October 17, 2012 22:23
PHP namespaces do not resolve upwards

This is the same as trying to reference stuff in the global namespace, such as PHPs predefined functions. We shouldn't have to prefix them with "", they should just resolve anyway.

@nathggns
nathggns / dabblet.css
Created October 10, 2012 22:38 — forked from anonymous/dabblet.css
Untitled
* { padding: 0; margin: 0; }
body { background: #eeeeee; }
img {
-webkit-filter: grayscale(100%);
position: absolute;
top: 50%;
left: 50%;
margin-top: -150px;
margin-left: -150px;
-webkit-animation: down 1s ease, scale 1s ease .5s;
@nathggns
nathggns / sass:less.md
Created October 5, 2012 21:38
Sass/Less

Firstly, I'd like to debunk any claims that I can't have a valid reason because I "don't use LESS enough". My work actually uses LESS for all it's sites, and I use Compass for all my personal projects.

Talking about Compass, that's actually my first point. I am yet to see any extension for less that makes CSS as easy as Compass does. I no longer have to worry about vendor prefixes, and I don't need to worry about code bloat, as it only gives you vendor prefixes for browsers that will actually use on them. You can also autogenerate sprites, autominify your code output, in browser mesages for error messages (using some cool psuedo element techniques), it can output so many different prefered outputs, it's freaking awesome.

Another reason, is it's syntax is closed to CSS in my opinion. Anything that could use a block, or includes something,

@nathggns
nathggns / test.php
Created September 29, 2012 19:36
$_SERVER['SCRIPT_FILENAME'] works on the CLI.
var_dump($argv, $_SERVER['SCRIPT_FILENAME'], __FILE__);
// array(1) {
// [0]=>
// string(9) "index.php"
// }
// string(9) "index.php"
// string(44) "/Users/Nathaniel/Projects/Scaffold/index.php"