Skip to content

Instantly share code, notes, and snippets.

View devth's full-sized avatar
Hacking on @yetibot

Trevor Hartman devth

Hacking on @yetibot
View GitHub Profile
@pgporada
pgporada / Makefile
Last active August 16, 2022 08:33
Terraform Makefile
.ONESHELL:
.PHONEY: help set-env init update plan plan-destroy show graph apply output taint
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
set-env:
@if [ -z $(ENVIRONMENT) ]; then\
echo "ENVIRONMENT was not set"; exit 10;\
fi
@noisesmith
noisesmith / gist:e6a3e0ae424e129ece19
Created January 28, 2016 22:22
handling signals in clojure
kingfisher.core=> (def hndlr (reify sun.misc.SignalHandler (handle [this signal](println "handling some sig!"))))
#'kingfisher.core/hndlr
kingfisher.core=> (sun.misc.Signal/handle (sun.misc.Signal. "USR2") hndlr)
#object[kingfisher.core$reify__32853 0x6bc27f36 "kingfisher.core$reify__32853@6bc27f36"]
kingfisher.core=> (clojure.java.shell/sh "kill" "-s" "SIGUSR2" "72011")
handling some sig!
{:exit 0, :out "", :err ""}
#!/bin/sh
PROJECT=thockin-dev
ZONE=us-central1-b
K8S_MIG=kubernetes-minion-group
# Assume I have 2 kubernetes services running, svc1 and svc1. Both are type
# NodePort with ports defined below. I want to expose them as hostnames
# defined below.
SVC1_NODE_PORT=30001
@runarorama
runarorama / gist:5af95832695e02426d32
Created May 4, 2015 20:51
Superstitious parent mode
import java.util.concurrent._
/**
* A thread pool for superstitious parent threads who
* know they shouldn't let their child threads back in the pool after
* eating, without waiting at least `crampFactor` milliseconds.
*/
object Superstitious {
def pool(crampFactor: Long) = new ThreadPoolExecutor(
0, Int.MaxValue, 60L, TimeUnit.SECONDS, new SynchronousQueue[Runnable]) {
@phrawzty
phrawzty / extant_infra_terraform.md
Last active June 16, 2017 00:40
Dealing with extant AWS resources in Terraform

What it is

Problem: Terraform doesn't play nicely with pre-existing infrastructure.

Solution: Officially there isn't one - but here's a work-around that does the trick.

Summary

  • Declare a new, temporary resource in your Terraform plan that is nearly identical to the extant resource.
  • Apply the plan, thus instantiating the temporary "twinned" resource and building a state file.
@favila
favila / datomic-mysql-bootstrap.sql
Created January 22, 2015 17:49
Better MySQL bootstrap setup for datomic's datomic_kvs table
-- Optimized MYSQL schema for datomic
-- Unfortunately the bin/sql/mysql-*.sql bootstrapping files for datomic are not
-- very good, and can actually cause failures if not adjusted.
-- One symptom of this is the following error:
-- SQL Error (1071): Specified key was too long; max key length is 767 bytes.
-- Reported here: https://support.cognitect.com/entries/28462168-MySQL-Caveats
-- This is caused by the default collation for the `id` column possibly being
@sjl
sjl / ext.vim
Created December 15, 2014 18:58
ways to run external commands in vim
" run command
" no stdin
" output displayed in "Press enter to continue" style
" current buffer untouched
:!uptime
" run command
" pipe range of text to command on stdin
" output replaces the range in the current buffer
:RANGE!grep foo

A Quick and Dirty Lens primer

Why does Lens exist? Well, Haskell records suck, for a number of reasons. I will enumerate them using this sample record.

data User = User { login    :: Text
                 , password :: ByteString
                 , email    :: Text
                 , created  :: UTCTime
 }
FIELDS = ['cmd', 'command', 'start', 'end', 'delta', 'msg', 'stdout', 'stderr']
def human_log(res):
if type(res) == type(dict()):
for field in FIELDS:
if field in res.keys():
encoded_field = res[field].encode('utf-8')
print '\n{0}:\n{1}'.format(field, encoded_field)
@kyledrake
kyledrake / ferengi-plan.txt
Last active April 6, 2024 00:30
How to throttle the FCC to dial up modem speeds on your website using Nginx
# The blog post that started it all: https://neocities.org/blog/the-fcc-is-now-rate-limited
#
# Current known FCC address ranges:
# https://news.ycombinator.com/item?id=7716915
#
# Confirm/locate FCC IP ranges with this: http://whois.arin.net/rest/net/NET-165-135-0-0-1/pft
#
# In your nginx.conf:
location / {