Skip to content

Instantly share code, notes, and snippets.

View mattbarackman's full-sized avatar

Matt Barackman mattbarackman

View GitHub Profile
@mattbarackman
mattbarackman / Type_Families_Sealed_Traits_and_Exhaustive_Pattern_Matching_in_Scala.md
Last active August 25, 2020 01:08
A brief lesson on Type Families, Sealed Traits, and Exhaustive Pattern Matching in Scala

Scala: Type Families, Sealed Traits, and Exhaustive Pattern Matching

By: Matt Barackman

What is a Type Family?

A collection of objects or case classes that share a sealed trait.

In the example below, the type family would be a collection of traffic light colors with Red, Yellow, and Green as member objects.

Default Rendering

By default, controllers in Rails automatically render views with names that correspond to valid routes.

For example, if you have this code in your BooksController class:

class BooksController < ApplicationController
end
@mattbarackman
mattbarackman / index.html
Created June 19, 2013 06:58 — forked from dbc-challenges/index.html
DBC Phase 2 Practice Assessment Part 3
<!doctype html>
<html>
<head>
<link rel="stylesheet" href="http://cdn.jsdelivr.net/normalize/2.1.0/normalize.css">
<link rel="stylesheet" href="main.css">
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700,800">
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Lato:100,900">
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/3.0.2/css/font-awesome.min.css">
</head>
@mattbarackman
mattbarackman / index.html
Last active December 18, 2015 09:19 — forked from dbc-challenges/index.html
DBC Phase 2 Practice Assessment Part 3
<!doctype html>
<html>
<head>
<link rel="stylesheet" href="http://cdn.jsdelivr.net/normalize/2.1.0/normalize.css">
<link rel="stylesheet" href="main.css">
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700,800">
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Lato:100,300,400,900">
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/3.0.2/css/font-awesome.min.css">
</head>
<!doctype html>
<html>
<head>
<link rel="stylesheet" href="http://cdn.jsdelivr.net/normalize/2.1.0/normalize.css">
<link rel="stylesheet" href="main.css">
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700,800">
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Lato:100,900">
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/3.0.2/css/font-awesome.min.css">
</head>
/* Here is your chance to take over Socrates!
Spend 10 minutes on each of the following hacks to the socrates website.
Enter them in the console to make sure it works and then save
your results here.
Choose a new pair for each. Add your names to the section you complete.
*/
@mattbarackman
mattbarackman / font-face.sublime-snippet
Created April 24, 2013 21:26
This is a snippet for Sublime Text 2 which contains the CSS rules necessary for creating a custom font-face. This would be used if you wanted to include a font-face kit downloaded from a website like fontsquirrel.com in your project. After adding the font files to your project folder, you would add this snippet to your CSS file and would then be…
<snippet>
<content><![CDATA[
@font-face {
font-family: '${1:FontName}';
src: url('${2:eot_filepath}'); /* IE9 Compat Modes */
src: url('${2:eot_filepath}?#iefix') format('embedded-opentype'), /* IE6-IE8 */
url('${4:woff_filepath}') format('woff'), /* Modern Browsers */
url('${5:ttf_filepath}') format('truetype'), /* Safari, Android, iOS */
url('${6:svg_filepath}#svgFontName') format('svg'); /* Legacy iOS */
}
@mattbarackman
mattbarackman / MidpointFindingKarel.java
Created September 12, 2012 03:24
Solution to CS106A Assignment 1.4 - MidpointFindingKarel
/*
* File: MidpointFindingKarel.java
* -------------------------------
* When you finish writing it, the MidpointFindingKarel class should
* leave a beeper on the corner closest to the center of 1st Street
* (or either of the two central corners if 1st Street has an even
* number of corners). Karel can put down additional beepers as it
* looks for the midpoint, but must pick them up again before it
* stops. The world may be of any size, but you are allowed to
* assume that it is at least as tall as it is wide.
@mattbarackman
mattbarackman / CheckerboardKarel.java
Created September 12, 2012 03:03
Solution to CS106A Assignment 1.3 - CheckerboardKarel
/*
* File: CheckerboardKarel.java
* ----------------------------
* The CheckerboardKarel class should draw a checkerboard using
* beepers, as described in Assignment 1. Karel will start in
* the bottom left-corner facing East and will place a beeper on
* its current location. It will start by going east, and snaking
* up the board, placing a beeper on every other square. It should
* be able to handle any size grid.
*
@mattbarackman
mattbarackman / StoneMasonKarel.java
Created September 12, 2012 02:56
Solution to CS106A Assignment 1.2 - StoneMasonKarel
/*
* File: StoneMasonKarel.java
* --------------------------
* The StoneMasonKarel subclass as it appears here does nothing.
* When you finish writing it, it should solve the "repair the quad"
* problem from Assignment 1. In addition to editing the program,
* you should be sure to edit this comment so that it no longer
* indicates that the program does nothing.
* This sub-class of Karel will repair missing beepers in
* vertical "stone columns". Karel will start at [1,1]