Skip to content

Instantly share code, notes, and snippets.

Matt Widmann mgwidmann

  • Washington DC
Block or report user

Report or block mgwidmann

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View watcher_hider.service.js.coffee
angular.module('utils.watcher_hider', [])
.service 'WatcherHider', ['$log', ($log)->
($scope)->
@scope = $scope
# Don't try this at home kids...
listeners = []
watches = []
@$watch = (name_or_fn, watcher_fn)=>
View ElmDemo.elm
module ElmDemo where
import Graphics.Element exposing (..)
import Graphics.Collage exposing (..)
import Color exposing (..)
import Time
import Text
import Window
-- MODEL
View ElmDemoRefactored.elm
module ElmDemoRefactored where
import Graphics.Element exposing (..)
import Graphics.Collage exposing (..)
import Color exposing (..)
import Time
import Text
import Window
-- MODEL
@mgwidmann
mgwidmann / ElmDemo.elm
Created Jan 12, 2016
Basic SVG drawing in Elm
View ElmDemo.elm
module ElmDemo where
import Graphics.Element exposing (..)
import Graphics.Collage exposing (..)
import Color exposing (..)
import Time
import Text
import Window
-- MODEL
@mgwidmann
mgwidmann / bartender.ex
Created Mar 4, 2016
Simple example showcasing the power of pattern matching.
View bartender.ex
# Lets create a bartender in the same way you would in a imperative language.
defmodule Bartender do
def serve(user, drink) do
if user.age >= 21 do
IO.puts "The bartender slides #{user.name} a #{drink}."
else
IO.puts "Sorry #{user.name}, you'll have to wait #{21 - user.age} more year(s)."
end
end
end
View on_definition.ex
$ mix new policy_enforcement_playground
$ cd policy_enforcement_playground
# Make a new file lib/authorization.ex
defmodule Authorization do
def authorize_first_thing(_user, resource) do
# Do some authorization here, modifying what gets returned based on the
# authorization level of the user
resource
end
@mgwidmann
mgwidmann / with_and_dialyzer.ex
Created Jun 23, 2016
Showing an example of using the with keyword & usage/output of dialyzer
View with_and_dialyzer.ex
# Assuming we have some code like this
defmodule Processor do
# A lot of code uses the following format, and its a good way to write code
# However, when we have potential failures at each step things get complicated
def process(user, meta) do
user
|> verify_authenticity(meta[:credentials])
|> process_payment(meta[:charges])
|> issue_resource
|> generate_response
View get_max_profit.rb
# prices = [11, 7, 5, 8, 10, 9]
# => 5
# ALGO 1: BRUTE FORCE
# for each map to profit, find biggest number
# 11 => [-4, -6, -3, -1, -2]
# 7 => [-2, 1, 3, 2]
# 5 => [3, 5, 4]
# 8 => [2, 1]
# 10 => [-1]
#
@mgwidmann
mgwidmann / wat.scala
Last active Mar 6, 2018
Scala's violations of the principle of least surprise
View wat.scala
{} + "" == "()" // true
pow(2, 31).intValue + 1 > 0 // false
Set(1,2,3).sameElements(Set(3,2,1)) // false
Some(null).get // No exception :(, Some(null) should result in a None IMO
// Option objects might be null!!!
def safeOption(shouldBeSafe : Option[String]) : String = {
@mgwidmann
mgwidmann / supervisor.ex
Last active Jul 30, 2018
Overview of the Supervision system
View supervisor.ex
# The golden trinity of Erlang is the secret sauce behind what makes
# Elixir a strong choice for any backend application and/or system.
# https://tkowal.wordpress.com/2015/10/20/failing-fast-and-slow-in-erlang-and-elixir/
# The supervision and worker system, commonly referred to as OTP (Open
# Telecom Platform, which has nothing to do with telephony), is what
# gives Erlang/Elixir applications them a robust "self-healing" type
# property that makes them extremely fault tolerant.
You can’t perform that action at this time.