Skip to content

Instantly share code, notes, and snippets.

View ream88's full-sized avatar

Mario Uher ream88

View GitHub Profile
@ream88
ream88 / curry.ex
Created August 17, 2019 11:54
Curried functions in Elixir
defmodule Curry do
defmacro curry([{name, arity}]) do
(arity - 1)
|> Range.new(0)
|> Enum.map(fn arity ->
arguments =
Range.new(0, arity)
|> Enum.filter(&(&1 > 0))
|> Enum.map(&"a#{&1}")
|> Enum.map(&String.to_atom/1)
@ream88
ream88 / sync_or_async.exs
Created August 31, 2018 09:55
GenStage sync and async
events = 1..5
defmodule SyncOrAsync do
use GenStage
def start_link(mode) when mode == :async or mode == :sync do
GenStage.start_link(__MODULE__, mode, name: __MODULE__)
end
# GenStage API
@ream88
ream88 / .gitignore
Last active August 6, 2017 21:51
Working Popup example
elm-stuff/
@ream88
ream88 / gist:4f4e07ddce88632ad73ea846d4a338d3
Created July 21, 2017 05:38
The most random UUID ever 😉
01234567-89ab-cdef-0123-456789abcdef
@ream88
ream88 / Child1.elm
Created July 20, 2017 19:45
Elm communication
module Child1 exposing (Msg(..), Model, init, update)
import WebData exposing (..)
type Msg
= Response (WebData (List String))
type alias Model =
@ream88
ream88 / ssl_puma.sh
Created October 10, 2016 13:59 — forked from tadast/ssl_puma.sh
localhost SSL with puma
# 1) Create your private key (any password will do, we remove it below)
$ cd ~/.ssh
$ openssl genrsa -des3 -out server.orig.key 2048
# 2) Remove the password
$ openssl rsa -in server.orig.key -out server.key
@ream88
ream88 / Component.js
Created August 14, 2016 11:14
Enhance React.Component.setState with logging
setState(...args) {
/* eslint-disable no-console */
console.trace();
console.group(this.constructor.name);
console.log("props", this.props);
console.log("state", this.state);
console.log("nextState", args[0]);
console.groupEnd(this.constructor.name);
/* eslint-enable no-console */
return Component.prototype.setState.apply(this, args);
@ream88
ream88 / hash-sort-by-key.rb
Last active June 6, 2016 09:59
Sort your .rubocop.yml
# http://dan.doezema.com/2012/04/recursively-sort-ruby-hash-by-key/
class Hash
def sort_by_key(recursive = false, &block)
self.keys.sort(&block).reduce({}) do |seed, key|
seed[key] = self[key]
if recursive && seed[key].is_a?(Hash)
seed[key] = seed[key].sort_by_key(true, &block)
end
seed
@ream88
ream88 / server.rb
Created March 10, 2016 08:23
Server which returns the request body
require 'webrick'
server = WEBrick::HTTPServer.new(Port: 8080)
server.mount_proc '/' do |req, res|
res.body = req.body
end
server.start
# Documentation: https://github.com/Homebrew/homebrew/blob/master/share/doc/homebrew/Formula-Cookbook.md
# http://www.rubydoc.info/github/Homebrew/homebrew/master/Formula
# PLEASE REMOVE ALL GENERATED COMMENTS BEFORE SUBMITTING YOUR PULL REQUEST!
class Dnstwist < Formula
desc ""
homepage ""
url "https://github.com/elceef/dnstwist/archive/v1.01.tar.gz"
version "1.01"
sha256 "6fae9f722ee711598fd23a93169a8539eaf2210410b75af22d9a4241d23da842"