Skip to content

Instantly share code, notes, and snippets.

@justin-endler
justin-endler / endler-migrate-field-data.php
Created December 17, 2012 19:03
Simple Drush script skeleton to find string values in a node field and migrate them to other fields.
<?php
/**
* @file endler-migrate-field-data.php
*
* Drush script to migrate some string from one set of node fields to another.
*
* @author Justin Endler
*/
function update_node_fields($entity_id, $value) {
@justin-endler
justin-endler / storeUtil.js
Last active December 19, 2015 02:39
JavaScript utilities for use in a Drupal Commerce project.
(function($) {
Drupal.behaviors.storeUtil = {
/**
* @param Number negative places to move the decimal left, positive to move it right
* @param String float
* @return String
*/
moveDecimal: function(places, f) {
// Move zero places.
if (!places) {
@justin-endler
justin-endler / console_info.sublime-snippet
Last active December 28, 2015 00:48
Sublime snippet for quick insertion of a labeled console.info()
<snippet>
<content><![CDATA[
console.info('${1:thing}:', ${1}); // @test
]]></content>
<tabTrigger>info</tabTrigger>
<description>console.info()</description>
<scope>source.js</scope>
</snippet>
@justin-endler
justin-endler / heroku-deploy.sh
Last active December 29, 2015 03:09
General node.js Express app deployment script for Heroku.
#!/bin/bash
# requires that node app.js be contained in a Procfile
# ./heroku-deploy.sh <NODE_ENV> <local_branch_to_push> <app_to_destroy_if_redeploy>
# validate minimal input
if [ -z "$1" ] || [ -z "$2" ]; then
echo "Run with at least NODE_ENV and local_branch_to_push as arguments $1 and $2"
exit 1
fi
@justin-endler
justin-endler / todo.sublime-snippet
Created November 23, 2013 19:54
// @todo Sublime snippet.
<snippet>
<content><![CDATA[
// @todo
]]></content>
<tabTrigger>todo</tabTrigger>
<description>@todo</description>
</snippet>
@justin-endler
justin-endler / test.sublime-snippet
Created November 23, 2013 19:53
// @test Sublime snippet.
<snippet>
<content><![CDATA[
// @test
]]></content>
<tabTrigger>test</tabTrigger>
<description>@test</description>
</snippet>
@justin-endler
justin-endler / cp_branch.sh
Created April 20, 2016 13:30
copy current git branch to clipboard
echo -n "$(git rev-parse --abbrev-ref HEAD)" | pbcopy
@justin-endler
justin-endler / indefinite_mutation_observer.js
Last active October 4, 2016 13:43
MutationObserver: Listen Indefinitely On Changing Element
// support multiple browsers
// http://stackoverflow.com/questions/2844565/is-there-a-jquery-dom-change-listener/11546242#11546242
MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
var elementId = 'some-id';
// instantiate initial observer
var observer = new MutationObserver(observeIndefinitely(elementId));
observer.observe(document.getElementById(elementId), {
// expensive, only use what's needed of these
attributes: true,
childList: true,
@justin-endler
justin-endler / mobile-width-helpers.js
Last active October 14, 2016 15:10
Mobile Width Problem Helpers
// not for production use
function MobileWidthHelpers () {
this.stringName = stringName;
var ignoreElements = [
'SCRIPT',
'LINK',
'META'
];
function stringName ($el) {
@justin-endler
justin-endler / findSelectors.js
Last active March 13, 2017 21:26
Find css selectors in js file
'use strict';
const file = 'some_file.js';
const ignore = [
'a',
'input',
'span',
'td',
'title',