Skip to content

Instantly share code, notes, and snippets.

@seriyps
seriyps / epgsql_cmd_eequery.erl
Last active November 1, 2021 18:58
Single - roundtrip version of epgsql:equery
%% Single-roundtrip version of epgsql:equery/3
%%
%% It does parse-bind-execute sequence in 1 network roundtrip.
%% The cost is that user should manually provide the datatype information for
%% each bind-parameter.
%% Another potential problem is that connection will crash if epgsql does not
%% have a codec for any of result columns. Explicit type casting may save you
%% in this case: `SELECT my_enum::text FROM my_tab'. Or you can implement the
%% codec you need.
%%
iex(14)> defmodule T do
...(14)> def f(fun, arg), do: apply(String, :"#{fun}", [arg])
...(14)> end |> elem(2) |> :beam_lib.chunks([:abstract_code]) |> elem(1) |> elem(1) |> get_in([:abstract_code]) |> elem(1) |> :erl_syntax.form_list |> :erl_prettypr.format |> IO.puts
warning: redefining module T (current version defined in memory)
iex:14
-file("iex", 14).
-module('Elixir.T').
@jessfraz
jessfraz / boxstarter.ps1
Last active July 7, 2024 22:46
Boxstarter Commands for a new Windows box.
# Description: Boxstarter Script
# Author: Jess Frazelle <jess@linux.com>
# Last Updated: 2017-09-11
#
# Install boxstarter:
# . { iwr -useb http://boxstarter.org/bootstrapper.ps1 } | iex; get-boxstarter -Force
#
# You might need to set: Set-ExecutionPolicy RemoteSigned
#
# Run this boxstarter by calling the following from an **elevated** command-prompt:
Originally from: http://erlang.org/pipermail/erlang-questions/2017-August/093170.html
For a safe and fast Erlang SSL server, there's a few
configuration values you might want by default:
[{ciphers, CipherList}, % see below
{honor_cipher_order, true}, % pick the server-defined order of ciphers
{secure_renegotiate, true}, % prevent renegotiation hijacks
{client_renegotiation, false}, % prevent clients DoSing w/ renegs
{versions, ['tlsv1.2', 'tlsv1.1']}, % add tlsv1 if you must
ifeq ($(STAGE),initial)
.PHONY: everything
everything:
$(MAKE) STAGE=bootstrap bootstrap $(MAKECMDFLAGS)
$(MAKE) STAGE=execute bootstrap $(MAKECMDFLAGS)
$(MAKE) STAGE=execute $(MAKECMDGOALS) $(MAKECMDFLAGS)
$(MAKECMDGOALS): everything
SIGNATURE__API = $(shell find api -type f -name "*.yaml" | sort | bin/sign | bin/update-if-different $(SIGNATURE_DIRECTORY)/api)
$(MAKE_DIRECTORY)/api: $(SIGNATURE__API) bin/dsl-api
bin/dsl-api -strict -root api/gen.a.root.yaml
@touch $@
api: $(MAKE_DIRECTORY)/api
################################################################################
@efrecon
efrecon / run.tpl
Last active July 26, 2024 07:48
`docker inspect` template to regenerate the `docker run` command that created a container
docker run \
--name {{printf "%q" .Name}} \
{{- with .HostConfig}}
{{- if .Privileged}}
--privileged \
{{- end}}
{{- if .AutoRemove}}
--rm \
{{- end}}
{{- if .Runtime}}
defmodule StructDefaults do
defmacro __using__(opts) do
name = case opts[:name] do
nil -> __CALLER__.module |> Module.split() |> List.last()
b when is_binary(b) -> b
end
mod = __CALLER__.module
quote location: :keep do
require StructDefaults
#unbind C-b
#set -g prefix C-a
set -g base-index 1
set -g default-terminal "screen-256color"
set -g terminal-overrides "xterm*:kLFT5=\eOD:kRIT5=\eOC:kUP5=\eOA:kDN5=\eOB:smkx@:rmkx@:smcup@:rmcup@"
setw -g xterm-keys on
#setw -g mode-mouse on
#setw -g alternate-screen on
(def ^:dynamic *indent* 0)
(alter-var-root
#'clojure.core/load
(fn [orig]
(fn [& paths]
(let [t (System/nanoTime)
r (binding [*indent* (inc *indent*)]
(apply orig paths))]
(binding [*out* *err*]
(println (apply str (repeat *indent* " ")) (/ (- (System/nanoTime) t) 1000000.0) paths)