Skip to content

Instantly share code, notes, and snippets.

View ls-lukebowerman's full-sized avatar

Luke Bowerman ls-lukebowerman

View GitHub Profile
@ls-lukebowerman
ls-lukebowerman / gist:995922
Created May 27, 2011 19:03
Nice trick to get list of JS events currently attached (good for auditing keyup/down)
// Requires jQuery
// KeyUP
$($(document).data("events").keyup).each(function(e){ console.log(this.data); });
// KeyDOWN (MOS default)
$($(document).data("events").keydown).each(function(e){ console.log(this.data); });
@ls-lukebowerman
ls-lukebowerman / gist:2432283
Created April 20, 2012 22:13
Receipt template w/ small footer
{% extends parameters.print ? "printbase" : "base" %}
{% block extrastyles %}
@page { margin: 0px; }
body {
margin: 0;
padding: 1px; <!-- You need this to make the printer behave -->
}
.store { page-break-after: always; margin-bottom: 40px; }
.receipt {
font: normal 10pt 'Helvetica Neue',Helvetica,Arial,sans-serif;
@ls-lukebowerman
ls-lukebowerman / gist:2855110
Created June 1, 2012 20:59
OR search in the API
https://east3.merchantos.com/API/Account/36836/Item.json?or=systemSku~pearl|description~pearl
{"httpCode":"500","httpMessage":"Internal Server Error","message":"findAllByFieldMatch got search for \"systemSku~pearl\". Did you mean: systemSku?"}
@ls-lukebowerman
ls-lukebowerman / gist:3282059
Created August 7, 2012 05:45
Table of Contents generator
$(document).ready(function() {
// Only find headings within the article ID to save overhead
// (we don't care about headings outside of the article for the TOC
$('#article').each(function() {
var article = $(this);
var toc = $('<div class="toc"><h3>Table of Contents</h3><ul></ul></div>');
var toc_ul = toc.find('ul');
article.find('h2').each(function() {
// Add a ID (anchor) to each heading
@ls-lukebowerman
ls-lukebowerman / sitemap.xml.erb
Created August 7, 2012 17:59
Sitemap (sitemaps.org) generator for Middleman
<% pages = sitemap.resources.find_all{|p| p.source_file.match(/\.html/) } %>
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<% pages.each do |p| %>
<url>
<loc>http://youdomain.com/<%=p.destination_path.gsub('/index.html','')%></loc>
<priority>0.7</priority>
</url>
<% end %>
</urlset>
@ls-lukebowerman
ls-lukebowerman / gist:3677503
Created September 8, 2012 17:24
IndexTank/JSON Sitemap Generator for Middleman
<%
entries = []
pages = sitemap.resources
pages = pages.find_all{|p| p.source_file.match(/\.html/) && !p.directory_index? && p.data.hide_listing != true }
pages.each do |article|
file = File.open(article.source_file,'r')
file_contents = file.read.split('---').last.gsub(/\t|\n/,' ')
content = Nokogiri::HTML(file_contents).xpath("//text()").to_s
@ls-lukebowerman
ls-lukebowerman / gist:3677557
Created September 8, 2012 17:26
Middleman/IndexTank content loading script
require 'rubygems'
require 'indextank'
api_client = IndexTank::Client.new 'http://:[email protected]'
help_index = api_client.indexes 'help'
require 'json'
# Build fresh sitemap.json
# `middleman build -g help/sitemap.json`
@ls-lukebowerman
ls-lukebowerman / gist:4640391
Created January 26, 2013 05:33
Simple jQuery table of contents generator. Scans page for <h2> headings, adds IDs to those headings that don't have any and then prepends a Table of contents to the page.
// Assumes availability of jQuery...
function generate_toc() {
// Get the headings
var body = $('body');
var headings = body.find('h2');
// We don't need a table of contents if we don't have any headings
if (headings.length == 0) return false;