Skip to content

Instantly share code, notes, and snippets.

View anicholson's full-sized avatar

Andy Nicholson anicholson

View GitHub Profile
@JoshCheek
JoshCheek / rails_d3_routing_visualizer.rb
Created April 27, 2015 02:45
Rails D3 Routing Visualizer
require 'action_dispatch/routing'
require 'json'
routes = ::ActionDispatch::Routing::RouteSet.new
routes.draw do
namespace :admin do
resources :users
end
resources :ducks do
member do
@brianarn
brianarn / underscore_conditionals.js
Created May 4, 2010 22:37
Conditionals with underscore.js
// A means of using underscore.js to do templates with conditionals
// Inside of underscore's template, it returns a function that uses
// 'with' on a variable named obj, and you can touch into that using
// inline JS and <% %> wrappers
// A template with conditional display of last names:
var good = _.template("Hello: <%= name %> <% if (obj.lastname) { %> <%= lastname %> <% } %>");
// A template that tries to do that, but fails:
var bad = _.template("Hello: <%= name %> <% if (lastname) { %> <%= lastname %> <% } %>");
@kevinmehall
kevinmehall / device.js
Last active August 17, 2016 09:32
Using Tessel CLI as a Node library for USB message passing
// Any copyright is dedicated to the Public Domain.
// http://creativecommons.org/publicdomain/zero/1.0/
process.on('message', function(msg) {
console.log('reply');
process.send(msg);
});
process.ref();
@dnagir
dnagir / import.rb
Created February 8, 2012 04:41 — forked from baldowl/import.rb
Import a blogger archive to jekyll (octopress version, allows quotes in titles)
require 'rubygems'
require 'nokogiri'
require 'fileutils'
require 'date'
require 'uri'
# usage: ruby import.rb my-blog.xml
# my-blog.xml is a file from Settings -> Basic -> Export in blogger.
data = File.read ARGV[0]
@henrik-muehe
henrik-muehe / Dockerfile
Created August 5, 2013 11:47
Allows installing the ubuntu "fuse" package without creating any devices. Used to install packages on docker which require fuse but do not actively use it.
...
# Fake a fuse install
RUN apt-get install libfuse2
RUN cd /tmp ; apt-get download fuse
RUN cd /tmp ; dpkg-deb -x fuse_* .
RUN cd /tmp ; dpkg-deb -e fuse_*
RUN cd /tmp ; rm fuse_*.deb
RUN cd /tmp ; echo -en '#!/bin/bash\nexit 0\n' > DEBIAN/postinst
RUN cd /tmp ; dpkg-deb -b . /fuse.deb
@DrPaulBrewer
DrPaulBrewer / GINISS
Last active May 4, 2020 04:19
GINISS Gini Coefficient Function for Google Sheets. Open Tools->Script Editor in Sheets and Copy/Paste.
/*
* GINISS and THEILT Copyright 2018- Paul Brewer, Economic and Financial Technology Consulting LLC <drpaulbrewer@eaftc.com>
* This file may be used or copied under the terms of the MIT License as explained below or at https://opensource.org/licenses/MIT
* The MIT License
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
* Software.
# get some ideas from https://github.com/zkat/genfun, https://www.npmjs.com/package/protoduck, and https://www.npmjs.com/package/@zkat/protocols
module X
module Generic
Any = BasicObject
DefaultArgs = [Any]
def define_generic_method(name, *args, &blk)
if args.empty?
raise TypeError, "Useless use of a generic method, you should have some arguments, otherwise a normal method is preferrable"
end
@exic
exic / player-control
Created December 2, 2014 12:16
Control a player implementing MPRIS D-Bus Specification v2.2
#!/bin/sh
name="$1"
shift
PATHS="org.mpris.MediaPlayer2.$name /org/mpris/MediaPlayer2"
DBUS_SEND="dbus-send --type=method_call --dest=$PATHS"
RC="$DBUS_SEND org.mpris.MediaPlayer2.Player"
if [ "$@" = "prev" ]; then
$RC.Previous
elif [ "$@" = "stop" ]; then
$RC.Pause
@cgrand
cgrand / heredoc.clj
Last active March 6, 2021 17:16
An ugly hacky heredoc for Clojure
(defn heredoc []
(let [delim (.readLine *in*)]
(->> (repeatedly #(.readLine *in*))
(take-while #(not= delim %))
(interpose \newline)
(apply str))))
; The following lines are read (by the reader) as:
; "Look )(\"\\T\na here doc!\n"
#=(heredoc)"""
@jharjono
jharjono / sinatra_sass_coffee.rb
Created March 7, 2011 19:12
a setup of Sinatra using Slim for HTML, Sass for CSS, and CoffeeScript for JavaScript
#!/usr/bin/env ruby
# Libraries:::::::::::::::::::::::::::::::::::::::::::::::::::::::
require 'rubygems'
require 'sinatra/base'
require 'slim'
require 'sass'
require 'coffee-script'
# Application:::::::::::::::::::::::::::::::::::::::::::::::::::