Skip to content

Instantly share code, notes, and snippets.

View mcamiano's full-sized avatar

Mitch Amiano mcamiano

  • Rolesville, North Carolina, USA
View GitHub Profile
@mcamiano
mcamiano / alternative.md
Last active December 20, 2015 14:39
ng-hide and ng-show do not modify the DOM so much as change a class. This attribute directive removes the contained content if the expression evaluates to true.

This is an improved alternative to the occlude directive. Suppose we want the occlude to happen dynamically, when a model changed. The other version of the occlude directive defined here would just be invoked once, at the time the link function is called on an instantiated template. Ideally, model changes should drive such DOM manipulations through watchers.

So let's set up a boolean select box. First some model driving the options in the controller:

  $scope.cfg={};
  $scope.cfg.boolean_options = [ {label: 'True', value:true}, {label: 'False', value:false} ];

  $scope.cfg.include_exclude = true;
@mcamiano
mcamiano / testInABox.php
Created June 1, 2012 20:14
Poor man's php unit testing.
if (realpath(__FILE__) == realpath($_SERVER["SCRIPT_FILENAME"])) { exit; }
function Scenario($msg=NULL) {
echo "<style>.bad { color: red; } .good { color: green; } .when { border: solid thin black; color: black; width: 75%; position: relative; margin-left: auto; margin-right: auto; margin-top: 2em;}</style>";
echo "<h1>Scenario: ".(is_null($msg) ? basename(__FILE__) : htmlspecialchars($msg))."</h1>";
}
function When($msg) {
echo "<fieldset class='when'><legend>When: ".htmlspecialchars($msg)."</legend>";
}
function Then( $content ) {
@mcamiano
mcamiano / _vimrc
Created May 15, 2012 18:09
Installing VIM under Windows
set nocompatible
set backupdir=~/tmp " keep vim's temp files out of your repos
" Use pathogen to easily modify the runtime path to include all plugins under
" the ~/.vim/bundle directory
filetype off " force reloading *after* pathogen loaded
call pathogen#helptags()
call pathogen#runtime_append_all_bundles()
filetype plugin indent on " enable detection, plugins and indenting in one step
@mcamiano
mcamiano / .rvmrc
Created May 9, 2012 18:29
"Controller" and routes for weather underground inquiry via Sinatra
rvm use ruby-1.8.7-p302@sinatra
@mcamiano
mcamiano / wunderground_inquiry.rb
Created May 9, 2012 16:59
Weather Underground Ruby Sample; Show current temps in F, download radar animation gif and launch Safari to view it
#!/usr/bin/env ruby
# See http://api.wunderground.com/weather/api/d/documentation.html
require 'open-uri'
require 'json'
zip=ARGV[0]||27571
apikey=YOURWUGAPIKEYHERE
open("http://api.wunderground.com/api/#{apikey}/conditions/forecast/q/#{zip}.json") do |f|
json_string = f.read
@mcamiano
mcamiano / enumerable_nil.txt
Created April 16, 2012 14:04
Enumerable nil
$ rails c
nLoading development environment (Rails 3.2.1)
1.9.3p0 :001 > nil
=> nil
1.9.3p0 :002 > nil.nil?
=> true
1.9.3p0 :004 > nil.each
@mcamiano
mcamiano / OneOffQuery.php
Created April 9, 2012 18:55
One-off PHP/mySql Query
<?php
/**
* @package One-off mySQL Query in PHP via mysqli
* @description Express a query as an object in PHP
* @version 1.0
* @copyright Copyright 2010 by Mitchell Amiano All Rights Reserved.
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
* */
@mcamiano
mcamiano / joomlaOneTimePad.php
Created April 9, 2012 02:41
One-shot status update for Joomla 1.5* component (not tested)
<?php
/**
* @package One-time pad signal script
* @description Feedback signal via HTTP GET or POST using a one-time pad communicated through a separate process, as an alternative to the convoluted Joomla! 1.5.x XMLRPC feature.
* @version 1.0
* @copyright Copyright 2010 by Mitchell Amiano All Rights Reserved.
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
* */
// place this script in a non-Web accessible location, then require it from a wrapper script
@mcamiano
mcamiano / jQuery Contrasty plugin
Created January 13, 2012 14:14
An example of: jQuery+CDN+plugin+QUnit for the WCAG 2.0 contrast algorithm
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>jQuery Contrast Checking Plugin</title>
<style type="text/css">
article, aside, figure, footer, header, hgroup,
menu, nav, section { display: block; }
</style>
@mcamiano
mcamiano / hyper-schema.js
Created December 21, 2011 17:44
Visualize a JS Schema by mapping to XML
/* this is a lot of probably unnecessary crap brought in from Compass.
*/
@import url(http://fonts.googleapis.com/css?family=Nixie+One:400);
@import url(http://fonts.googleapis.com/css?family=Cabin:500);
/* line 17, ../../../.rvm/gems/ruby-1.9.2-p0@global/gems/compass-0.11.1/frameworks/compass/stylesheets/compass/reset/_utilities.scss */
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,