Skip to content

Instantly share code, notes, and snippets.

@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
@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 / 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 / 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
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 / 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)

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 / Ball.elm
Last active October 23, 2019 18:10
Gravity and Ball
import Graphics.Collage exposing (..)
import Graphics.Element exposing (..)
import Color exposing (..)
import Keyboard
import Time
import Debug
-- Model
type alias Model = { x : Float, y : Float, radius: Float }
@JoelQ
JoelQ / README.md
Created October 15, 2015 13:50
Using Shell Scripts for a Better User Experience (source for https://robots.thoughtbot.com/improving-user-experience-with-shell-scripts)

Server scripts

This is the source for the scripts discussed in https://robots.thoughtbot.com/improving-user-experience-with-shell-scripts

Both scripts are in the bin/ directory of the repo that contains all the markdown documents for blog posts. Users run bin/server and everything is automatically set up for them to view a local preview of the blog. bin/server-setup is a dependency of bin/server and is never run directly by users.

Maitre-d is the name of the "blog engine" discussed in the article.

@JoelQ
JoelQ / dir_comparison.rb
Created January 8, 2015 16:45
__dir__ comparison
puts "__dir__ is the same as File.expand_path(__dir__)"
puts __dir__ == File.expand_path(__dir__)
puts "__dir__ is the same as File.expand_path( File.dirname(__FILE__) )"
puts __dir__ == File.expand_path( File.dirname(__FILE__) )
puts "__dir__ is the same as File.expand_path('../', __FILE__)"
puts __dir__ == File.expand_path("../", __FILE__)
# Script Output: