Skip to content

Instantly share code, notes, and snippets.

View tamsky's full-sized avatar

Marc Tamsky tamsky

View GitHub Profile
@branneman
branneman / better-nodejs-require-paths.md
Last active June 24, 2025 22:40
Better local require() paths for Node.js

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

const Article = require('../../../../app/models/article');

Those suck for maintenance and they're ugly.

Possible solutions

; Pick up service x events, sent by error detection in service 'y' stream
(streams
(where (service "x")
;Index API service events for 60s we can watch for expiries info
(with :ttl 60 (update-index (index)))
(changed-state {:init "ok"}
(service-x-state-change-email "[email protected]"))
(expired (with :state "ok" reinject))))
@dergachev
dergachev / squid-deb-proxy_on_docker.md
Last active February 21, 2025 02:49
Caching debian package installation with docker

TLDR: I now add the following snippet to all my Dockerfiles:

# If host is running squid-deb-proxy on port 8000, populate /etc/apt/apt.conf.d/30proxy
# By default, squid-deb-proxy 403s unknown sources, so apt shouldn't proxy ppa.launchpad.net
RUN route -n | awk '/^0.0.0.0/ {print $2}' > /tmp/host_ip.txt
RUN echo "HEAD /" | nc `cat /tmp/host_ip.txt` 8000 | grep squid-deb-proxy \
  && (echo "Acquire::http::Proxy \"http://$(cat /tmp/host_ip.txt):8000\";" > /etc/apt/apt.conf.d/30proxy) \
  && (echo "Acquire::http::Proxy::ppa.launchpad.net DIRECT;" >> /etc/apt/apt.conf.d/30proxy) \
  || echo "No squid-deb-proxy detected on docker host"
@jjongsma
jjongsma / packer-config
Last active December 18, 2023 15:15
Process YAML and write Packer JSON to STDOUT
#!/usr/bin/python
#
# Usage: packer-config my-template.yaml | packer build -
#
# Constructs a Packer JSON configuration file from the specified YAML
# template file and writes it to STDOUT.
#
# The YAML template format adds some flexibility and readability by
# adding comments and an !include directive, allowing for the
# following template syntax:
@danrigsby
danrigsby / packer-ami-id
Last active December 14, 2023 15:07
Get AMI ID from a packer build
packer build packer.json 2>&1 | sudo tee output.txt
tail -2 output.txt | head -2 | awk 'match($0, /ami-.*/) { print substr($0, RSTART, RLENGTH) }' > sudo ami.txt
#!/bin/bash
set -eu
shopt -s nullglob
if [[ -n ${RUN:-} ]]; then
dry=
else
dry=echo
fi
@jmoiron
jmoiron / 01-curl.go
Last active October 19, 2024 11:28
io.Reader & io.Writer fun
package main
import (
"fmt"
"io"
"net/http"
"os"
)
func init() {
@ktheory
ktheory / dd.log
Last active November 10, 2023 23:41
EC2 EBS-SSD vs instance-store performance on an EBS-optimized m3.2xlarge
# /tmp/test = EBS-SSD
# /mnt/test = instance-store
root@ip-10-0-2-6:~# dd bs=1M count=256 if=/dev/zero of=/tmp/test
256+0 records in
256+0 records out
268435456 bytes (268 MB) copied, 3.26957 s, 82.1 MB/s
root@ip-10-0-2-6:~# dd bs=1M count=256 if=/dev/zero of=/tmp/test
256+0 records in
256+0 records out
svc host fault upgrade size power ip
42fzbcx2ev juju0nezlcysed3o... 0 0 Small Started 10.0.0.20
42fzbcx2ev juju9bd6mjna00h0... 0 4 Small Started 10.0.0.60
42fzbcx2ev juju9ygqoy9qjkdq... 1 1 Small Started 10.0.0.28
42fzbcx2ev jujufrh460g4vyra... 1 0 Small Started 10.0.0.68
42fzbcx2ev jujukhrocaqpux90... 1 3 Small Started 10.0.0.52
42fzbcx2ev jujuzbbtbkk8tdo6... 0 2 Small Started 10.0.0.44
47rntclyak jujugk2ygbnatkhc... 0 0 Small Started 10.0.0.4
51etwr329x juju6329s6bqqao2... 0 0 Small Started 10.0.0.12
51etwr329x jujuuxa3sfxyp12f... 1 1 Small Started 10.0.0.36
@earnubs
earnubs / vmware-ubuntu-workspace.md
Last active December 10, 2021 16:45
Ubuntu on VMware with LXD containers