Skip to content

Instantly share code, notes, and snippets.

View isaacrankin's full-sized avatar

Isaac Rankin isaacrankin

View GitHub Profile
@isaacrankin
isaacrankin / steps.md
Last active April 14, 2016 23:56
Vagrant MySQL server and database import
  1. shell into vagrant box - vagrant ssh
  2. install MySQL server - sudo apt-get install mysql-server mysql-client
  3. open mysql - sudo mysql -u root -p
  4. create project database - CREATE DATABASE sublime;
  5. import sql - mysql -u root -p sublime < sublime.sql
@isaacrankin
isaacrankin / resize-image.php
Created February 17, 2016 03:15
WordPress Image resize on the fly
/**
* Resize image on the fly
*
* @param int $attachment_id Attachment ID
* @param int $width Width
* @param int $height Height
* @param boolean $crop Crop or not
*
* @return string|bool URL of resized image, original file if error
*/
@isaacrankin
isaacrankin / flatten-by-prop.js
Created October 23, 2015 23:38
Flatten a nested array and combine/crawl by a specified property
/**
* Flatten a nested array and combine/crawl by specified property
*/
flattenByProp (arr, prop) {
var flatten = function (arr) {
return arr.reduce(function (flat, toFlatten) {
// combine items on this level
var combo = flat.concat(toFlatten);
#!/usr/bin/env node
require('shelljs/global');
// Prevent committing of debug configurations
console.log('Performing pre-commit tests...');
if (!which('git')) {
echo('Sorry, this script requires git');
process.exit(1);
@isaacrankin
isaacrankin / remember-how-mocha.md
Last active August 29, 2015 14:18
Remember How Mocha Tests

Command Line

Install Mocha JS globally npm install -g mocha

Then run mocha init test in the root of your project.

"test" is the directory where the testing files will be created, and it's where mocha will look to run tests from.

Then run tests with mocha.

@isaacrankin
isaacrankin / .htaccess
Last active August 29, 2015 14:16
Disable robots for staging site
# Use PHP to output robots.txt to avoid accidentally indexing staging sites
RewriteRule ^robots\.txt$ robots.php [NC,L]
@isaacrankin
isaacrankin / detect-css-background-blend-modes.js
Created February 12, 2015 02:39
Check support for CSS background-blend-modes
// This could be used for detecting other things theoretically
if(!('backgroundBlendMode' in document.body.style)) {
// No support for background-blend-mode
var html = document.getElementsByTagName('html')[0];
html.className = html.className + ' no-background-blend-mode';
}
@isaacrankin
isaacrankin / router.js
Created February 11, 2015 23:25
The simplest JS router
var base = '/';
switch (location.pathname){
case base + 'contact':
console.log('you are viewing the contact page');
break;
}
@isaacrankin
isaacrankin / bb-touch-events.js
Last active August 29, 2015 14:06
Bind touch or mouse events in a Backbone view.
var ExampleView = Backbone.View.extend({
el: '.example',
events: function(){
var action = (Modernizr.touch) ? 'touchend' : 'click',
events = {};
events[ action + ' .btn'] = 'doSomething';
@isaacrankin
isaacrankin / Read-More-Pattern.markdown
Created July 31, 2014 23:21
A tricky way to have a responsive "read more/accordion" content.