Skip to content

Instantly share code, notes, and snippets.

@wxactly
wxactly / getQueryParameters.js
Last active August 31, 2018 21:14
Get query parameters as an object
function getQueryParameters(queryString) {
queryString = (queryString || document.location.search).replace(/(^\?)/, '');
var queryParams = {};
if (queryString) {
var keyVals = queryString.split('&');
for (var i = 0; i < keyVals.length; i++) {
var keyVal = keyVals[i].split('=');
queryParams[keyVal[0]] = decodeURIComponent(keyVal[1].replace(/\+/g, '%20'));
@wxactly
wxactly / RoboFile.php
Last active July 14, 2017 21:05
Robo task for updating Drupal 8 module config
<?php
class RoboFile extends \Robo\Tasks
{
/**
* Update site config by importing from a module's config directory.
*
* @param string $module Module name
* @param array $opts
@wxactly
wxactly / git-p4merge.sh
Created April 14, 2016 05:40
Install/configure p4merge as your git mergetool and difftool
brew cask install p4merge --force
git config --global merge.tool p4mergetool
git config --global mergetool.p4mergetool.cmd "$HOME/Applications/p4merge.app/Contents/Resources/launchp4merge \$PWD/\$BASE \$PWD/\$LOCAL \$PWD/\$REMOTE \$PWD/\$MERGED"
git config --global mergetool.keepBackup false
git config --global diff.tool p4mergetool
git config --global difftool.p4mergetool.cmd "$HOME/Applications/p4merge.app/Contents/Resources/launchp4merge \$LOCAL \$REMOTE"
@wxactly
wxactly / search-api-redhen-contact-autocomplete.php
Last active June 21, 2016 15:40
Drupal Search API - Simple RedHen contact autocomplete
<?php
/**
* Implements hook_menu().
*/
function MY_MODULE_menu() {
$items['MY_MODULE/redhen/contact/autocomplete'] = array(
'title' => 'Autocomplete for RedHen Contacts',
'page callback' => 'MY_MODULE_contact_autocomplete',
'access callback' => 'redhen_contact_access',
@wxactly
wxactly / notify.sh
Last active March 16, 2016 18:50
Trigger OSX notifications from iTerm2
# Paste into .zshrc, with or without the alias:
function notify() {
printf "\x1b]9;%s\x7" "$*"
}
alias n="notify"
# Usage:
# notify Testing 1 2 3
#
@wxactly
wxactly / RoboFile.php
Last active January 29, 2016 18:19
ThinkShout/Cascade RoboFile
<?php
/**
* This is project's console commands configuration for Robo task runner.
*
* @see http://robo.li/
*/
class RoboFile extends \Robo\Tasks
{
use \Robo\Common\Timer;
@wxactly
wxactly / prototype.js
Created January 5, 2015 22:07
"Objects-only" prototypal inheritance user-land lib. (Inspired by http://davidwalsh.name/javascript-objects-deconstruction)
Prototype = {
create: function() {
var proto = Object.prototype;
var protoProperties = arguments[0] || {};
if(arguments.length > 1) {
proto = arguments[0];
protoProperties = arguments[1] || {};
}
var prototypeObject = Object.create(proto);
for(var protoProperty in protoProperties) {
@wxactly
wxactly / stubQueryMethod.js
Last active August 29, 2015 14:06
Sails.js: Stub Waterline query method with Sinon.js
var util = require('util');
var _ = require('lodash');
var sinon = require('sinon');
/**
* Replaces a query method on the given model object with a stub. The query
* will still operate on a callback, and allow full access to waterline's
* deferred object. However, the query will not cause any I/O and instead
* will immediately resolve to the given result.
*