Skip to content

Instantly share code, notes, and snippets.

@cghiban
cghiban / make-load.sh
Created March 12, 2021 16:11 — forked from xaprb/make-load.sh
A little shell script for hammering the dvdstore database on Postgres
#!/usr/bin/env bash
if [ -z "$1" ]; then
echo "Usage: $0 <iterations>"
exit 1
fi
# Display product ID, category, title, price, num orders
# ordered by top products limit 10
function top_products(){
@cghiban
cghiban / create_triggers
Created March 12, 2021 15:39 — forked from colophonemes/create_triggers
Postgres TRIGGER to call NOTIFY with a JSON payload
CREATE TRIGGER person_notify AFTER INSERT OR UPDATE OR DELETE ON income
FOR EACH ROW EXECUTE PROCEDURE notify_trigger(
'id',
'email',
'username'
);
CREATE TRIGGER income_notify AFTER INSERT OR UPDATE OR DELETE ON income
FOR EACH ROW EXECUTE PROCEDURE notify_trigger(
'id',
@cghiban
cghiban / golang_job_queue.md
Created November 24, 2020 20:05 — forked from harlow/golang_job_queue.md
Job queues in Golang
@cghiban
cghiban / _tree
Created November 23, 2020 21:17 — forked from alexedwards/_tree
Dependency injection via closure (handlers in multiple packages)
.
├── go.mod
├── handlers
│ ├── books
│ │ └── books.go
│ └── env.go
├── main.go
└── models
└── models.go
@cghiban
cghiban / _tree
Created November 23, 2020 21:11 — forked from alexedwards/_tree
Config package with global variable
.
├── config
│ └── config.go
├── go.mod
├── go.sum
├── main.go
└── models
└── books
└── books.go
@cghiban
cghiban / home-server.md
Created October 26, 2020 18:59 — forked from nileshtrivedi/home-server.md
Home Server setup: Raspberry PI on Internet via reverse SSH tunnel

Raspberry Pi on Internet via reverse SSH tunnel

HackerNews discussed this with many alternative solutions: https://news.ycombinator.com/item?id=24893615

I already have my own domain name: mydomain.com. I wanted to be able to run some webapps on my Raspberry Pi 4B running perpetually at home in headless mode (just needs 5W power and wireless internet). I wanted to be able to access these apps from public Internet. Dynamic DNS wasn't an option because my ISP blocks all incoming traffic. ngrok would work but the free plan is too restrictive.

I bought a cheap 2GB RAM, 20GB disk VM + a 25GB volume on Hetzner for about 4 EUR/month. Hetzner gave me a static IP for it. I haven't purchased a floating IP yet.

@cghiban
cghiban / pre-commit
Created May 2, 2018 14:24 — forked from hraban/pre-commit.md
Git pre-commit hook (.git/hooks/pre-commit) to prevent accidentally committing debug code (add NOCOMMIT in source comment)
#!/bin/sh
# This pre-commit hook will prevent you from committing any line (or filename) containing
# the string NOCOMMIT. Use that tag in comments around source code you want to avoid
# accidentally committing, like temporary IP addresses or debug printfs.
#
# To add it to an existing repository, save it to .git/hooks/pre-commit (or append, if
# that file already exists). Remember to make executable (chmod +x ...)
#
# To automatically add this pre-commit hook to every repository you create or clone:
@cghiban
cghiban / git-workflow.md
Created September 8, 2017 19:46
A basic git workflow for centralized repositories.

Basic Workflow

Description

Different uses of git will have a different optimal workflow. This document describes a git workflow with the following characteristics:

  • It is a centralized workflow, meaning multiple developers all push to a shared repository. (As opposed to a fork-and-pull-request Github-style workflow.)
  • It is safe to use when collaborating on a feature branch with others, but requires no workflow changes when working alone. (So there's only one set of steps to remember.)
  • Some git users rely heavily on rebases, using them for any and all conflicts. This is an unhealthy coping mechanism born of past git merge trauma. This workflow relies heavily on merges, using rebase only when it is safe to do so (with commits that have yet to be pushed).
  • push --force is never needed (and may be disallowed by the remote repository.)
@cghiban
cghiban / introrx.md
Created April 18, 2017 14:28 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing
#!/usr/bin/env bash
perl_version='5.25.6'
perl_version='5.24.0'
verify_pkg() {
pkg="$1"
[[ $(which "${pkg}") ]] || {
echo "${pkg} not found. Exiting..."
exit 1