Skip to content

Instantly share code, notes, and snippets.

@afiore
afiore / Gemfile
Created May 13, 2012 16:28
silly rack app
source 'http://rubygems.org'
gem 'grape'
@afiore
afiore / gist:1341530
Created November 5, 2011 13:59
Load annotator comments in a weblog sidebar
<!-- make sure to include this after jquery -->
<script type="text/javascript">
jQuery(function ($) {
/**
* Populates a DOM element with Annotator data
*
* Params:
*
* annotations - The data fetched from the Annotator api endpoint.
@afiore
afiore / unique-id.php
Created May 29, 2011 13:39
Caching a local variable in php
<?php
function uniqueId(){
static $id;
if (!isset($id)) {
$id=0;
} else {
$id++;
}
echo 'id_' . $id . "\n";
@afiore
afiore / nanoc_blog_excerpt.rb
Created May 17, 2011 16:58
A nanoc helper for extracting blog post summaries through a <!--READMORE--> marker
require 'rubygems'
require 'nokogiri'
module Helpers
def blog_excerpt(item, read_more='<!--READMORE-->')
post_dom = Nokogiri::HTML::DocumentFragment.parse(item.compiled_content)
more_tag_found = false
post_dom.css('*').each do |p, index|
if p.inner_html.match(read_more)
p.inner_html = p.inner_html.gsub(Regexp.new("#{read_more}.*"), "&nbsp; <a href=\"#{item.identifier}\" title=\"#{item[:title]}\" class=\"read-more\">Read more...</a>")
@afiore
afiore / gist:946525
Created April 28, 2011 15:07
Sinon.js spies fail with objects using light-traits.js and cortex.js
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Spying on objects created through Cortex and light-traits.js </title>
<!-- light-traits.js and cortex.js, twaked so that I don't need to use requireJS or similar libraries -->
<script type="text/javascript" src="https://gist.github.com/raw/946407/4bc11f02474bd466d768589fd0ffaf92195f19ff/light-traits.js"></script>
<script type="text/javascript" src="https://gist.github.com/raw/946411/a106ac47587356f6e235136f80692958b324bf8a/cortex.js"></script>
<script type="text/javascript" src="http://sinonjs.org/releases/sinon-1.0.0.js"></script>
/* vim:set ts=2 sw=2 sts=2
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
/* vim:ts=2:sts=2:sw=2:
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
@afiore
afiore / index.html
Created January 4, 2011 22:02 — forked from mbostock/.block
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://github.com/simplegeo/polymaps/raw/v2.2.0/polymaps.min.js"></script>
<script type="text/javascript" src="http://github.com/mbostock/polymaps/raw/586fbb0346548a5559b6edea8aab76ac51334da5/lib/crimespotting/crimespotting.js"></script>
<style type="text/css">
@import url("http://github.com/simplegeo/polymaps/raw/v2.2.0/examples/example.css");
html, body {
We couldn’t find that file to show.
@afiore
afiore / pagesnap
Created June 21, 2010 02:06
Save a webpage (and its linked assets) into a single HTML file.
#! /usr/bin/env php
<?php
/***
* PageSnap
*
* Script for archiving a HTML page (and associated media assets) into a single file.
*
* Requires:
*