Skip to content

Instantly share code, notes, and snippets.

View tmjoen's full-sized avatar
🔥

T. Mjoen tmjoen

🔥
  • Bielke&Yang
  • Oslo, Norway
View GitHub Profile
@fishcakez
fishcakez / event_watcher.ex
Created October 8, 2015 17:25
Simple example of the GenEvent watcher pattern to ensure handlers are re-added on crash
defmodule EventWatcher do
use Application
def start(_type, _args) do
import Supervisor.Spec, warn: false
children = [
worker(GenEvent, [[name: EventWatcher.GenEvent]], [id: :event_manager]),
supervisor(EventWatcher.Watcher.Supervisor, [], [id: :watcher_supervisor])
]
@JobLeonard
JobLeonard / merge.js
Last active September 26, 2017 22:30
A dumb merge function for updating simple state trees in redux
/**
* Returns a new object that merges the values of
* `newObj` into `oldObj`. Uses shallow copying.
*
* **WARNING: Do NOT pass cyclical objects!
* This includes React nodes!**
*
* **IMPORTANT:** util.merge does **NOT** behave like
* lodash merge! *TL;DR:* (typed) arrays are not merged
* but replaced by the newer array.
@justincarroll
justincarroll / bootstrap-masonry-template.htm
Last active August 15, 2020 16:48
This is my template for using Masonry 3 with Bootstrap 3. For those of you who follow this gist a lot has changed since Bootstrap 2.
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bootstrap Masonry Template</title>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=PT+Sans+Caption:400,700">
@pithyless
pithyless / gist:1547408
Created January 1, 2012 14:02
jQuery set Headers for $.ajax
// jQuery Headers support for $.ajax
$.ajax({
beforeSend: function(xhrObj){
xhrObj.setRequestHeader("Content-Type","application/json");
xhrObj.setRequestHeader("Accept","application/json");
}
type: "POST",
url: "/article",
processData: false,
@ruckus
ruckus / gist:2293434
Created April 3, 2012 16:36
Basic setup of WAL-E for continuous archiving and recovery

WAL-E needs to be installed on all machines, masters and slaves.

How to install WAL-E

Only one machine, the master, writes WAL segments via continuous archiving. The configuration for the master postgresql.conf is:

archive_mode = on
archive_command = 'envdir /etc/wal-e.d/env wal-e wal-push %p'
archive_timeout = 60
@essen
essen / http_specs.md
Last active January 10, 2022 02:01
HTTP and related specifications
@angelikatyborska
angelikatyborska / gettext_test.exs
Last active January 16, 2022 16:24
A unit test for Gettext translations that checks if the original and the translation use the same HTML tags. Uses Floki to parse HTML.
defmodule MyAppWeb.GettextTest do
use ExUnit.Case
import MyAppWeb.Gettext
# A unit test for Gettext translations that checks if the original and the translation
# use the same HTML tags.
#
# Uses Floki to parse HTML.
describe "translations" do

(a gist based on the old toolmantim article on setting up remote repos)

To collaborate in a distributed development process you’ll need to push code to remotely accessible repositories.

This is somewhat of a follow-up to the previous article setting up a new rails app with git.

For the impatient

Set up the new bare repo on the server:

@mmmries
mmmries / 01.README.md
Last active November 11, 2022 16:59
Load Test Phoenix Presence

Phoenix Nodes

First I created 3 droplets on digital ocean with 4-cores and 8GB of RAM. Login as root to each and run:

sysctl -w fs.file-max=12000500
sysctl -w fs.nr_open=20000500
ulimit -n 4000000
sysctl -w net.ipv4.tcp_mem='10000000 10000000 10000000'
@aaronjensen
aaronjensen / drain_stop.ex
Last active November 28, 2022 06:59
Phoenix Drain Stop
# ATTENTION: This is now supported in plug_cowboy as of 2.1.0:
# https://hexdocs.pm/plug_cowboy/Plug.Cowboy.Drainer.html
defmodule DrainStop do
@moduledoc """
DrainStop Attempts to gracefully shutdown an endpoint when a normal shutdown
occurs. It first shuts down the acceptor, ensuring that no new requests can be
made. It then waits for all pending requests to complete. If the timeout
expires before this happens, it stops waiting, allowing the supervision tree
to continue its shutdown order.