Skip to content

Instantly share code, notes, and snippets.

Avatar
Writing code

Cory Reed swashcap

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

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 Aug 29, 2015
Example of responsive formatting an "Onboard" section.
View format-onboard.js
/* global Modernizr */
jQuery(function ($) {
'use strict';
var SCREEN_SMALL = '(min-width: 768px)';
/**
* "Welcome" onboarding message.
*/
var $onboard = $('.onboard');
View angular-model.js
// 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 Aug 29, 2015
ShipStation’s XML Schema
View shipstation-schema.md

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.

View query-builder.js
/**
* 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 Aug 29, 2015
CSS Background Images
View css-background-images.js
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 Sep 22, 2015
Postgres Standard Timestamp Parser
View parse-postgres-standard-timestamp.js
/**
* 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 Oct 31, 2015
Get info about stylesheets
View stylesheets.js
'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 Nov 10, 2015
Get arbitrarily deeply nested objects with a comparator.
View get-deep-objects.js
/**
* 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) {
You can’t perform that action at this time.