Skip to content

Instantly share code, notes, and snippets.

View mindreframer's full-sized avatar
🎯
Focusing

Roman Heinrich mindreframer

🎯
Focusing
View GitHub Profile
@mindreframer
mindreframer / dyanmic_or_di_elixir.md
Created September 5, 2016 16:45 — forked from timruffles/dyanmic_or_di_elixir.md
Approaches to dependency-injection/dynamic dispatch in elixir

In many production systems you'll want to have one module capable of talking to many potential implementations of a collaborator module (e.g a in memory cache, a redis-based cache etc). While testing it's useful to control which module the module under test is talking to.

Here are the approaches I can see. The two points that seem to divide the approaches are their tool-ability (dialyzer) and their ability to handle stateful implementations (which need a pid).

Passing modules

Modules are first class, so you can pass them in. Used in EEx, where passed module must implement a behaviour.

@mindreframer
mindreframer / my_app.ex
Created August 29, 2016 15:46 — forked from alanpeabody/my_app.ex
Websockets in Elixir with Cowboy and Plug
defmodule MyApp do
use Application
def start(_type, _args) do
import Supervisor.Spec, warn: false
children = [
Plug.Adapters.Cowboy.child_spec(:http, MyApp.Router, [], [
dispatch: dispatch
])
@mindreframer
mindreframer / stage_inspector.ex
Created August 18, 2016 07:06 — forked from rob-brown/stage_inspector.ex
Inspect the data passed between GenStages.
defmodule StageInspector do
alias Experimental.{GenStage}
use GenStage
def init(type) when type in [:consumer, :producer_consumer] do
{type, type}
end
def handle_events(events, _from, state = :consumer) do
Enum.each events, &inspect_event/1
@mindreframer
mindreframer / infra-secret-management-overview.md
Created May 16, 2016 16:29 — forked from maxvt/infra-secret-management-overview.md
Infrastructure Secret Management Software Overview

Currently, there is an explosion of tools that aim to manage secrets for automated, cloud native infrastructure management. Daniel Somerfield did some work classifying the various approaches, but (as far as I know) no one has made a recent effort to summarize the various tools.

This is an attempt to give a quick overview of what can be found out there. The list is alphabetical. There will be tools that are missing, and some of the facts might be wrong--I welcome your corrections. For the purpose, I can be reached via @maxvt on Twitter, or just leave me a comment here.

There is a companion feature matrix of various tools. Comments are welcome in the same manner.

@mindreframer
mindreframer / duration.ex
Created April 3, 2016 08:40 — forked from rcdilorenzo/duration.ex
A simple construction of a duration time (e.g. "01:30" or "01:30:23") as a custom ecto type
defmodule Duration do
@moduledoc """
This duration module parses and formats strings
for a time duration in hours and minutes and
optionally seconds (e.g. 01:00 for an hour,
00:01:10 for one minute and ten seconds).
"""
@match ~r/^(?<hour>\d{1,2}):(?<min>\d{1,2}):?(?<sec>\d{0,2})$/
def parse(string) do
@mindreframer
mindreframer / benchmark.rb
Last active August 29, 2015 14:19
proc vs. direct method call
require 'benchmark'
require 'json'
HASH = {'a'=>1, 'b'=>[1,2,3]}
class Roda
class << self
attr_accessor :opts
end
end
@mindreframer
mindreframer / create_files.rb
Created April 3, 2015 12:35
Benchmark Static Site Generators
#!/usr/bin/env ruby -wKU
require 'yaml'
class Generator
def run
300.times do |i|
File.open(name(i), 'w') do |f|
f.puts Article.new.content
end
end
@mindreframer
mindreframer / give_index.rb
Created November 30, 2014 21:42
give files index based on order in a table of content file
# quick script to give files an index calculated from a table of contents file
class Renamer
COMMON_STRING = 'Series Name by Author Name'
def run
actual.content.each do |file|
clean_file = file.gsub(COMMON_STRING, '')
to = wished.wished_file_for_file(clean_file)
cmd = "mv '#{file}' #{to}"
puts cmd
`#{cmd}`
@mindreframer
mindreframer / slack.rake
Last active August 29, 2015 14:06
slack + capistrano
# lib/capistrano/tasks/slack.rake
# install slack-notifier gem
# include this file into your lib/capistrano/tasks/ folder
# add this line to the end of your Capfile:
# Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
# deploy with:
# MSG='fixing that payment bug...' cap staging deploy
class SlackNotifierWrapper
http://ulozto.net/xnvgH92b/skype-6-6-0-106-by-salwoh-exe