Skip to content

Instantly share code, notes, and snippets.

View dhbradshaw's full-sized avatar

Douglas H. Bradshaw dhbradshaw

  • Harvest Alabama
View GitHub Profile
@dhbradshaw
dhbradshaw / postgres-windows.md
Last active April 21, 2022 19:08
Postgres on WSL (Windows Subsystem for Linux) ubuntu 18.04

Postgres on WSL (Windows Subsystem for Linux) ubuntu 18.04

Hint: it's not different than running it under ubuntu without Windows.

Add postgres package registry

sudo apt install postgresql-common
sudo sh /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh

Update apt

@dhbradshaw
dhbradshaw / pkill.sh
Last active November 27, 2019 11:52
pkill example: kill guake process
# Try listing the processes associated with a term, for example guake.
$ pgrep guake
8494
# Kill guake processes without bothering looking at them.
$ pkill guake
@dhbradshaw
dhbradshaw / gnu_encryption.sh
Last active January 24, 2019 13:23
gnu encryption
# Encrypt file
gpg -c --cipher-algo AES256 private-file.txt
# Decrypt it
gpg private-file.txt.gpg
# !!Don't forget the passphrase!!
@dhbradshaw
dhbradshaw / no-rebase.sh
Last active September 19, 2019 15:08
Better than rebase
# Source: https://makandracards.com/makandra/527-squash-several-git-commits-into-a-single-commit
# Switch to the master branch and make sure you are up to date.
git checkout master
git fetch # this may be necessary (depending on your git config) to receive updates on origin/master
git pull
# Merge the feature branch into the master branch.
git merge feature_branch
@dhbradshaw
dhbradshaw / systemd_services.md
Last active May 4, 2024 03:20 — forked from leommoore/systemd_services.md
Systemd Services 101

Check that your system supports systemd

pidof systemd
2733

If this return a number then your system supports systemd. Most Linux distributions in 2017 support systemd.

Check out the processes currently running.

Since systemd starts the process then all processes will be children of systemd

@dhbradshaw
dhbradshaw / imgSources.js
Last active December 17, 2018 16:51
Array of img urls from JS console
// Get html collection of images:
var imgs = document.getElementsByTagName('img')
// Convert to array
imgs = Array.from(imgs)
// Map to urls
var urls = imgs.map(img => img.src)
// Copy to clipboard
@dhbradshaw
dhbradshaw / morse.js
Last active January 6, 2021 17:09 — forked from eholk/morse.js
A Morse Code generator in Java Script
function MorseNode(ac, rate) {
// ac is an audio context.
this._oscillator = ac.createOscillator();
this._gain = ac.createGain();
this._gain.gain.value = 0;
this._oscillator.frequency.value = 750;
this._oscillator.connect(this._gain);
In [1]: %load_ext autoreload
In [2]: %autoreload 2
In [3]: from core.courses import questions
In [4]: questions.meaning_of_life()
Out[4]: 42
In [5]: "Rewriting method"
@dhbradshaw
dhbradshaw / hn_seach.js
Created September 2, 2016 10:50 — forked from kristopolous/hn_seach.js
hn job query search
function query() {
var
// HN is done with very unsemantic classes.
job_list = Array.prototype.slice.call(document.querySelectorAll('.c5a,.cae,.c00,.c9c,.cdd,.c73,.c88')),
query_list = Array.prototype.slice.call(arguments),
shown = 0, total = job_list.length;
// Traverses up the dom stack trying to find a match of a specific class
function up_to(node, klass) {
if (node.classList.contains(klass)) {
@dhbradshaw
dhbradshaw / creating time-aware-datetime-object.py
Last active February 10, 2016 14:47
creating timezone-aware datetime objects
from django.utils import timezone
import pytz
pytz_tz = pytz.timezone('America/Chicago')
# wrong -- The direct approach leads to somewhat random time offsets between timezones.
adt = timezone.datetime(year=2016, month=1, day=6, tzinfo=pytz_tz)
# correct: Localize a naive datetime.
ndt = timezone.datetime(year=2016, month=1, day=6)