Skip to content

Instantly share code, notes, and snippets.

View doublejosh's full-sized avatar
🎰
front-ending

Josh Lind doublejosh

🎰
front-ending
View GitHub Profile
@doublejosh
doublejosh / gist:f1a0b5302b9a141af75b
Created November 7, 2014 02:15
Cross origin colorTheif
// Get image colors (cross origin fun).
$(window).load(function() {
var canvas = document.createElement('canvas'),
ctx = canvas.getContext("2d");
bgColor,
$image;
canvas.width = 50;
canvas.height= 50;
$('#card-deck .card img').each(function() {
@doublejosh
doublejosh / gist:471b1d374d69f84a83d1
Created January 12, 2015 22:41
Request function example
/**
* Send the request to retrigger a build.
*
* @param int $build_id
* Travis build id to act upon, for URL construction.
* @param string $token
* Travis user authorization token.
* @return array
* Response items the calling function(s) might care about.
*/
@doublejosh
doublejosh / gist:092bfb1b71df44e78214
Created January 17, 2015 01:43
temporary_css_from_staging.html
<style>
.page { display:none; }
</style>
<script>
function addEvent(elem, event, fn) {
if (elem.addEventListener) {
elem.addEventListener(event, fn, false);
} else {
elem.attachEvent('on' + event, function() {
// set the this pointer same as addEventListener when fn is called
/**
* Data transforms due to version updates.
*/
function schema() {
// Update keys.
var keys = {
'MY-NEW-KEY': {'oldKey': 'MY-OLD-KEY', 'version': '0.2.0'}
};
for (var newKey in keys) {
@doublejosh
doublejosh / new-feature-testable.js
Last active August 29, 2015 14:17
AB test a new JS feature
var should_show = $.cookie('testNameSpace');
// Allow A/B test override.
if ($('body.override').length > 0) should_show = 1;
// User is a yes OR no choice yet.
if (should_show == 1 || (should_show == null && Math.random() < 0.2)) {
//Set cookie to yes.
$.cookie('testNameSpace', 1, { path : '/' });
@doublejosh
doublejosh / PageCachable.php
Last active August 29, 2015 14:17
Page with memcache
<?php
class PageCachable {
private $memcache,
$memcacheOptions = [
'enabled' => FALSE,
'host' => 'localhost',
'port' => '11211',
'lifetime' => 10800,
<?php
function my_module_special_form($form, &$form_state, $node = FALSE) {
$node_id = (is_object($node) && is_numeric($node->nid)) ? $node->nid : '';
// Ajaxify.
if (module_exists('context') && _tableau_is_active_context(array('ajaxify_premium')) {)
$form['#prefix'] = '<div id="formwrapper">';
$form['#suffix'] = '</div>';
// Submit button.
@doublejosh
doublejosh / watchLog.js
Last active August 29, 2015 14:18
Log front-end events to New Relic and the browser as desired by environment.
// Logging "constants"
nameSpace.watchLogDEBUG = 7;
nameSpace.watchLogNOTICE = 5;
nameSpace.watchLogWARNING = 4;
nameSpace.watchLogERROR = 3;
/**
* Log events.
*
* EXAMPLES:
@doublejosh
doublejosh / example-profile1.yml
Last active August 29, 2015 14:18
Peeps Picker example #1
---
name: Ms. Awesome
email: awesome@example.com
favSkills:
- api
- js
- php
intSkills:
- performance
- ci
@doublejosh
doublejosh / example-profile2.yml
Last active August 29, 2015 14:18
Peeps Picker example #2
---
name: Mr. Smarty
email: smarty@example.com
favSkills:
- crm
- drupal
- ux
intSkills:
- modules
- css