Skip to content

Instantly share code, notes, and snippets.

View DawnPaladin's full-sized avatar

James Harris DawnPaladin

View GitHub Profile
def naive(sock_pile)
paired = []
while (sock_pile.length > 0)
first = sock_pile.pop
match_index = sock_pile.index { |sock| sock == first }
second = sock_pile.delete_at(match_index)
paired.push [first, second]
end
paired
end
def sock_pile(colors, num_pairs)
sock_pairs = []
colors.each do |color|
num_pairs.times do
sock_pairs.push color
sock_pairs.push color
end
end
sock_pairs.shuffle
end
@DawnPaladin
DawnPaladin / _layout.ejs
Last active December 4, 2016 03:28
Harp layout file for Bootstrap, with highlight.js
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.8.0/styles/default.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.8.0/highlight.min.js"></script>
@DawnPaladin
DawnPaladin / _layout.ejs
Last active December 4, 2016 03:09
Harp layout file for Bootstrap
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
@DawnPaladin
DawnPaladin / rails_cheatsheet.rb
Last active November 28, 2016 04:46
Rails cheatsheet
# Initialize app
$ rails new app_name
# For better errors, put this in the Gemfile
group :development do
gem "better_errors"
end
gem "binding_of_caller"
# To include Bootstrap:
@DawnPaladin
DawnPaladin / Gemfile
Last active November 23, 2016 19:01
Including Bootstrap in Rails
gem 'bootstrap-sass'
@DawnPaladin
DawnPaladin / Gemfile
Created November 16, 2016 18:42
Sinatra boilerplate
source "https://rubygems.org"
gem 'sinatra'
gem 'sinatra-contrib'
@DawnPaladin
DawnPaladin / .gitignore
Created October 5, 2016 01:52
Bootstrap boilerplate
.sass-cache
@DawnPaladin
DawnPaladin / blocks.rb
Last active May 6, 2019 01:51
Basic Ruby
# my_script.rb
def my_each(arr)
i = 0
while i < arr.size
yield(arr[i]) # this executes whatever block gets passed in
i+=1
end
arr
end
@DawnPaladin
DawnPaladin / module.js
Created September 14, 2016 18:21
Module pattern
var module = (function() {
var exports = {};
var publicVar = "foo";
var privateVar = "bar";
exports.publicVar = publicVar; // Expose the public variable
return exports; // Now leaving the module; only things attached to "exports" will be visible outside.
})();
module.publicVar // => "foo"
module.privateVar // => undefined