Skip to content

Instantly share code, notes, and snippets.

@jumanjiman
jumanjiman / get-rate-limit
Created September 28, 2022 15:26
GH ratelimit in both REST and GraphQL
#!/usr/bin/env bash
set -eEu
set -o pipefail
# Use env var to hide corporate namespace.
GITHUB_BASE_URL="${GITHUB_BASE_URL:-https://ghe.example.com}"
echo 'Get ratelimit with REST API v3'
curl \
-H 'Accept: application/vnd.github+json' \
@jumanjiman
jumanjiman / dumpsqlite3tocsv.py
Created October 8, 2019 16:54 — forked from garthk/dumpsqlite3tocsv.py
Unicode-safe Python script to dump sqlite3 tables to CSV for Trac data extraction
#!/usr/bin/env python
"""
Script to open a sqlite3 database and dump all user tables to CSV files.
Tested in Unicode-rich environment.
Usage:
dumpsqlite3tocsv foo.db
"""
import sqlite3, csv, codecs, cStringIO, os, os.path
@jumanjiman
jumanjiman / date_arithmetic
Created July 15, 2019 13:24
bash date arithmetic
#!/bin/bash
set -eEu
set -o pipefail
do_something() {
some_date=$1
echo "$some_date"
}
# https://stackoverflow.com/a/25701358
@jumanjiman
jumanjiman / Dockerfile
Created February 28, 2019 14:17
exim mail relay
FROM alpine:3.9
# docker build --rm -t relay --build-arg proxy=<something> .
ARG proxy
RUN http_proxy=${proxy} https_proxy=${proxy} \
apk --no-cache --available upgrade
RUN http_proxy=${proxy} https_proxy=${proxy} \
apk --no-cache add exim
@jumanjiman
jumanjiman / .mailmap
Created August 13, 2018 14:53
mailmap header comments
# This list is used by git-shortlog to fix botched name translations in the git archive,
# making contributions from the same person appear not to be so.
# Reasons include:
# - the author's full name was messed up and/or
# - not always written the same way
# - the author has multiple email addresses
#
# Note: NEVER REMOVE A MAILMAP ENTRY.
# These maps tie a commit author to a real human for accountability.
# If you remove a mailmap, then we lose the tie between author and human.
@jumanjiman
jumanjiman / .pre-commit-config.yaml
Created July 11, 2018 13:17
pre-commit hook to check mailmap
---
# Configure various overrides and exceptions in this file.
# See https://pre-commit.com/ for details.
fail_fast: false
repos:
- repo: local
hooks:
- id: check-mailmap
@jumanjiman
jumanjiman / Dockerfile
Created January 28, 2016 16:41
exim in a docker container
FROM alpine:3.3
RUN echo "http://dl-4.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories
RUN apk add --no-cache exim
COPY . /
RUN /usr/sbin/harden.sh
# Volumes must be created AFTER we harden.
@jumanjiman
jumanjiman / harden.sh
Last active February 1, 2024 14:27
hardening script for an alpine docker container
#!/bin/sh
# Copyright 2020 Paul Morgan
# License: GPLv2 (https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html)
set -x
set -e
#
# Docker build calls this script to harden the image during build.
#
# NOTE: To build on CircleCI, you must take care to keep the `find`
# command out of the /proc filesystem to avoid errors like:
@jumanjiman
jumanjiman / blah.rb
Last active August 29, 2015 14:05
meta
class Blah
def table
{
:dword => :read_dword,
:string => :read_string,
}
end
def read_string(a_key)
puts 'string'
@jumanjiman
jumanjiman / docker-limits.sh
Created May 25, 2014 13:21
memory limits in docker containers
#!/bin/bash
# Demonstrate memory resource limits in docker
# See also http://stackoverflow.com/a/20111960
function demo() {
mem=$1
echo "Run a container and limit to $mem"
cid=$(docker run -d -m $mem busybox /bin/sh -c "tail -f /var/log/*")