Skip to content

Instantly share code, notes, and snippets.

View MattMSumner's full-sized avatar

Matthew Sumner MattMSumner

View GitHub Profile
@MattMSumner
MattMSumner / recurse.c++
Created April 12, 2017 23:02
Recursion in c++
int findLargest(int array[])
{
int arrayLength = sizeof(array)/sizeof(array[0]);
int firstElement = array[0];
int newArray[] = // This needs to be a new array without the original array's first element.
if (arrayLength == 1) {
return max(firstElement, newArray[0])
} else {
return max(firstElement, findLargest(newArray));
}

Readme

This contains instructions for setting up a bookmarklet to pre-populate the form found on Tell Me When It Closes.

Chrome

  1. ⌘⌥B to open the bookmarks window
  2. Right click in the bookmarks pane and select Add Page...
  3. Choose an appropriate name.
@MattMSumner
MattMSumner / components.my-component.js
Created September 28, 2016 15:16
same array for all components
import Ember from 'ember';
export default Ember.Component.extend({
someArray: [1, 2],
actions: {
addElement() {
this.get('someArray').pushObject(1);
}
}
});
data Hop = Hop {name :: String, alphaAcid :: Double} deriving (Show)
data BoilTime = BoilTime Int deriving (Show)
data HopAddition = HopAddition Hop BoilTime deriving (Show)
data HomebrewRecipe = HomebrewRecipe [HopAddition] deriving (Show)
recipeIbus :: HomebrewRecipe -> Double
recipeIbus (HomebrewRecipe as) = sum $ map ibus as
ibus :: HopAddition -> Double
ibus x = utilization x * ouncesOfHops * 7490 / 5

A function describes a relationship between two sets, a set of inputs and outputs.

Combinators

  1. λx.xxx - YES
  2. λxy.zx - NO
  3. λxyz.xy(zx) - YES
  4. λxyz.xy(zxy) - YES
  5. λxy.xy(zxy) - NO
matrix = [
[1,2,3,4,5],
[6,7,8,9,10],
[2,4,6,8,10],
[1,3,5,7,9],
[3,6,9,2,4]
]
matrix.each_with_index.inject({start_top_left: 0, start_top_right: 0}) do |hash_of_sums, (row, index)|
hash_of_sums[:start_top_left] += row[index]