Skip to content

Instantly share code, notes, and snippets.

Avatar
Writing code

Cory Reed swashcap

Writing code
View GitHub Profile
@swashcap
swashcap / wp-remove-submenu.md
Created May 6, 2014
Easily remove the “Themes” and “Editor” submenus from the WordPress admin area.
View wp-remove-submenu.md

According to a WordPress.org support thread, it’s very easy to remove the Themes and Editor sub-pages entirely, making it (nearly) impossible to change themes. Drop this in your functions.php file:

/**
 * Remove the 'Themes' submenu page.
 *
 * @link http://codex.wordpress.org/Function_Reference/remove_submenu_page
 *
 * @return void
 */
@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.

@swashcap
swashcap / gulpfile.js
Last active Nov 23, 2016
Gulpifying Jekyll
View gulpfile.js
/* global -$ */
'use strict';
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var browserSync = require('browser-sync');
var reload = browserSync.reload;
gulp.task('styles', function () {
return gulp.src('app/css/main.scss')
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'];
You can’t perform that action at this time.