Skip to content

Instantly share code, notes, and snippets.

View types.markdown

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 Jul 3, 2021
Elm Destructuring (or Pattern Matching) cheatsheet
View destructuring.md

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 Mar 24, 2020
Using Mailboxes in Elm: a tutorial blog post
View using_mailboxes_in_elm.md

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 Jul 18, 2018
Getting Mailgun SMTP Batch emails to work in ActionMailer.
View mailgun_batch_smtp.rb
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 Sep 21, 2021
Activerecord without Rails
View Rakefile
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 Apr 27, 2019
Higher order function in bash!
View gist:6015948
#!/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 Feb 12, 2012
List remote Git branches and the last commit date for each branch. Sort by most recent commit date.
View git-branches-by-commit-date.sh
# 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 Feb 19, 2011
A naive socket chat using select() and ruby fibers
View fiberchat.rb
require 'rubygems'
require 'socket'
include Socket::Constants
class ChatServer
def initialize
@reading = Array.new
@writing = Array.new
@clients = Hash.new