Skip to content

Instantly share code, notes, and snippets.

@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>
@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 / 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 / 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 / Gemfile
Created May 13, 2012 16:28
silly rack app
source 'http://rubygems.org'
gem 'grape'
rake/rdoctask is deprecated. Use rdoc/task instead (in RDoc 2.4.2+)
DEPRECATION WARNING: Rake tasks in vendor/plugins/action_mailer_cache_delivery/tasks, vendor/plugins/broccoli/tasks, vendor/plugins/browser_utils/tasks, vendor/plugins/engines/tasks, vendor/plugins/friendly_identifier/tasks, vendor/plugins/hoptoad_notifier/tasks, vendor/plugins/nature_support/tasks, vendor/plugins/restful_authentication/tasks, vendor/plugins/textile_editor_helper/tasks, and vendor/plugins/yaml_db/tasks are deprecated. Use lib/tasks instead. (called from /home/andrea/.rvm/gems/ree-1.8.7-2012.02@events/gems/rails-2.3.11/lib/tasks/rails.rb:10)
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
rake aborted!
private method `gsub' called for nil:NilClass
/home/andrea/.rvm/gems/ree-1.8.7-2012.02@events/gems/activesupport-2.3.11/lib/active_support/whiny_nil.rb:52:in `method_missing'
/home/andrea/.rvm/gems/ree-1.8.7-2012.02@global/gems/bundler-1.1.4/lib/bundler/runtime.rb:77:in `require'
/hom
@afiore
afiore / aggregate_sparql_query.rb
Last active December 13, 2015 20:39
SPARQL aggregate query example using Ruby SPARQL::Client gem
require 'rubygems'
require 'sparql/client'
ENDPOINT_URL = "http://localhost:3030/data/query"
query =
SPARQL::Client.new(ENDPOINT_URL, :method => 'post')
.select(:person, :count => {:other_person => :count} )
.where([:person, RDF::FOAF.knows, :other_person])
.group(:person)
@afiore
afiore / Rakefile
Last active December 14, 2015 10:59
Some overlooked features of Rake, Ruby's build tool
require 'yaml'
require 'json'
require 'logger'
# Some useful, and often overlooked features of Rake, Ruby's build tool.
directory "logs"
desc "Log tasks execution to a file"
task "log" => ['logs'] do
MyLogger.instance
@afiore
afiore / shooping_cart.hs
Last active December 9, 2022 15:00
Minimalist Shopping cart implementation in Haskell
import qualified Data.Map as DM
data Product = Product String Float deriving (Show)
type ProductMap = DM.Map String [Product]
type DiscountTimes = (ProductMap -> Int)
data Discount = Discount Float DiscountTimes
products :: [Product]
products = milk ++ marsBars
where milk = replicate 7 $ Product "milk" 1.30
(ns cascalog-tutorial.core
(:use cascalog.api
cascalog.playground
[clojure.string :only [split]]
[cheshire.core :only [parse-string generate-string]]))
(def input-tap
(hfs-tap (cascading.scheme.hadoop.TextLine.)
(str (System/getProperty "user.dir")
"/all.json")))