Skip to content

Instantly share code, notes, and snippets.

@rmosolgo
rmosolgo / index.html
Last active December 11, 2015 17:49
AidData Purpose Codes
<html>
<head>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js'></script>
</head>
<body>
<div id='chart'></div>
<script src='https://data.itpir.wm.edu//codes/pcwheel.js'></script>
</body>
@rmosolgo
rmosolgo / code_tree.json
Created February 5, 2013 22:15
Code explorer 1.2
{"all_activity_children":544,"all_children":788,"children":[{"all_activity_children":216,"all_children":296,"children":[{"all_activity_children":53,"all_children":71,"children":[{"all_activity_children":0,"all_children":0,"children":[],"code":"11000","name":"Education, combinations of purposes","parent":"110","type":"purpose","updated_at":"2013-02-04T19:56:57Z"},{"all_activity_children":19,"all_children":25,"children":[{"all_activity_children":0,"all_children":0,"children":[],"code":"11100","name":"Education, level unspecified, combinations of purposes","parent":"111","type":"purpose","updated_at":"2013-02-04T19:56:57Z"},{"all_activity_children":1,"all_children":1,"children":[{"all_activity_children":0,"all_children":0,"children":[],"code":"11105.01","name":"Education, level unspecified, activity unspecified or does not fit under any other applicable codes","parent":"11105","type":"activity","updated_at":"2013-02-04T19:56:55Z"}],"code":"11105","name":"Education, level unspecified, purpose unspecified or does
@rmosolgo
rmosolgo / README.md
Last active December 14, 2015 22:48 — forked from chrismytton/README.md
Run ruby from inside Markdown. Denote code by leading TAB. (four spaces won't work)

Literate Ruby

Inspired by Literate CoffeeScript.

$ cat hello.litrb
Here's a simple program

    puts "Hello, world"
$ ruby litrb.rb < hello.litrb

Hello, world

@rmosolgo
rmosolgo / data_uri.json
Last active December 15, 2015 18:09
JSON for data URIs of file type icons, based on Gmail's icons (is this illegal?) and http://dopiaza.org/tools/datauri/index.php
{
"doc" : "data:image/gif;base64,R0lGODlhEAAQANUgANvh8gZCm0RrvGCAylhwppOr5rnI7XmT1oCe5jJVmT1otmeK1TVesgg4ia672IOc2ipit4uk3Vd90E52y3eKnGd+syg+bfDy+oml6U1qpwlLsgU2goSEhMbGxgAAAP///////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAACAALAAAAAAQABAAAAaIQJCQQywahUgQ58NsMjkeYaGAQRwWkokA8oSCCk6nhukpexCGxwCwJkQ0nfincwaoAQJAhjKezz0HHwcCDgkRCQYBHX50Cx8VAgQbDBYfioweEh8EiBsbDh8NcYt0Ex+TFxsKTBtOdKthrKN/EBq2AbgNnq5RQ2GjpL1KsbxIHMDIccJQZs3NQQA7",
"xls" : "data:image/gif;base64,R0lGODlhEAAQAMQfADRMGDhsIDRiFGuuZVWWRUiLOJXDkEaELDt3HI+8ij19I2SnXTNZFV6OVs3bzP79+trl2nOkb6CynpuvmoaohG+abOTr5FygVTJsDQoKCoSEhP7+/sbGxgAAAP///////yH5BAEAAB8ALAAAAAAQABAAAAWL4CdqZGmK6Kd57MOyWicOw3IRRHEoCPzIg41wKMSwMh3kwLAgbByNywTDqXo4mYXFMDhELgWI8XrtXJ6GiyLA2QiqnGvGmbikAxWIgBXndAoJCAECCQUBEgxwcgdEFIMNAC9lCkREkWR+CBibAgwMAKB9cigrcH1WfqSSq2Wkpq9VMiMdSbS0GUhIIQA7",
"ppt" : "data:image/gif;base64,R0lGODlhEAAQANUgAO+TaZQ4LY8zJpE6M/CXXdd/XsdzV8VoTYcsJ9uDYvCkb//8+X0iGv
@rmosolgo
rmosolgo / bootstrap-teaser.js
Last active December 16, 2015 14:08
example of bootstrap-teaser.js, paragraph preview plugin for jquery / bootstrap
$(function() {
$('.teaser').each(function() {
var el = $(this);
var long_text = el.html()
var n_sentences = el.attr("data-teaser-length") || 1;
var short_text = el.html().split(/([\.\?\!])\s/, (n_sentences * 2) ).map(function(d, i) {return i % 2 == 0 ? d : d + " " }).join("")
if (long_text != short_text) {
el.html('')
el.append(
nice_money = (amount, options={}) ->
# Props to akmiller for original code -- I'm using it all the time though so hosting it here.
full_label = options.full_label || false
if d3?
if 1000 >= amount
label = ""
money = "#{d3.format("0,r")(d3.round(amount,0))}"
else if 1000000 > amount >= 1000
label = (if full_label then "Thousand" else "K" )
money = "#{d3.round((amount/1000),0)}"
@rmosolgo
rmosolgo / split_to_fit.coffee
Created May 6, 2013 14:40
JavaScript to split a string into an array of strings close to the specified length.
split_to_fit = (string, allowable_width) ->
# console.log("splitting '#{string}' to fit #{allowable_width}")
splitters = [' ', ',', '-', '.'] # allowable splitters
new_strings = []
for w in [allowable_width..0]
# console.log("trying width=#{w}, which returns '#{string[w]}'")
if string[w] in splitters
# console.log("found a splitter at #{w} in #{string}")
if string[w] is ' '
end_of_word = w-1
@rmosolgo
rmosolgo / batman.jquery.js
Created November 22, 2013 19:36
The Batman.js version 0.15.0 jquery adapter in plain JS
(function() {
Batman.extend(Batman.DOM, {
querySelectorAll: function(node, selector) {
return jQuery(selector, node);
},
querySelector: function(node, selector) {
return jQuery(selector, node)[0];
},
setInnerHTML: function(node, html) {
return jQuery(node).html(html);
@rmosolgo
rmosolgo / private.coffee
Last active January 3, 2016 07:19
Private variables and methods in JavaScript and CoffeeScript
Submarine = ->
# "private", within function scope but not attached to the new instance
secretWeapon = "missiles"
fireSecretWeapon = -> console.log "fire ze " + secretWeapon
# "public", attached to the new instance
@reveal = -> secretWeapon
@setWeapon = (weapon) ->
secretWeapon = weapon
@fire = -> fireSecretWeapon()
@
@rmosolgo
rmosolgo / properties of prototypes in JS.coffee
Created January 17, 2014 00:52
Be careful with prototype properties in JS when you change them
class Tophat
dimensions: {height: 50, circumference: 20}
color: "black"
tpains_hat = new Tophat
tpains_hat.dimensions.height = 120
tpains_hat.color = "#f59145"
lincolns_hat = new Tophat
console.log lincolns_hat.color # => "black"