Skip to content

Instantly share code, notes, and snippets.

View markandrus's full-sized avatar
🍊
orange

Mark Roberts markandrus

🍊
orange
View GitHub Profile
@markandrus
markandrus / pow.c
Created February 1, 2011 18:18
fast exponentiation
// main.c
// Mark Roberts
// Thanks:
// http://stackoverflow.com/questions/101439
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h> // uint64_t => [0, ULONG_LONG_MAX]
// Same algorithm referenced on StackOverflow:
@markandrus
markandrus / kaprekar.hs
Created June 8, 2011 23:00
Kaprekar Routine Visualization
{- Kaprekar Routine Visualization -}
-- Inspiration: http://mathworld.wolfram.com/KaprekarRoutine.html
import Data.Maybe
import Data.Word
import qualified List
import Data.Digits
import qualified Data.Vector.Storable as V
import Data.Array.Repa hiding ((++))
import Data.Array.Repa.IO.DevIL
import Data.Array.Repa.ByteString
@markandrus
markandrus / stylecheck.sh
Created June 11, 2011 00:29
List CSS class and id usage within a directory of files
#! /bin/sh
# stylecheck.sh:
#
# Find unused CSS class and id selectors, given a CSS file and a directory
# of HTML documents.
#
# $1 = CSS document, $2 = HTML directory
#
# Returns a report in YAML.
#
@markandrus
markandrus / stylecheck.rb
Created June 29, 2011 17:28
stylecheck.rb
#! /usr/local/bin/ruby
require 'rubygems'
require 'nokogiri'
require 'css_parser'
puts "Report of Unused CSS Rules\n---\nHTML Path:\t" + ARGV[0] + "\n"
htmls = (`ack '' #{ARGV[0]} -l --type html`).split("\n").map { |html| Nokogiri::HTML(File.read(html)) }
styles = (1..ARGV.length-1).inject(Array.new) { |a, i| a | (`ack '' #{ARGV[i]} -l --type css`).split("\n") }
puts "\t- Checking " + htmls.length.to_s + " HTML file(s) against " + styles.length.to_s + " stylesheet(s)\n\n"
styles.each do |style|
puts "Stylesheet:\t" + style
@markandrus
markandrus / gist:2924525
Created June 13, 2012 14:45
Fixing "TemplateSyntaxError at /admin/logout/"
# Because Jinja2 is the default template loader, add any non-Jinja templated
# apps here:
JINGO_EXCLUDE_APPS = [
'admin',
'registration', # Added registration
'debug_toolbar',
'debug_toolbar_user_panel',
'memcache_toolbar',
]
@markandrus
markandrus / gotcha.js
Created November 28, 2012 20:32
Variable Scoping in JavaScript: A counter-intuitive example?
/* Variable Scoping in JavaScript: A counter-intuitive example? */
// Initally empty list of functions
fs = [];
// Populate `fs` with functions.
for (var i=0; i<10; i++) {
fs.push(function() {
console.log(i);
});
@markandrus
markandrus / quick.c
Created November 30, 2012 05:27
Quicksort & Quickselect
#include <assert.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
static inline int
rand_in_range (int l, int u)
{
assert (l <= u);
int r=(random () % (u-l+1)) + l;
@markandrus
markandrus / telephone.c
Created December 4, 2012 00:22
telephone
#include <assert.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
static char keypad[10][5]={"0","1","ABC","DEF","GHI","JKL","MNO","PQRS","TUV","WXYZ"};
static char options[10] ={ 1 , 1 , 3 , 3 , 3 , 3 , 3 , 4 , 3 , 4 };
static inline bool
@markandrus
markandrus / bfs-state-monad.hs
Created December 12, 2012 10:06
Breadth-First Search, State Monad, explicit queue, and Lenses.
{-#LANGUAGE TemplateHaskell #-}
import Control.Lens
import Control.Monad.State
data Tree a = Node a
| Branch a (Tree a) (Tree a)
childrenOf (Node _) = []
childrenOf (Branch _ l r) = [l, r]
{-#LANGUAGE TemplateHaskell, NoImplicitPrelude, StandaloneDeriving #-}
module StableMarriage
( -- * Usage
-- $usage
Id
, Rank
, stableMarriage
-- * Internals
-- ** Partner