Skip to content

Instantly share code, notes, and snippets.

View hackervera's full-sized avatar
😻

Veronika Tyler hackervera

😻
View GitHub Profile
@moxley
moxley / strip_ecto_record.exs
Created March 31, 2016 23:32
Strip an Ecto record of attributes that cannot be encoded to JSON
record = Enum.reduce(Map.keys(record), %{}, fn (key, map) ->
value = Map.get(record, key)
key_to_add = cond do
is_map(value) && Map.get(value, :__struct__, nil) == Elixir.Ecto.Association.NotLoaded ->
nil
key == :__meta__ ->
nil
key == :__struct__ ->
nil
@theoretick
theoretick / fml.sh
Last active August 16, 2018 17:17
just fix it, bash
#!/bin bash
function dammit_bundler() {
bundle clean
bundle install
}
function dammit_npm() {
rm -fr ./node_modules/
npm cache clean -f

My Elixir Deployment Wishlist

Foreward

Based on my recent experience of deployment, I've become rather frustrated with the deployment tooling in Elixir. This document is the result of me thinking to myself, "I wish we had x...". This document isn't meant to dishearten anyone who has built tooling for elixir - thank you so much for what you've done. This is meant more as what I personally see as something that would help a lot of Erlang/Elixir newbies like myself to be able to get deploying quickly and efficiently.

1. Release files should be templates

It should be possible to add in custom configuration to the bootstrap scripts. This would allow plugins to be able to add extra steps to the startup / shutdown / upgrade procedure. One way to implement this would be to make all scripts which handle bootstrapping or controlling the machine [.eex][1] templates. This would allow other parts of the release system to inject new functionality where needed.

@theoretick
theoretick / upgrade_postgresql_9.3_to_9.4.sh
Last active March 2, 2016 19:03
shell script for upgrading postgres 9.3 to 9.4 with postGIS. RUN AS ROOT
#! /bin/bash
#
# Based on http://www.gab.lc/articles/migration_postgresql_9-3_to_9-4
#
# Make sure only root can run our script
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root" 1>&2
exit 1
fi
@henrik
henrik / regex_case.exs
Last active September 21, 2022 03:06
Proof-of-concept of an Elixir construct like `case` but that matches strings against regexps. #elixirlang
defmodule RegexCase do
defmacro regex_case(string, do: lines) do
new_lines = Enum.map lines, fn ({:->, context, [[regex], result]}) ->
condition = quote do: String.match?(unquote(string), unquote(regex))
{:->, context, [[condition], result]}
end
# Base case if nothing matches; "cond" complains otherwise.
base_case = quote do: (true -> nil)
new_lines = new_lines ++ base_case
@moxley
moxley / shell_command.rb
Last active December 25, 2016 16:58
Runs shell command with similar IO stream behavior as a shell script: Stdout and stderr of command are captured and piped to caller's stdout and stderr.
require "open4"
require 'stringio'
class ShellCommand
class CommandError < StandardError
attr_reader :stderr_string
def initialize(message, stderr_string)
super(message)
@stderr_string = stderr_string
@pincheira
pincheira / homebrew.rb
Last active July 1, 2016 17:07
Working version of Homebrew for OS X 10.10

Working version of Homebrew for OS X 10.10

The only way to get working Homebrew on OS X 10.10 for now (10.10 beta was just released a couple of hours ago) is by using an special fork by @jacknagel available at https://github.com/jacknagel/homebrew/tree/rb2.

To install this working version of Homebrew just execute:

ruby -e "$(curl -fsSL https://gist.githubusercontent.com/jpincheira/bd3698fee46735fac252/raw/2c6a2f81927871c1a64e2dfbbc5eef451c71a9ac/homebrew.rb)"

@akorobov
akorobov / ipv6-httpd.py
Created December 11, 2013 00:58
quick ipv6 http server using python's SimpleHttpServer
import socket
from BaseHTTPServer import HTTPServer
from SimpleHTTPServer import SimpleHTTPRequestHandler
class MyHandler(SimpleHTTPRequestHandler):
def do_GET(self):
if self.path == '/ip':
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()
@samn
samn / media_dog.clj
Last active October 16, 2019 22:11
Using the Twitter API with Clojure
(ns media-dog
(:require [twitter.oauth :as oauth]
[twitter.callbacks.handlers :as handlers]
[twitter.api.streaming :as streaming]
[cheshire.core :as json])
(:import (twitter.callbacks.protocols AsyncStreamingCallback)))
(def creds (oauth/make-oauth-creds
; consumer key
"CDdirssorFxBYmWWQmM1xw"
(ns async-test.timeout.core
(:require [cljs.core.async :refer [chan close!]])
(:require-macros
[cljs.core.async.macros :as m :refer [go]]))
(defn timeout [ms]
(let [c (chan)]
(js/setTimeout (fn [] (close! c)) ms)
c))