Skip to content

Instantly share code, notes, and snippets.

View Gazler's full-sized avatar

Gary Rennie Gazler

View GitHub Profile
@jboner
jboner / latency.txt
Last active May 2, 2024 09:45
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@jedsundwall
jedsundwall / measured-voice-terms-of-service.md
Last active December 18, 2015 18:29
This gist contains Measured Voice's government-friendly terms of service, which you can see at http://measuredvoice.com/terms. Measured Voice owns the copyright to these terms, but you are free to copy them for your own use under a the Creative Commons Attribution-ShareAlike 3.0 license (http://creativecommons.org/licenses/by-sa/3.0/). We want t…

Measured Voice Terms of Service

Amended on 25 January, 2013

1. Your Acceptance of Terms

1.1 Your use of Measured Voice and the Measured Voice web site (collectively referred to as the “Service”), is subject to the terms of a legal agreement (“Terms”) between you and Captura Group Inc., DBA Measured Voice (“Measured Voice”). The following Terms of Services ("TOS") explains the agreement and the terms of that agreement.

1.2 In order to use the Service, you must first agree to the Terms. You may not use the Service if you do not accept the Terms. You can accept the Terms by (a) actually using the Service, or (b) clicking a box where such box is made available to you. If you do not agree to any of the following Terms, please do not use the Service. You should print or otherwise save a copy of these TOS for your records.

@ottomata
ottomata / kafka-mirror
Created August 12, 2013 21:15
init.d script for Kafka MirrorMaker
#!/bin/sh
#
# /etc/init.d/kafka -- startup script for the kafka distributed publish-subscribe messaging system
#
# Written by Alexandros Kosiaris <akosiaris@wikimedia.org>
#
### BEGIN INIT INFO
# Provides: kafka
# Required-Start: $local_fs $remote_fs $network
# Required-Stop: $local_fs $remote_fs $network
@staltz
staltz / introrx.md
Last active May 2, 2024 12:31
The introduction to Reactive Programming you've been missing
@pnc
pnc / observer.md
Last active September 9, 2023 23:32
Using Erlang observer/appmon remotely

Using OTP's observer (appmon replacement) remotely

$ ssh remote-host "epmd -names"
epmd: up and running on port 4369 with data:
name some_node at port 58769

Note the running on port for epmd itself and the port of the node you're interested in debugging. Reconnect to the remote host with these ports forwarded:

$ ssh -L 4369:localhost:4369 -L 58769:localhost:58769 remote-host
@potatosalad
potatosalad / jws-payload-example.ex
Created September 22, 2015 15:53
Example of extracting the payload from a JWS signature
jwk_map = %{ "kty" => "oct", "k" => :base64url.encode("secret")}
jws_map = %{ "alg" => "HS256" }
jwt_map = %{ "test" => true }
signature = JOSE.JWT.sign(jwk_map, jws_map, jwt_map)
signature_compacted = JOSE.JWS.compact(signature)
{_, signature_map} = JOSE.JWS.expand(signature_compacted)
payload = JOSE.JWT.from(:base64url.decode(Map.get(signature_map, "payload")))
# one-liner version:
def update_company(company, company_params) do
changeset = Company.changeset(company, company_params)
if Ecto.Changeset.fetch_change(changeset, :shortname) != :error do
Logger.debug "Shortname changed"
#TODO dont allow shortname change if shortname is in use in video addresses
:ok
end
Repo.transaction( fn ->
case Repo.update(changeset) do
@henrik
henrik / say_when.exs
Last active September 7, 2016 09:03
Example of using "guard clauses" in your own code with Elixir macros. Inspired by `plug :foo when action in [:create, :update]`. This implementation accepts any types of conditions, not just the subset allowed in actual guard clauses. But also see https://gist.github.com/henrik/68f136f9916165e0defb for an implementation with real guard clauses.
defmodule Lab do
defmacro say({:when, _, [message, condition]}) do
{result, _} = Code.eval_quoted(condition)
if result do
quote do
IO.puts unquote(message)
end
end
end
@aaronjensen
aaronjensen / drain_stop.ex
Last active November 28, 2022 06:59
Phoenix Drain Stop
# ATTENTION: This is now supported in plug_cowboy as of 2.1.0:
# https://hexdocs.pm/plug_cowboy/Plug.Cowboy.Drainer.html
defmodule DrainStop do
@moduledoc """
DrainStop Attempts to gracefully shutdown an endpoint when a normal shutdown
occurs. It first shuts down the acceptor, ensuring that no new requests can be
made. It then waits for all pending requests to complete. If the timeout
expires before this happens, it stops waiting, allowing the supervision tree
to continue its shutdown order.
@andreicristianpetcu
andreicristianpetcu / ansible-summary.md
Created May 30, 2016 19:25
This is an ANSIBLE Cheat Sheet from Jon Warbrick

An Ansible summary

Jon Warbrick, July 2014, V3.2 (for Ansible 1.7)

Configuration file

intro_configuration.html

First one found from of