Skip to content

Instantly share code, notes, and snippets.

This document has moved!

It's now here, in The Programmer's Compendium. The content is the same as before, but being part of the compendium means that it's actively maintained.

@yang-wei
yang-wei / destructuring.md
Last active September 5, 2024 18:56
Elm Destructuring (or Pattern Matching) cheatsheet

Should be work with 0.18

Destructuring(or pattern matching) is a way used to extract data from a data structure(tuple, list, record) that mirros the construction. Compare to other languages, Elm support much less destructuring but let's see what it got !

Tuple

myTuple = ("A", "B", "C")
myNestedTuple = ("A", "B", "C", ("X", "Y", "Z"))
@mgold
mgold / using_mailboxes_in_elm.md
Last active March 24, 2020 16:05
Using Mailboxes in Elm: a tutorial blog post

Using Mailboxes in Elm

Max Goldstein | July 30, 2015 | Elm 0.15.1

In Elm, signals always have a data source associated with them. Window.dimensions is exactly what you think it is, and you can't send your own events on it. You can derive your own signals from these primitives using map, filter, and merge, but the timing of events is beyond your control.

This becomes a problem when you try to add UI elements. We want to be able to add checkboxes and dropdown menus, and to receive the current state of these elements as a signal. So how do we do that?

The Bad Old Days

@tiegz
tiegz / mailgun_batch_smtp.rb
Last active July 18, 2018 15:43
Getting Mailgun SMTP Batch emails to work in ActionMailer.
class FoobarMailer < BaseMailer
# The method you'll actually call to generate the batched email
def batched_foobar
# Recipient Variables
recipients = {"you@somewhere.com" => {"name" => "You Youington"}}
mail(to: "me@somewhere.com") do |format|
# Mailgun requires you to base64 your Recipient Variables JSON
format.custom('application/json', content_transfer_encoding: "base64") do
render text: Base64.encode64(recipients.to_json)
@schickling
schickling / Rakefile
Last active September 3, 2024 02:52
Activerecord without Rails
require "active_record"
namespace :db do
db_config = YAML::load(File.open('config/database.yml'))
db_config_admin = db_config.merge({'database' => 'postgres', 'schema_search_path' => 'public'})
desc "Create the database"
task :create do
ActiveRecord::Base.establish_connection(db_config_admin)
@marc0der
marc0der / gist:6015948
Last active May 24, 2022 10:06
Higher order function in bash!
#!/bin/bash
function printit {
echo "This is from an embedded function: $1"
}
function printthat {
echo "This is the first line."
$1 $2
echo "This is the third line."
@jasonrudolph
jasonrudolph / git-branches-by-commit-date.sh
Created February 12, 2012 20:40
List remote Git branches and the last commit date for each branch. Sort by most recent commit date.
# Credit http://stackoverflow.com/a/2514279
for branch in `git branch -r | grep -v HEAD`;do echo -e `git show --format="%ci %cr" $branch | head -n 1` \\t$branch; done | sort -r
@pfleidi
pfleidi / fiberchat.rb
Created February 19, 2011 18:51
A naive socket chat using select() and ruby fibers
require 'rubygems'
require 'socket'
include Socket::Constants
class ChatServer
def initialize
@reading = Array.new
@writing = Array.new
@clients = Hash.new