Skip to content

Instantly share code, notes, and snippets.

View taylorlapeyre's full-sized avatar

Taylor Lapeyre taylorlapeyre

View GitHub Profile
@taylorlapeyre
taylorlapeyre / rps.clj
Created February 7, 2015 16:57
Rock Paper Sissors
(defn draw?
[machine-choice player-choice]
(= machine-choice player-choice))
(defn player-win?
[machine-choice player-choice]
(case machine-choice
"rock" (= player-choice "paper")
"paper" (= player-choice "sissors")
"sissors" (= player-choice "rock")))
(map fizzbuzz (range 100))
; => ("fizzbuzz" 1 2 "fizz" 4 "buzz" "fizz" 7 ...)
(defn divisible?
"Returns true if the remainder of x / y is zero, else false."
[x y]
(zero? (rem x y)))
(defn fizzbuzz
"Returns Fizz if n is divisible by 3, buzz if n is divisible by 5,
and fizzbuzz if n is divisible by both."
[n]
(cond (divisible? n 15) "fizzbuzz"
@taylorlapeyre
taylorlapeyre / clojure
Created December 6, 2014 22:47
An easy easy way to run Clojure.
#!/usr/bin/env bash
LEIN_URL=https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein
function execute_clojure {
if [[ -d $HOME/.lein ]]; then
if [[ ! -f $HOME/.lein/profiles.clj ]]; then
echo '{:user {:plugins [[lein-exec "0.3.4"]]}}' > $HOME/.lein/profiles.clj
fi
else
@taylorlapeyre
taylorlapeyre / description.md
Last active August 29, 2015 14:08
A clever problem for an interview or just for fun

Generating HTML

Say that one day we decide to write a new templating library for generating HTML.

In this new library, you are passed an array where the first element is the name of an HTML tag, the second element is optionally a hash containing the element's HTML attributes, and the rest of the elements are the HTML elements that are children of it.

For example:

html = [:html,
@taylorlapeyre
taylorlapeyre / answer.clj
Last active August 29, 2015 14:07
Answer
(defn abs [x]
"Returns x if the number is > 0, otherwise -x"
(if (neg? x) (- x) x))
(defn square [x]
"Squares the number"
(* x x))
(defn cube [x]
"Multiplies the square of the number by itself"
getStuff = function() {
return {
url: window.location.href,
name: $('.full-name').html(),
title: $('.title').html(),
date: new Date(),
}
}
/*
* int i = 0;
* int nl = 0;
* while (S[i]) {
* if (S[i] > 97 && S[i] < 122) {
* nl++;
* }
* i++;
* }
*/
@taylorlapeyre
taylorlapeyre / tutor.rb
Last active August 29, 2015 13:57
Quick attempt at Eric's thing in ruby, without dealing with arrays
class SpanishTutor
def initialize(path_to_dictionary)
@dictionary = parse_file(path_to_dictionary)
@num_incorrect = 0
@num_correct = 0
start_repl
end
def start_repl
loop do
@taylorlapeyre
taylorlapeyre / guide.md
Last active August 29, 2015 13:56
Guides for developing our web application.

The Things

The Language

[Ruby][ruby] - a dynamic scripting language with a focus on simplicity

The Framework

[Rails][rails] - a popular MVC web framework built on ruby