Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env ruby
ROMAN = {
1000 => 'M',
900 => 'CM',
800 => 'DCCC',
500 => 'D',
400 => 'CD',
100 => 'C',
90 => 'XC',
@queerviolet
queerviolet / change.rb
Last active August 29, 2015 14:11
change.rb
#!/usr/bin/env rspec
# Given an amount (a positive int) and a currency (a hash of {coin (a string)
# => value (an int)}), return how many of each coin is needed to make the
# amount as a hash {coin (a string) => count (an int)}. This method is useful
# for more than money, but money is a nicely concrete example of its utility.
#
# make_change assigns counts based on the iteration order of the currency you
# pass in. If you want optimal change, the currency you pass in must be sorted
# in descending order of value.
@queerviolet
queerviolet / sudoku.c
Last active August 29, 2015 14:13
sudoku.c
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#define SUDOKU_SZ 9
#define SUDOKU_BLK_SZ 3
typedef struct {
uint8_t cells[SUDOKU_SZ * SUDOKU_SZ];
@queerviolet
queerviolet / tsudoku.c
Last active August 29, 2015 14:13
grand central sudoku
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <dispatch/dispatch.h>
#include <sys/time.h>
#define SUDOKU_SZ 9
#define SUDOKU_BLK_SZ 3
@queerviolet
queerviolet / index.html
Last active August 29, 2015 14:13
ink pad widget
<!doctype html>
<html>
<head>
<script src="inkpad.js"></script>
<style>
body {
margin: 0; padding: 0;
}
ink-pad#ink {
@queerviolet
queerviolet / ashi_browser.rb
Created January 21, 2015 22:40
ashi_browser.rb
require 'open-uri'
require 'nokogiri'
url = ARGV[0]
while true
puts '******************************************'
puts "ashibrowse v.0.0000001 — Retrieving #{url}"
body = open(url).read
doc = Nokogiri::HTML(body)
@queerviolet
queerviolet / tree.rb
Last active August 29, 2015 14:16
tree utility in ruby
#!/usr/bin/env ruby
# tree.rb prints a directory tree.
# Prints a tree with all the descendants of path
# if path is a directory. If path is not a directory,
# does nothing.
def print_tree(path, prefix='')
return unless File.directory?(path)
Dir.entries(path).each_with_index do |entry, index|
@queerviolet
queerviolet / using-onload.html
Last active August 29, 2015 14:16
Javascript UI modules
<!doctype html>
<html>
<head>
<script src="using-onload.js"></script>
<script>
new Status.Error("Something went wrong");
new Status.Error("I feel confused");
new Status.Error("Rampancy emminent.");
</script>
<style>
@queerviolet
queerviolet / apply.js
Created April 8, 2015 13:46
JSLN specimen #003 livecode
function p() {
// call console.log with this=console and all our arguments
// as positional args.
console.log.apply(console, arguments);
}
p('hello');
p('hello', 'world');
function hello(x, y) {
@queerviolet
queerviolet / carousel.html
Created April 9, 2015 19:08
Image carousel widget