Skip to content

Instantly share code, notes, and snippets.

View swashcap's full-sized avatar
Writing code

Cory Reed swashcap

Writing code
View GitHub Profile
@swashcap
swashcap / angular-resources.md
Last active August 29, 2015 14:01
Angular Resources
@swashcap
swashcap / gulp-vs-grunt.md
Last active August 29, 2015 14:02
A little comparison of GulpJS and GruntJS

Gulp vs. Grunt

Grunt is “the JavaScript task runner” built on NodeJS. It does what it claims to do: run tasks. Gulp is a build tool that runs on NodeJS. In their words:

Gulp's use of streams and code-over-configuration makes for a simpler and more intuitive build.

Code Example

Compiling Sass to CSS gives an excellent measure of the differences between Gulp and Grunt. These are taken straight from each project’s Readme.

@swashcap
swashcap / format-onboard.js
Last active August 29, 2015 14:03
Example of responsive formatting an "Onboard" section.
/* global Modernizr */
jQuery(function ($) {
'use strict';
var SCREEN_SMALL = '(min-width: 768px)';
/**
* "Welcome" onboarding message.
*/
var $onboard = $('.onboard');
@swashcap
swashcap / angular-model.js
Created October 29, 2014 00:26
Models in Angular
// Define the model
(function (angular) {
'use strict';
var Model = function (data) {
this.id = data.ID;
this.name = this._getName(data);
};
Model.prototype._getTitle = function (data) {
return data.firstName + ' ' + data.lastName;
@swashcap
swashcap / shipstation-schema.md
Last active August 29, 2015 14:10
ShipStation’s XML Schema

ShipStation has an XML API (PDF). Unfornately, because of poor PDF formatting, its impossible to properly copy-paste the XML validation schema. The following is the properly formated schema (as far as I can tell). Save it as a .xsd file and use it to validate your app’s output.

The email regular expression may change due to your language of choice. Originally, the PDF used:

([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+```

However, PHP didn’t like the \@ so I changed it to @. Your mileage may vary.

@swashcap
swashcap / query-builder.js
Created July 1, 2015 23:04
Query Builder test
/**
* Test Query builder.
*/
'use strict';
var _ = require('lodash');
var config = require('config');
var client = require('./lib/client').client;
var nav = require('./lib/nav/navigation')(client, config);
var micis = require('./lib/auth/micis')(client);
@swashcap
swashcap / css-background-images.js
Last active August 29, 2015 14:26
CSS Background Images
var pattern = /url\(([^)]+)/g;
var cssBackgrounds = [];
var results = [];
var matches;
// Loop over every stylesheet and get the background image references in every
// `background: url(...)`
for (var i = 0, il = document.styleSheets.length; i < il; i++) {
for (var j = 0, jl = document.styleSheets[i].rules.length; j < jl; j++) {
if (document.styleSheets[i].rules[j].cssText.indexOf('url(') !== -1) {
@swashcap
swashcap / parse-postgres-standard-timestamp.js
Last active September 22, 2015 22:20
Postgres Standard Timestamp Parser
/**
* Parse Postgres's standard timestamps.
*
* Example: `Tue Jan 01 2019 00:00:00 GMT+0000 (UTC)`
*
* @todo Write tests!
*/
var MONTHS = ['january', 'february', 'march', 'april', 'may', 'june', 'july',
'august', 'september', 'october', 'november', 'december'];
@swashcap
swashcap / stylesheets.js
Created October 31, 2015 21:40
Get info about stylesheets
'use strict';
var fs = require('fs');
var parse = require('css').parse;
var path = require('path');
var files = []; // Add your files here
var filePaths = files.map(function(file) {
return path.join(__dirname, file);
@swashcap
swashcap / get-deep-objects.js
Created November 10, 2015 22:41
Get arbitrarily deeply nested objects with a comparator.
/**
* Get deeply nested objects using a 'compare' function.
*
* @param {(object|array)} target Data tree in which to find objects.
* @param {function} compare Passed items in the `target` data tree. It
* should return a boolean value based on the
* item.
* @return {array}
*/
function getDeepObjects(target, compare) {