Skip to content

Instantly share code, notes, and snippets.

View tifletcher's full-sized avatar

Themba Fletcher tifletcher

  • CrunchBase
  • San Francisco, CA
View GitHub Profile
@tifletcher
tifletcher / wal_throughput.sql
Created October 10, 2024 21:54
Measures the throughput on the WAL over 5 seconds using postgres builtin stuff
DO $$
DECLARE
start_lsn pg_lsn;
end_lsn pg_lsn;
wal_bytes_diff numeric;
time_diff numeric;
bytes_per_second numeric;
start_time timestamp;
end_time timestamp;
BEGIN
@tifletcher
tifletcher / git-mergediff
Created June 10, 2019 21:58
git mergediff
#!/bin/bash
# preferences
# set DEBUG to "-v" or "" -- it will
# 1. activate shell tracing
# 2. be passed to curl as an argument
if [ -z "$DEBUG" ];
then
@tifletcher
tifletcher / postgres_queries_and_commands.sql
Created January 14, 2019 23:06 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@tifletcher
tifletcher / select_all.js
Created March 27, 2018 17:00
select all for google inbox
document.querySelectorAll('[role="checkbox"][aria-checked="false"]').forEach(x => x.click())
@tifletcher
tifletcher / hide_files.js
Last active February 13, 2018 19:55
Bookmarklet: Hide files by regex(pathname) during github code review.
(function(){
var hideIfMatches = (matcher) => (node) => {
if(node.querySelector(".file-header").getAttribute("data-path").match(matcher))
node.style.display = "none"
}
var fileNodes = document.querySelectorAll("#files .file")
var matcher = RegExp(prompt("Hide files when path matches regex:", "^reference.*"))
fileNodes.forEach(hideIfMatches(matcher))
})()
case class Foo (
fooInt: Int,
fooString: String
)
val theFoos = Seq(
Foo(0, "hello"),
Foo(1, "goodbye"),
Foo(2, "")
)
@tifletcher
tifletcher / ScopedSpec.scala
Created December 22, 2017 22:39
Using locally defined traits for per-test state setup with scalatest. Much NIH.
import org.scalatest.FunSpec
class ScopedSpec extends FunSpec {
trait SpecScope {
val x = 1
}
implicit val scopeConstructor = ScopeFactory(new SpecScope {})
@tifletcher
tifletcher / projections.sc
Created November 9, 2017 06:42
Arbitrary type projections as extension methods callable on the <From> type parameterized by the desired <To> type
import java.util.UUID
// given this machinery
trait Translator[-I, +O] {
def translate(i: I): O
}
object TypeProjector {
implicit class Translatable[T](i: T) {
def project[U](implicit translator: Translator[T, U]): U = translator.translate(i)
@tifletcher
tifletcher / FutureUtils.scala
Last active May 17, 2024 04:52
parallel and sequential futures
import scala.concurrent.Future
implicit val ec = scala.concurrent.ExecutionContext.global
def future(name: String): Future[String] = {
println(s"constructing $name")
Future {
Thread.sleep(1000)
println(s"resolved $name")
name
#!/bin/bash
#
# preferences
# set DEBUG to "-v" or "" -- it will
# 1. activate shell tracing
# 2. be passed to curl as an argument
if [ -z "$DEBUG" ];