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 / wp-remove-submenu.md
Created May 6, 2014 04:51
Easily remove the “Themes” and “Editor” submenus from the WordPress admin area.

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 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 / gulpfile.js
Last active November 23, 2016 03:02
Gulpifying Jekyll
/* 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')
@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'];