Skip to content

Instantly share code, notes, and snippets.

Avatar

Paul Schoenfelder bitwalker

View GitHub Profile
@bitwalker
bitwalker / run.sh
Created Jun 15, 2016 — forked from djo/run.sh
Handling of UNIX-signals in Erlang/Elixir is not supported, this script provides start-stop management with handling TERM signal for Docker installation.
View run.sh
#!/usr/bin/env bash
set -x
term_handler() {
echo "Stopping the server process with PID $PID"
erl -noshell -name "term@127.0.0.1" -eval "rpc:call('app@127.0.0.1', init, stop, [])" -s init stop
echo "Stopped"
}
trap 'term_handler' TERM INT
@bitwalker
bitwalker / observer.md
Created Mar 17, 2016 — forked from pnc/observer.md
Using Erlang observer/appmon remotely
View observer.md

Using OTP's observer (appmon replacement) remotely

$ ssh remote-host "epmd -names"
epmd: up and running on port 4369 with data:
name some_node at port 58769

Note the running on port for epmd itself and the port of the node you're interested in debugging. Reconnect to the remote host with these ports forwarded:

$ ssh -L 4369:localhost:4369 -L 58769:localhost:58769 remote-host
@bitwalker
bitwalker / time_vs_datatime.md
Created Mar 11, 2016 — forked from pixeltrix/time_vs_datatime.md
When should you use DateTime and when should you use Time?
View time_vs_datatime.md

When should you use DateTime and when should you use Time?

It's a common misconception that [William Shakespeare][1] and [Miguel de Cervantes][2] died on the same day in history - so much so that UNESCO named April 23 as [World Book Day because of this fact][3]. However because England hadn't yet adopted [Gregorian Calendar Reform][4] (and wouldn't until [1752][5]) their deaths are actually 10 days apart. Since Ruby's Time class implements a [proleptic Gregorian calendar][6] and has no concept of calendar reform then there's no way to express this. This is where DateTime steps in:

>> shakespeare = DateTime.iso8601('1616-04-23', Date::ENGLAND)
=> Tue, 23 Apr 1616 00:00:00 +0000
>> cervantes = DateTime.iso8601('1616-04-23', Date::ITALY)
=> Sat, 23 Apr 1616 00:00:00 +0000
View how-to-set-up-stress-free-ssl-on-os-x.md

How to set up stress-free SSL on an OS X development machine

One of the best ways to reduce complexity (read: stress) in web development is to minimize the differences between your development and production environments. After being frustrated by attempts to unify the approach to SSL on my local machine and in production, I searched for a workflow that would make the protocol invisible to me between all environments.

Most workflows make the following compromises:

  • Use HTTPS in production but HTTP locally. This is annoying because it makes the environments inconsistent, and the protocol choices leak up into the stack. For example, your web application needs to understand the underlying protocol when using the secure flag for cookies. If you don't get this right, your HTTP development server won't be able to read the cookies it writes, or worse, your HTTPS production server could pass sensitive cookies over an insecure connection.

  • Use production SSL certificates locally. This is annoying

View .conf
my_app.complex_list.buzz.type = person
my_app.complex_list.buzz.age = 25
my_app.complex_list.fido.type = dog
my_app.complex_list.fido.opts.special_value = biz
View .conf
my_app.complex_list.buzz.type = person
my_app.complex_list.buzz.age = 25
my_app.complex_list.fido.type = dog
my_app.complex_list.fido.age = 5
@bitwalker
bitwalker / dabblet.css
Created Nov 7, 2013 — forked from giuseppeg/dabblet.css
Dead Center an element with display: inline-block
View dabblet.css
/**
* Dead Center an element with display: inline-block
*/
html,
body { margin: 0; height: 100%; }
.container {
letter-spacing: -0.31em;
text-rendering: optimizespeed;
View passive-attach-module-pattern-example.js
/**
* JavaScript Module Pattern Example with "Passive Attachment"
*/
(function (root, builder, undefined) {
if (typeof define === 'function') {
// CommonJS AMD
define('MyModule', ['jQuery', 'DependencyA', 'DependencyB'], function($, a, b) {
return builder(root, $, a, b, null);
});
}
View IndexedState.md

The Indexed State Monad in Haskell, Scala, and C#

Have you ever had to write code that made a complex series of succesive modifications to a single piece of mutable state? (Almost certainly yes.)

Did you ever wish you could make the compiler tell you if a particular operation on the state was illegal at a given point in the modifications? (If you're a fan of static typing, probably yes.)

If that's the case, the indexed state monad can help!

Motivation