Skip to content

Instantly share code, notes, and snippets.

Applied Functional Programming with Scala - Notes

Copyright © 2016-2018 Fantasyland Institute of Learning. All rights reserved.

1. Mastering Functions

A function is a mapping from one set, called a domain, to another set, called the codomain. A function associates every element in the domain with exactly one element in the codomain. In Scala, both domain and codomain are types.

val square : Int => Int = x => x * x
// paste in your console
speechSynthesis.onvoiceschanged = function() {
var msg = new SpeechSynthesisUtterance();
msg.voice = this.getVoices().filter(v => v.name == 'Cellos')[0];
msg.text = Object.keys(window).join(' ');
this.speak(msg);
};
@efroese
efroese / gist:968ffdfc586863060537
Created June 9, 2015 20:46
Scala syntax highlighting for reviewboard in Chrome!
@podlech
podlech / yosemite_ruby_libv8_therubyracer.sh
Last active November 1, 2016 11:02
OS X Yosemite ruby (1.9.3p484) libv8 (3.11.8.17) therubyracer (0.11.4)
brew install homebrew/dupes/apple-gcc42
rbenv install 1.9.3-p484
rbenv global 1.9.3-p484
git clone https://github.com/cowboyd/libv8.git
cd libv8
git checkout 3.11
export CC=/usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/gcc-4.2
export CXX=/usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/g++-4.2
export CPP=/usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/cpp-4.2
bundle install
@AviDuda
AviDuda / README.md
Last active April 23, 2024 10:32
Unmuting Twitch VODs
@luxerama
luxerama / grape_log_request_subscriber.rb
Last active December 12, 2016 15:31
Grape Log Instrumentation
class GrapeRequestLogSubscriber < ActiveSupport::LogSubscriber
def grape_controller(event)
request = Rack::Request.new(event.payload).env
response = Rack::Response.new(event.payload)
data = extract_request(request)
data.merge! extract_status(response)
logger.send(:warning, data.to_json)
end
@afn
afn / gist:c04ccfe71d648763b306
Created June 12, 2014 15:35
Restart phantomjs when it hangs
# Borrowed from https://github.com/y310/rspec-retry/blob/master/lib/rspec/retry.rb
CAPYBARA_TIMEOUT_RETRIES = 3
RSpec.configure do |config|
config.around(:each, type: :feature) do |ex|
example = RSpec.current_example
CAPYBARA_TIMEOUT_RETRIES.times do |i|
example.instance_variable_set('@exception', nil)
self.instance_variable_set('@__memoized', nil) # clear let variables
@lelandbatey
lelandbatey / whiteboardCleaner.md
Last active February 25, 2024 13:47
Whiteboard Picture Cleaner - Shell one-liner/script to clean up and beautify photos of whiteboards!

Description

This simple script will take a picture of a whiteboard and use parts of the ImageMagick library with sane defaults to clean it up tremendously.

The script is here:

#!/bin/bash
convert "$1" -morphology Convolve DoG:15,100,0 -negate -normalize -blur 0x1 -channel RBG -level 60%,91%,0.1 "$2"

Results

@v1nc3ntlaw
v1nc3ntlaw / mysql-utf8mb4-barracuda
Last active August 22, 2020 00:09
MySQL using utf8mb4 and innodb_file_format Barracuda settings
[mysqld]
init_connect='SET collation_connection = utf8mb4_unicode_ci'
init_connect='SET NAMES utf8mb4'
character-set-server = utf8mb4
character-set-client = utf8mb4
collation-server = utf8mb4_unicode_ci
skip-character-set-client-handshake
innodb_file_format = Barracuda
@nathany
nathany / ruby2.md
Last active December 20, 2015 00:59
Ruby 2.0 backwards incompatible changes

Ruby 2.0 backwards incompatible changes

From Peter Cooper's Walkthrough:

  • lines, bytes, chars, codepoints returned an Enumerator in 1.9 -> use each_lines, each_bytes, each_chars, each_codepoints instead for an Enumerator
  • # encoding: utf-8 is the default (which impacts regular expressions that expect it to be us-ascii, eg. vpim)
  • respond_to? on a protected method returns false (was true)
  • inspect doesn't use the redefined to_s
  • Array#values_at returns nil for each number outside of the array
  • CSV.dump & CSV.load are gone (object serialization)