Skip to content

Instantly share code, notes, and snippets.

class Node
attr_accessor *%i(value left right)
def initialize(value, left: nil, right: nil)
self.value = value
self.left = left
self.right = right
end
end
def root

Keybase proof

I hereby claim:

  • I am rpdillon on github.
  • I am rpdillon (https://keybase.io/rpdillon) on keybase.
  • I have a public key whose fingerprint is 90EF 478C 989C 54F4 F659 6303 9637 8E85 DBF2 EC6C

To claim this, I am signing this object:

#!/usr/bin/env ruby
words = {}.tap{|h| h.default = 0}
corpus = %x[ls].split.select{|n| n =~ /\.txt/}
.map{|f| File.read(f)}.reduce(&:+).split
.map{|w| w.downcase.gsub(/[^a-z]/,'')}
corpus.each{|w| words[w] += 1}
ranked_words = words.select{|k,_| k.length > 3}.sort_by{|_,v| -v}[0..5000]
10.times do
puts ranked_words.sample(4).map(&:first).map(&:capitalize).join
end
@rpdillon
rpdillon / sched-fix
Created February 15, 2013 18:45
Hack-fix for Heroku Scheduler
jQuery('.task .on-edit').show(); jQuery('.not-on-edit').hide(); jQuery('.timestamp').hide(); jQuery('.action.on-edit').show(); jQuery('input[name="command"]').css('width', '600px')
/* -*- Mode: Text; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
* Solarized.
* see output-base.css for details.
*/
@rpdillon
rpdillon / calc.rb
Created June 18, 2012 15:28
Evaluate simple infix arthimetic (four operators + parens)
# Requires space-delimited input if negative numbers are used
def tokenize(s)
s.split(/(-?[0-9]+|[*-\/+()])/).map { |t| t.strip }.select { |token| token != "" }
end
# Evaluates token collections that have only the + and - operators
def evaluate(tokens)
current = 0
value = Integer(tokens.shift)
op = tokens.shift
@rpdillon
rpdillon / string-permute.rb
Created June 18, 2012 15:27
Generate permutations of a string using the rank/unrank method (Skiena)
def rank(s)
if s.length == 1
return 0
else
multiplier = s.split("").sort.index(s[0].chr)
subcombos = (1..(s.length-1)).reduce { |a,b| a * b }
return (multiplier * subcombos) + rank(s.slice(1..-1))
end
end
@rpdillon
rpdillon / euler-3.clj
Created April 11, 2011 14:49
Project Euler #3 in Clojure
(defn primes-until
"A tail-recursive primes generator that generates primes until
<stop-pred> returns true. <stop-pred> is a function that
takes in the current candidate prime and the number of primes
generated so far and returns true or false."
[stop-pred]
(defn rec
"p: vector of primes found so far; i: candidate prime"
[p i] (cond
(stop-pred i (count p)) p
(defun random-dark-inspiration ()
"Downloads a random (dark) Inspiration theme and evaluates it."
(interactive)
(let* ((num (number-to-string (+ 500000 (random 399999)))))
(inspiration num)))
(defun inspiration (num)
"Fetches and evaluates the specified color theme from Inspiration."
(interactive)
(let* ((buffer (url-retrieve-synchronously
import java.util.ArrayList;
import java.util.List;
public class StringListSerialize {
public static final String DELIMITER = ",";
public static String serialize(List<String> strings) {
StringBuilder metadata = new StringBuilder();
StringBuilder concat = new StringBuilder();