Skip to content

Instantly share code, notes, and snippets.

@aradnom
aradnom / _checkbox-input.sass
Created September 30, 2015 22:07
Checkbox input sass
.checkbox-input
display: block
position: relative
background-color: rgba(#000, 0.2)
border-bottom: 1px solid rgba(#fff, 0.2)
overflow: hidden
&__input
display: none
@aradnom
aradnom / checkbox-input.html
Created September 30, 2015 22:05
Checkbox input
<div class="checkbox-input">
<input class="checkbox-input__input" id="card-default" name="card-default" type="checkbox" ng-model="creditCard.default">
<label class="checkbox-input__label" for="card-default">Make this my default card</label>
</div>
@aradnom
aradnom / arrayStringToProperties.js
Created September 28, 2015 19:37
Explode array component string into usable array of properties, i.e. 'field[subfield1][subfield2][subfield3]' => ["field", "subfield1", "subfield2", "subfield3"]
/**
* Explode array component string into usable array of properties, i.e.
* 'field[subfield1][subfield2][subfield3]' =>
* ["field", "subfield1", "subfield2", "subfield3"]
*
* @param {String} string String of fields
*
* @return {Array} Returns array of field properties
*/
function arrayStringToProperties ( string ) {
@aradnom
aradnom / sailsjs-hooks.txt
Created September 19, 2015 00:27
Sails.js default hooks - list of all hooks packaged by default with Sails.js
Loaded hooks (in the order they are loaded):
hook:moduleloader:loaded
hook:userconfig:loaded
hook:userhooks:loaded
hook:logger:loaded
hook:request:loaded
hook:blueprints:loaded
hook:responses:loaded
hook:controllers:loaded
@aradnom
aradnom / auto-paragraph.js
Created August 11, 2015 17:41
Simple auto-paragraph for JavaScript
/**
* Convert text containing newlines to paragraph'd markup.
*
* @param {String} text Text to add p tags to
*
* @return {String} Returns paragraphized text
*/
function autoParagraph ( text ) {
return '<p>' + text.split( /\n+/ ).join( '</p>\n<p>' ) + '</p>';
}
@aradnom
aradnom / riotjs-router.js
Created July 15, 2015 05:43
First attempt at a simple router in Riot.js.
// Create new observable for watching route changes
var Router = riot.observable();
// Process routes on both route change and initial load
riot.route( processRoute );
riot.route.exec( processRoute );
// Expose the Router object
riot.mixin( 'Router', Router );
@aradnom
aradnom / dashes-to-camelcase.js
Created July 1, 2015 18:11
Dashes to camelCase
/**
* Given a string-like-this, return a stringLikeThis.
*
* @param {String} str String to transform
*
* @return {String} Returns camelCased string
*/
function dashesToCamelCase ( str ) {
return str
.split( '-' )
@aradnom
aradnom / repeatDoneEvent.js
Created March 30, 2015 17:19
Simple directive for firing an event when ng-repeat is finished populating.
'use strict';
/**
* Simple directive for emitting an event when repeat is finished
*/
App.directive( 'repeatDoneEvent', function ( $window ) {
return function( scope, element, attrs ) {
if ( scope.$last ) {
// At this point, ng-repeat is done populating - but we're not finished
// yet because $compile still has to compile any tags in the repeat
@aradnom
aradnom / camelcase-to-display.js
Created March 2, 2015 19:02
Given a camelcased string, return the formatted (display version) of the string, i.e. returnThisString --> Return This String
return ('' + str).match( /[A-Z]?[a-z]+/g )
.map( function ( v ) { return v.substr( 0, 1 ).toUpperCase() + v.substr( 1, v.length ); } )
.join( ' ' );
@aradnom
aradnom / array-intersect.php
Created February 4, 2015 21:00
Performs a true array intersection (array_uintersect will keep items in a1 even if they are not present in a2, a3, etc.)
$combined = array_filter($array1, function ($a) use ($array2) {
$found = array_filter($array2, function ($b) use ($a) {
return ((int) $a->ID) === ((int) $b->ID);
});
return !empty($found);
});