Skip to content

Instantly share code, notes, and snippets.

View bdfinlayson's full-sized avatar

Bryan Finlayson bdfinlayson

View GitHub Profile
@bdfinlayson
bdfinlayson / pancake.rb
Created February 20, 2018 03:10
Flattening an array of arbitrarily nested arrays of integers into a flat array of integers
def to_pancake(ingredients, pancake = [])
ingredients.each do |ingredient|
ingredient.is_a?(Array) ? to_pancake(ingredient, pancake) : pancake << ingredient
end
pancake
end
@bdfinlayson
bdfinlayson / gist:27d9e15e82e978a83b3b
Last active August 29, 2015 14:24
Follow Up Answers: Javascript Closure, Stateless HTTP Protocol, and Hoisting
// QUESTION: What is a closure in Javascript?
// ANSWER: Javascript closures are inner functions
// that refer to variables in their outer function
// EXAMPLE:
function whatNum () {
var outerNum = 10;
console.log('I am the outer function and I returned ' + outerNum)
@bdfinlayson
bdfinlayson / gist:276c5d35559e3f601094
Last active August 29, 2015 14:24
Hash Parser Code Challenge
class HashParser
def initialize(hash)
@hash = hash
end
def parse
array = Array.new
@hash.each_key do |key|
if key.is_a?(Fixnum)
@bdfinlayson
bdfinlayson / gist:82fb1027c0db614be454
Created May 29, 2015 14:35
Vim key remapping for setting up a new grid layout
This mapping opens up a new tab in vim with a grid layout:
map <s-tab> :tabnew<cr>:vsplit<cr>:split<cr>:wincmd l<cr>:split<cr>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
var date = new Date();
{
"rules": {
"users": {
"$uid": {
".write": "auth !== null && auth.uid === $uid",
".read": "auth !== null && auth.uid === $uid"
}
}
}
}
'use strict';
var userZipCode,
startingUrl,
customUrl;
document.querySelector('#submitButton').addEventListener('click', function() {
userZipCode = document.querySelector('#userZipCode').value;
startingUrl = 'https://api.wunderground.com/api/152eccaad753eb4b/forecast10day/q/37207.json';
customUrl = startingUrl.replace('37207', userZipCode);
<!-- first exercise -->
<ul class="list" id="font">
<li >One</li>
<li>Two</li>
<li>Three</li>
<ul>
<li><a href="//google.com">Four</a></li>
<li><img class="profile" src="https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xap1/v/t1.0-1/p320x320/10407377_1513146665609773_349423795913602248_n.jpg?oh=2b0a250e7e5c6fe24802bc86cd0f2fc0&oe=553D5781&__gda__=1428243844_9dfe36a5e35f033f59332b10b9d1b221">Five</a></li>
</ul>