Skip to content

Instantly share code, notes, and snippets.

@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.
@pmarreck
pmarreck / id3parser.exs
Last active November 20, 2016 16:29
Code refactor suggestion to Benjamin Tan's Elixir ID3 parsing code from http://benjamintan.io/blog/2014/06/10/elixir-bit-syntax-and-id3/
defmodule ID3Parser do
@id3_tag_size 128
def parse(file_name, io_input \\ &File.read/1, io_output \\ &IO.puts/1) do
case io_input.(file_name) do
{:ok, binary} ->
{title, artist, album, year, comment} = parse_binary(binary)
io_output.(title)
@e-monson
e-monson / kmeans.exs
Created August 9, 2015 16:29
Implementing k-means in Elixir (unfinished)
defmodule Kmeans do
def test_points do
# This just outputs 100 random points for testing purposes
Stream.repeatedly(fn -> :random.uniform(100) end)
|> Stream.chunk(3)
|> Enum.take(100)
|> Enum.map(&List.to_tuple/1)
end
def point_range(list) when is_list(list) do
@napcs
napcs / JS Loading in web frameworks like Elixir
Last active January 20, 2020 04:05
Per-view JavaScript functions for Phoenix. Keeps things out of global space, allows a page to specifically invoke the JS it needs.
How to load page-specific JS functions and pass values to those functions when JS is loaded below your views.
@awohletz
awohletz / core.cljs
Created December 10, 2014 02:46
Om routing with Secretary
(ns om-routing.core
(:require-macros [secretary.core :refer [defroute]]
[cljs.core.async.macros :refer [go go-loop]])
(:require [om.core :as om :include-macros true]
[om-tools.core :refer-macros [defcomponent]]
[sablono.core :as h :refer-macros [html]]
[secretary.core :as secretary :include-macros true]
[goog.events :as events]
[goog.history.EventType :as EventType]
[cljs.core.async :refer [put! chan <! pub sub]])
@skyriverbend
skyriverbend / rails_switch_branch.py
Created November 15, 2012 05:54
Rails: Switch branches and run migrations
#!/usr/local/bin/python
"""
To use this script, you must be in the root directory of a Rails project that
is using git. You should also make sure that your directory does not contain any
uncommitted changes. Then run:
$ python rails_switch_branch.py name_of_another_branch
Running the above will do the following:
@marktheunissen
marktheunissen / pedantically_commented_playbook.yml
Last active April 26, 2024 23:26 — forked from phred/pedantically_commented_playbook.yml
Insanely complete Ansible playbook, showing off all the options
This playbook has been removed as it is now very outdated.