Skip to content

Instantly share code, notes, and snippets.

@dspinellis
dspinellis / Makefile
Last active March 5, 2022 14:16
Add a help target for any Makefile
URL=https://www.spinellis.gr/unix
love: # Help: Create a file name love
touch love
money: # Help: Hit the jackpot
yes $$ | fmt | head
me a wizard: MOOC # Help: Become a Unix command-line wizard
@kpirliyev
kpirliyev / postgresql_13_replication.md
Last active March 1, 2024 11:07
PostgreSQL 13 Master-Slave Streaming Replication

PostgreSQL 13 Master-Standby Streaming Replication

PostgreSQL has various types of replication available and it could be a little bit confusing to figure out what has to be done to just configure a simple master-standby replicated database setup. Digging my way through documentation I decided to write my own little guide on how to setup simple replication in PostgreSQL 13.

How it works

Streaming replication works by streaming the contents of WAL (Write-Ahead Logging) file from one server to another. Each transaction is first written into the WAL file, so essentially every change on the primary server will be replicated on the standby server. Standby server could be used for read-only operations, but can't be written to. Ofcourse, transferring data over the network takes time and there is a small lag before data written to one server becomes available on the other. To guarrantee data consistency on both servers at the time of read operation we can enable synchronous replication mode. This way, datab

@mahemoff
mahemoff / README.md
Last active April 6, 2024 00:38
Vim Terminal Mode - A short introduction

Vim has a Terminal Mode!

Since v8.1 (May 2018), Vim has shipped with a built-in terminal. See https://vimhelp.org/terminal.txt.html or type :help terminal for more info.

Why use this? Mainly because it saves you jumping to a separate terminal window. You can also use Vim commands to manipulate a shell session and easily transfer clipboard content between the terminal and files you're working on.

Key Bindings

@narrowtux
narrowtux / model.ex
Last active February 16, 2023 08:39
Recursive models with ecto
defmodule Model do
schema "models" do
field :foo, :string
has_many :children, Model, foreign_key: :parent_id
belongs_to :parent, Model, foreign_key: :parent_id
end
@doc """
Recursively loads parents into the given struct until it hits nil
"""
# Corey's challenge is to make the second test pass without ever making the first test fail.
# run ruby stack.rb to run the tests
# For more information see http://tooky.co.uk/kickstart-academy-podcast-with-corey-haines-and-sandi-metz/
class Stack
def empty?
true
end
def push(element)
@empty = false
@lelandbatey
lelandbatey / whiteboardCleaner.md
Last active April 25, 2024 02:01
Whiteboard Picture Cleaner - Shell one-liner/script to clean up and beautify photos of whiteboards!

Description

This simple script will take a picture of a whiteboard and use parts of the ImageMagick library with sane defaults to clean it up tremendously.

The script is here:

#!/bin/bash
convert "$1" -morphology Convolve DoG:15,100,0 -negate -normalize -blur 0x1 -channel RBG -level 60%,91%,0.1 "$2"

Results

@Odaeus
Odaeus / application_controller.rb
Last active June 15, 2021 09:34
Alternative to Rails' sharing of instance variables between controller and views.
class ApplicationController < ActionController::Base
# Creates an accessor which is exposed to the view
def self.view_accessor(*names)
attr_accessor *names
helper_method *names
end
end
@aslakhellesoy
aslakhellesoy / gfm.sh
Last active November 23, 2016 09:57
Compile and show GFM docs in your browser.https://help.github.com/articles/github-flavored-markdown
#!/bin/sh
# Compile and show [GFM](https://help.github.com/articles/github-flavored-markdown) docs in your browser.
# Before this works you need to `gem install bcat`
#
# Usage: gfm.sh FILE.md
#
curl --silent --data-binary @- https://api.github.com/markdown/raw -H "Content-Type: text/plain" | bcat
@andkerosine
andkerosine / raskell.rb
Created August 15, 2012 05:56
Haskell-like list comprehensions in Ruby
$stack, $draws = [], {}
def method_missing *args
return if args[0][/^to_/]
$stack << args.map { |a| a or $stack.pop }
$draws[$stack.pop(2)[0][0]] = args[1] if args[0] == :<
end
class Array
def +@