Skip to content

Instantly share code, notes, and snippets.

@mgk
mgk / script-template.sh
Created June 8, 2023 14:49 — forked from m-radzikowski/script-template.sh
Minimal safe Bash script template - see the article with full description: https://betterdev.blog/minimal-safe-bash-script-template/
#!/usr/bin/env bash
set -Eeuo pipefail
trap cleanup SIGINT SIGTERM ERR EXIT
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P)
usage() {
cat <<EOF
Usage: $(basename "${BASH_SOURCE[0]}") [-h] [-v] [-f] -p param_value arg1 [arg2...]
@mgk
mgk / Recreate container
Created October 18, 2022 15:05 — forked from brunohulk/Recreate container
Recreate docker containers
docker-compose rm --all && docker-compose pull && docker-compose build --no-cache && docker-compose up -d --force-recreate
@mgk
mgk / git-branching-diagram.md
Created November 20, 2021 13:42 — forked from bryanbraun/git-branching-diagram.md
Example Git Branching Diagram

Example Git Branching Diagram

You can use this diagram as a template to create your own git branching diagrams. Here's how:

  1. Create a new diagram with diagrams.net (formerly draw.io)
  2. Go to File > Open From > URL
  3. Insert this url (it points to the xml data below): https://gist.githubusercontent.com/bryanbraun/8c93e154a93a08794291df1fcdce6918/raw/bf563eb36c3623bb9e7e1faae349c5da802f9fed/template-data.xml
  4. Customize as needed for your team.

@mgk
mgk / iframe_helper.rb
Created October 20, 2021 13:43
rails sanitizing iframe helper
module IframeHelper
def iframe(html_options={})
attributes =
html_options
.map {|name, value| value.nil? ? name : %(#{name}="#{value}")}
.join(" ")
sanitize("<iframe #{attributes}></iframe>",
tags: %w(iframe),
attributes: html_options.keys.map(&:to_s)
@mgk
mgk / Capybara.md
Created March 10, 2020 17:22 — forked from tomas-stefano/Capybara.md
Capybara cheatsheet

Capybara Actions

# Anchor
click_link 'Save'

# Button
click_button 'awesome'

# Both above
@mgk
mgk / HTML-code-table-JavaScript.html.js
Created December 2, 2019 17:31
DataGrip Extractor for tables with JSON (uses <td><pre></pre></td> instead of just <td></td>)
function eachWithIdx(iterable, f) { var i = iterable.iterator(); var idx = 0; while (i.hasNext()) f(i.next(), idx++); }
function mapEach(iterable, f) { var vs = []; eachWithIdx(iterable, function (i) { vs.push(f(i));}); return vs; }
function escape(str) {
str = str.replaceAll("\t|\b|\\f", "");
str = com.intellij.openapi.util.text.StringUtil.escapeXml(str);
str = str.replaceAll("\\r|\\n|\\r\\n", "<br/>");
return str;
}
var NEWLINE = "\n";
@mgk
mgk / README.md
Created April 20, 2018 19:08 — forked from tombigel/README.md
How to Change Open Files Limit on OS X and macOS Sierra (10.8 - 10.12)

How to Change Open Files Limit on OS X and macOS

This text is the section about OS X Yosemite (which also works for macOS Sierra) from https://docs.basho.com/riak/kv/2.1.4/using/performance/open-files-limit/#mac-os-x

The last time i visited this link it was dead (403), so I cloned it here from the latest snapshot in Archive.org's Wayback Machine https://web.archive.org/web/20170523131633/https://docs.basho.com/riak/kv/2.1.4/using/performance/open-files-limit/

Mac OS X

To check the current limits on your Mac OS X system, run:

@mgk
mgk / US Zip Codes from 2013 Government Data
Created December 31, 2017 21:57 — forked from erichurst/US Zip Codes from 2013 Government Data
All US zip codes with their corresponding latitude and longitude coordinates. Comma delimited for your database goodness. Source: http://www.census.gov/geo/maps-data/data/gazetteer.html
This file has been truncated, but you can view the full file.
ZIP,LAT,LNG
00601,18.180555, -66.749961
00602,18.361945, -67.175597
00603,18.455183, -67.119887
00606,18.158345, -66.932911
00610,18.295366, -67.125135
00612,18.402253, -66.711397
00616,18.420412, -66.671979
00617,18.445147, -66.559696
@mgk
mgk / gpg-import-and-export-instructions.md
Created November 28, 2017 03:54 — forked from chrisroos/gpg-import-and-export-instructions.md
Instructions for exporting/importing (backup/restore) GPG keys

Every so often I have to restore my gpg keys and I'm never sure how best to do it. So, I've spent some time playing around with the various ways to export/import (backup/restore) keys.

Method 1

Backup the public and secret keyrings and trust database

cp ~/.gnupg/pubring.gpg /path/to/backups/
cp ~/.gnupg/secring.gpg /path/to/backups/
cp ~/.gnupg/trustdb.gpg /path/to/backups/

or, instead of backing up trustdb...

@mgk
mgk / map-to-json.js
Created September 9, 2017 19:41 — forked from davemackintosh/map-to-json.js
Convert ES6 `Map`s to a standard JSON object without effing Babel.
/**
* Convert a `Map` to a standard
* JS object recursively.
*
* @param {Map} map to convert.
* @returns {Object} converted object.
*/
function map_to_object(map) {
const out = Object.create(null)
map.forEach((value, key) => {