Skip to content

Instantly share code, notes, and snippets.

@jbrechtel
jbrechtel / run_me_before_compiling_ruby.txt
Created September 6, 2013 15:01
Before building Ruby....don't forget about readline zlib and ssl!
apt-get -y install build-essential libssl-dev libreadline-dev zlib1g-dev
@jbrechtel
jbrechtel / hack.sh
Last active December 20, 2015 14:39 — forked from erikh/hack.sh
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/6148219/hack.sh | sh
#
(ns middler-clojure.core
(:use org.httpkit.server)
(:use clojure.walk)
(:require [org.httpkit.client :as http])
(:gen-class))
(defn app [req]
(println req)
(let [uri (:uri req)]
(println (class uri))
require 'rubygems'
require 'csv'
require 'json'
require 'pp'
data = CSV.parse(File.read(ARGV[0]))
cols = data.shift
hashes = data.map { |v| cols.zip(v) }.map { |a| Hash[*a.flatten] }
puts 'var e = '+hashes.to_json
import org.specs2._
import execute.AsResult
import mutable.Around
/* this scope is incidentally lazy since the singleton never gets constructed if code that uses it isn't executed */
object databaseScope extends Around {
def setupDB { println("#####################\nBUILDING DATABASE\n#####################") }
setupDB
def around[T: AsResult](t: => T) = AsResult(t)
@jbrechtel
jbrechtel / game_of_life.markdown
Last active June 19, 2017 01:35
Conway's Game of Life

Conway's Game of Life

Conway's Game of Life is a set of rules which define a cellular automata. Read more about it in Wikipedia. Your task is to write a Conway's Game of Life (GOL) simulation.

GOL consists of a two-dimensional grid of cells. Each cell is either alive or dead. Your simulation should calculate the grid over a user-specified number of generations. To calculate the next generation you apply the following rules to each cell in the grid and the resulting grid is the next generation.

Rules

  • Any live cell with fewer than two live neighbours dies, as if caused by under-population.
  • Any live cell with two or three live neighbours lives on to the next generation.
@jbrechtel
jbrechtel / foo.clj
Last active December 12, 2015 02:49
clojure example
(defn add-prefix [prefix string]
"Prepends prefix to string separated by a space"
(str prefix " " string))
(def formalize-male
"Returns a formal version of a male name"
(partial add-prefix "Mr"))
(defn parenthesize [string]
"Wraps names in parentheses"
@jbrechtel
jbrechtel / deck_of_cards_2.markdown
Last active June 19, 2017 01:34
Dealing cards continued

Dealing cards to players

Using the classes built in the previous dealing cards problem, we're going to deal cards to players now.

Your program will deal cards to a user-specified number of players.

The program should ask for user input and respond to the following 3 commands

  • add_player
  • deal_cards
@jbrechtel
jbrechtel / deck_of_cards_1.markdown
Created January 31, 2013 14:57
Deck of cards problem part 1

Dealing cards

A deck comprises 52 cards of 4 suits (spades, hearts, clubs, and diamonds). Each suit has 13 cards of values from 2-10, Jack, Queen, King, and Ace.

Write a class to represent a card. The class should have a suit and value property indicating its suit and value.

Write a class that has a draw method.

  • The draw method should accept an integer as an argument.
  • The draw method should return an array of card objects.
@jbrechtel
jbrechtel / event_ticketing.markdown
Last active December 11, 2015 23:48
Event ticketing problem

You're building a system to process orders for seats to an event

You have two input files

The first is sections.txt. It contains a list of sections of seats. Each section has a name, a number of available seats and a cost per seat. It looks like this

Upper 30 50
Balcony 20 100