Skip to content

Instantly share code, notes, and snippets.

@mozz100
mozz100 / marketo_interesting_moment.js
Created January 30, 2012 12:03
Marketo Sales Insight - notify sales team which file was downloaded
/* Use the Munchkin API to record a 'visitWebPage' event (see http://community.marketo.com/MarketoArticle?id=kA050000000Kyr7). Set the url of the visitWebPage event to the url of the download. I found that I had to make the link open in a new window, otherwise the Munchkin never manages to 'call home'...
I did it with jQuery. Replace $jq with a reference to a valid jQuery object in the code below.
We use a separate subdomain for Marketo-hosted landing pages and resources (in common with most users, I suspect). Since we wanted to track downloads for any PDF or PPT file within that domain, the jQuery selector pretty much wrote itself. It's case sensitive, but could easily be extended or modified to work around that - wasn't necessary for me.
Opening the links in a new window seems to help with the tracking. If the new page loads too quickly, then it seemed as if the event handler code didn't get called. Leaving the original window open avoids this (I set target="_blank").
*/
@mozz100
mozz100 / querystring.js
Created February 1, 2012 15:19
Read the querystring from javascript
// Adapted from http://stackoverflow.com/questions/901115/get-query-string-values-in-javascript
// Give a querystring like this: yourpage.html?cheese=wensleydale&biscuits=nice
var qs = (function(a) {
if (a == "") return {};
var b = {};
for (var i = 0; i < a.length; ++i)
{
var p=a[i].split('=');
if (p.length != 2) continue;
@mozz100
mozz100 / clickClear.js
Created March 21, 2012 10:17
Simulate 'placeholder' with Javascript
// clear the email address field when the user clicks into it
function clickClear(e) {
if (e.value == 'Your email address') { // text must match the default value attribute on the <input> tag
e.value = '';
}
}
@mozz100
mozz100 / create_database.sql
Created April 23, 2012 20:21
Shakespeare data manipulation
# -----------------------------------------------------------------------------------
# Create the database
CREATE DATABASE `shkspr` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
# -----------------------------------------------------------------------------------
# Create table structures
CREATE TABLE `shkspr`.`Chapters` (
`WorkID` VARCHAR( 32 ) NOT NULL ,
@mozz100
mozz100 / droners.sql
Created April 25, 2012 21:37
Shakespeare PGSQL queries
-- of all the characters, whose paragraphs/speeches are the longest, on average?
SELECT
"characters"."name" AS "character_name",
SUM(length("paragraphs"."plain_text")) as "letter_count",
COUNT(*) as "paragraph_count",
SUM(length("paragraphs"."plain_text"))/COUNT(*) as "drone_factor"
FROM "paragraphs"
INNER JOIN "characters" ON "paragraphs"."character_id" = "characters"."id"
@mozz100
mozz100 / drupal_search.sql
Last active October 11, 2015 12:17
Search Drupal node content for a string
SELECT * FROM node_revisions
INNER JOIN node ON node.nid = node_revisions.nid
WHERE body LIKE '%search term%'
AND node.status = 1
AND node_revisions.vid IN (SELECT vid FROM node WHERE status = 1)
@mozz100
mozz100 / collapse_categories.js
Last active December 15, 2015 04:49 — forked from Mikhail-Zakharov/Collapse categories_Ver2.js
Add this as a global javascript widget in Zendesk to achieve collapsible category headers.
var collapsed_by_default = false; // set this to true if you prefer collapsed by default
function HideCategory(id, IsAgent, animation) {
// Function hides category
$j("div#category_" + id).hide(animation);
SetDownArrow(id, IsAgent);
$j.cookie('hide_category_' + id, 'yes', { expires: 180 });
$j("div#category_header_" + id).attr("onclick", "ShowCategory(" + id + "," +IsAgent+ ",'blind')");
};
@mozz100
mozz100 / utc-timestamp.py
Created October 1, 2013 09:13
Get UTC timestamp in python. Is there a better way? This seems highly verbose.
from datetime import tzinfo, timedelta, datetime
import calendar
class UTC(tzinfo):
"""UTC"""
def utcoffset(self, dt):
return timedelta(0)
def tzname(self, dt):
return "UTC"
def dst(self, dt):
return timedelta(0)
@mozz100
mozz100 / gmail_snooze.js
Created October 22, 2013 14:48
GMail snooze, with some mozz modifications
// see http://googleappsdeveloper.blogspot.co.uk/2011/07/gmail-snooze-with-apps-script.html
// Should be set to run every day at midnight, and moves emails one label 'nearer' to the inbox
var MARK_UNREAD = false;
var ADD_UNSNOOZED_LABEL = true;
function getLabelName(i) {
return "Snooze/Snooze " + i + " days";
}
@mozz100
mozz100 / mozzicon.py
Last active December 26, 2015 10:09
Mozzicon: html/python implementation of https://github.com/cupcake/sigil
def mozzicon(md5):
# Inspired by (!) https://github.com/cupcake/sigil
# return a 5 by 5 grid of divs with horizontal plane of symmetry
# (css used to rotate by 90deg)
# md5 is a string like "9eadbe04ba0a832eecbd0a27f563e0a6"
# use first char of hash to pick a color from 7
colors = ('2d4fff', 'feb42c', 'e279ea', '1eb3fd', 'e84d41', '31cb73', '8d45aa', )