Skip to content

Instantly share code, notes, and snippets.

Ruby docs for Array#uniq

From the docs:

uniq → new_ary uniq { |item| ... } → new_ary Returns a new array by removing duplicate values in self.

If a block is given, it will use the return value of the block for comparison. It compares values using their hash and eql? methods for efficiency.

@JoelQ
JoelQ / intro_to_elm_slide_notes.md
Created June 15, 2016 19:55
Raw speaker notes for Intro to Elm talk. Slides at http://www.slideshare.net/thoughtbot/intro-to-elm

What is Elm

Pure Functions

What does that mean?

  • For a given input, you always get the same output
  • The output cannot depend on any external factors (e.g. File on disk, some external variable)
namespace :dependencies do
task :pre_task do
puts "pre-task"
end
task task1: :pre_task do
puts "task1"
end
task task2: :pre_task do
@JoelQ
JoelQ / Main.elm
Created October 27, 2016 18:40
Simple ports example
port module Main exposing (..)
import Html.App
import Html exposing (..)
import Html.Attributes exposing (id)
type alias Row =
List String
@JoelQ
JoelQ / Shuffle.elm
Created November 21, 2016 21:05
Mapping a list to a shuffled version of itself
module Main exposing (..)
import Array
import Tuple
import Dict exposing (Dict, get)
import Random exposing (Generator, map)
-- RANDOM
@JoelQ
JoelQ / 1-README.md
Last active December 16, 2016 02:38
What's up with Html a ?

What's up with Html a?

Ever wonder why sometimes the compiler yells at you for using type Html a ? Why is a ok some times but not others?

It's not unique to Html a. Look at the same problem using a simpler type we all understand: List a.

Here are a few questions and thoughts to ponder:

  • Compare the myList and myHtml functions. How are they similar? How are they different?
  • Why do you think these functions will compile or not compile?
@JoelQ
JoelQ / monoid_builder.rb
Created February 24, 2017 19:23
Builders as monoids
User = Struct.new(:name, :age, :profession)
class MonoidBuilder
def initialize(name: nil, age: nil, profession: nil)
@name = name
@age = age
@profession = profession
end
def self.empty

Mapping the world

Abstract

Provide a concise description for the program limited to 600 characters or less.

From the earliest cave paintings to today's GPS-assisted smartphone apps, maps have been an important part of we have described the world around us. But what goes into turning the life-size 3d world into a 2d image that fits in your

Modeling Data with Algebraic Data Types

Abstract

Provide a concise description for the program limited to 600 characters or less.

What is "good code"? You've probably heard something like "readable, easy to change, modular, and correct". But what does that look like in practice?

@JoelQ
JoelQ / README.md
Last active June 2, 2017 19:56
Script to generate domain-specific Elm types wrapping primitives (see https://robots.thoughtbot.com/lessons-learned-avoiding-primitives-in-elm for why this is a good idea)