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
/**
* Turn decimals into fractions.
*/
function dec2frac($f) {
$base = floor($f);
if ($base) {
$out = $base . ' ';
$f = $f - $base;
}
if ($f != 0) {
@doublejosh
doublejosh / form_cache_size_breakdown
Last active August 29, 2015 13:57
Form Cache Table Size Breakdown
LOCAL...
mysql -uroot -proot tableau_pantheon_www -e "select cid, LENGTH(data) as length_data, serialized, expire, created INTO OUTFILE '/Users/***USER***/Documents/Tableau/form_cache_size-local.csv' FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' from cache_form"
LOCAL WITH OUT OUTFILE...
mysql -uroot -proot tableau_pantheon_www -e "select cid, LENGTH(data) as length_data, serialized, expire, created from cache_form" > /Users/jlind/Documents/Tableau/form_cache_size-local.txt
REMOTE...
mysql -upantheon -p***PASS*** -h dbserver.live.***HASH***.drush.in -P ***PORT*** pantheon -e "select cid, LENGTH(data) as length_data, serialized, expire, created from cache_form" > /Users/***USER***/Documents/Tableau/form_cache_size-live.txt
@doublejosh
doublejosh / gist:9898601
Last active August 29, 2015 13:57
HTML Emails Suck
Main things to keep in mind, since they're hard to believe...
1. Only use inline style.
2. Just give in and nest tables. It's terrible, but reliable everywhere.
3. Margin and padding is not completely supported (depending on DOM element).
Mostly just not Outlook > 2003, which is insane.
4. Apply style to divs and not many other tags.
@doublejosh
doublejosh / omghosts
Last active August 29, 2015 13:59 — forked from angrytoast/omghosts
Never accidentally leave your /etc/hosts file edited again!!! Let your computer remind you.
#! /usr/bin/env bash
GOLDEN_DOMAIN="example.com"
PROBLEM="$(cat /etc/hosts | grep $GOLDEN_DOMAIN | grep -v '^#' | wc -w)"
if [ "$PROBLEM" -gt 0 ]; then
say omg fix yer hosts
fi
@doublejosh
doublejosh / get_any_object.php
Last active August 29, 2015 14:01
Agnostic current entity loader function
<?php
/**
* Utility function to agnosticly get the current menu object.
* Structured like menu_get_object(), but the passed type will be set for you.
*
* @param string (reference) $return_type
*
* return object
* Entity object of current menu callback page.
*/
@doublejosh
doublejosh / CollectionClass.js
Last active August 29, 2015 14:02
Ultra-light-weight basic object convenience methods class.
Collection = function (obj) {
// Private vars.
var keyList = null,
length = null;
// Public functions.
return {
/**
@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) {