Skip to content

Instantly share code, notes, and snippets.

View KamilLelonek's full-sized avatar
🏋️‍♂️
Do you even lift?

Kamil Lelonek KamilLelonek

🏋️‍♂️
Do you even lift?
View GitHub Profile
@jswny
jswny / Flexible Dockerized Phoenix Deployments.md
Last active July 3, 2023 05:25
A guide to building and running zero-dependency Phoenix (Elixir) deployments with Docker. Works with Phoenix 1.2 and 1.3.

Prelude

I. Preface and Motivation

This guide was written because I don't particularly enjoy deploying Phoenix (or Elixir for that matter) applications. It's not easy. Primarily, I don't have a lot of money to spend on a nice, fancy VPS so compiling my Phoenix apps on my VPS often isn't an option. For that, we have Distillery releases. However, that requires me to either have a separate server for staging to use as a build server, or to keep a particular version of Erlang installed on my VPS, neither of which sound like great options to me and they all have the possibilities of version mismatches with ERTS. In addition to all this, theres a whole lot of configuration which needs to be done to setup a Phoenix app for deployment, and it's hard to remember.

For that reason, I wanted to use Docker so that all of my deployments would be automated and reproducable. In addition, Docker would allow me to have reproducable builds for my releases. I could build my releases on any machine that I wanted in a contai

@bithavoc
bithavoc / postgres-notify-trigger.sql
Last active February 2, 2019 09:31
I used this trigger to notify table changes via NOTIFY (migrating off RethinkDB)
CREATE OR REPLACE FUNCTION notify_trigger() RETURNS trigger AS $$
DECLARE
channel_name varchar DEFAULT (TG_TABLE_NAME || '_changes');
BEGIN
IF TG_OP = 'INSERT' THEN
PERFORM pg_notify(channel_name, '{"id": "' || NEW.id || '"}');
RETURN NEW;
END IF;
IF TG_OP = 'DELETE' THEN
PERFORM pg_notify(channel_name, '{"id": "' || OLD.id || '"}');
@josteink
josteink / on_stateful_code.txt
Last active October 21, 2020 05:37
On why stateful code is bad
On why stateful code is bad
===========================
STUDENT: Sir, can I ask a question?
TEACHER: Yes!
STUDENT: How do you put an elephant inside a fridge?
TEACHER: I don't know.
STUDENT: It's easy, you just open the fridge and put it in. I have another question!
TEACHER: Ok, ask.
STUDENT: How to put a donkey inside the fridge?
# Expectations:
#
# * application code in /srv/myapp/current
# * ruby runtime in /srv/myapp/.rubies/ruby-2.3.0
# * unicorn.rb config specifies pid file location to /srv/myapp/current/unicorn.pid and working directory to /srv/myapp/current
[Unit]
Description=Sample unicorn app
[Service]
@mlomnicki
mlomnicki / json_ostruct.rb
Created January 28, 2016 14:50
JSON + OpenStruct
require 'json'
require 'ostruct'
data = '{"a": {"b": 1}}'
result = JSON.parse(data, object_class: OpenStruct)
result.a.b # => 1
<?
/////////////////////
// slack2html
// by @levelsio
/////////////////////
//
/////////////////////
// WHAT DOES THIS DO?
/////////////////////
//
#!/usr/bin/env elixir
defmodule Committer do
defstruct [:name, :email]
def list(repo) do
repo
|> from_repo
|> Stream.unfold(fn str ->
case String.split(str, "\n", parts: 2, trim: true) do
@domgetter
domgetter / hash_compose.rb
Last active August 29, 2015 14:23
Hash#compose
# Since a key-value store is a finite, discrete function, and functions
# can be composed, then Hashes can be composed.
#
# The syntactic sugar for calling lambdas, accessing array values, and
# other objects which have a #[] method allow composition of Hashes
# with all sorts of objects and contexts with the same implementation.
#
# Play with it at https://eval.in/388458
#
class Hash
/* VT100 terminal reset (<ESC>c) */
console.log('\033c');
/* numbers comparations */
> '2' == 2
true
> '2' === 2