Skip to content

Instantly share code, notes, and snippets.

View dylanerichards's full-sized avatar

Dylan Richards dylanerichards

View GitHub Profile

Keybase proof

I hereby claim:

  • I am dylanerichards on github.
  • I am dylanerichards (https://keybase.io/dylanerichards) on keybase.
  • I have a public key ASCe5ovvtncj3b6yQevyKLq2erkT6cm35ZiARvm36wPA8Ao

To claim this, I am signing this object:

@dylanerichards
dylanerichards / trapped-rain-refactored.rb
Created October 14, 2017 17:15
Trapped Rain Problem
def trapped_rain(data)
[].tap { |total_rain| data.each_with_index { |datum, index| total_rain << [data[0..index].max, data[index..-1].max].min - datum} }.inject(&:+)
end
trapped_rain(rainfall)
@dylanerichards
dylanerichards / html
Created March 3, 2017 16:41
getting input currency formatting to work
in application.html.erb
<html ng-app="app">
<div ng-controller="moneyCtrl">
<input type="text" ng-model="test" format="number"/>
</div>
var header = document.getElementById("header")
var button = document.getElementById("login-button")
button.addEventListener("click", function() {
validateForm()
})
function validateForm() {
if(checkPassword() == true && checkUsername() == true) {
def find(id)
cmd = `sqlite3 test "select * from things where id = #{id}"`
end
def all
users_array = []
users = `sqlite3 test "select * from things;"`.split("\n")
users.each { |user| users_array << user }
@dylanerichards
dylanerichards / problem-1.js
Last active September 28, 2016 20:36
JS Code Challenges
function stringy(num) {
var result = [1];
if (num == 1) { return result; };
for(i = 0; i < num; i++) {
var lastElement = result[result.length - 1];
lastElement == 0 ? result.push(1) : result.push(0);
}
@dylanerichards
dylanerichards / git.sh
Created September 8, 2016 20:32
Making a repo
➜ new-repository git init
Initialized empty Git repository in /Users/dylanrichards/code/new-repository/.git/
➜ new-repository git:(master) touch index.html
➜ new-repository git:(master) ✗ gd
➜ new-repository git:(master) ✗ gaa
On branch master
Initial commit
Changes to be committed:
class WakaWaka
attr_reader :code
def initialize(code)
@code = code
end
MAPPINGS = {
'<' => 'Waka',
'>' => 'waka',
class NumberGuessingGame
def initialize
p @number = rand(0..9).to_s
end
def guess
puts "I'm thinking of a random number from 0 to 9"
puts "Can you guess it?"
input = gets.chomp
board_string = "003020600900305001001806400008102900700000008006708200002609500800203009005010300"
class Sudoku
attr_accessor :board
def initialize(string)
@board = string
end
def rows