Skip to content

Instantly share code, notes, and snippets.


CHANN channprj

View GitHub Profile
lizthegrey / attributes.rb
Last active Jan 23, 2021
Hardening SSH with 2fa
View attributes.rb
default['sshd']['sshd_config']['AuthenticationMethods'] = 'publickey,keyboard-interactive:pam'
default['sshd']['sshd_config']['ChallengeResponseAuthentication'] = 'yes'
default['sshd']['sshd_config']['PasswordAuthentication'] = 'no'
tkafka / listAllEventListeners.js
Last active Jan 14, 2021 — forked from dmnsgn/listAllEventListeners.js
List all event listeners in a document
View listAllEventListeners.js
console.table((function listAllEventListeners() {
const allElements ='*'));
allElements.push(document); // we also want document events
const types = [];
for (let ev in window) {
if (/^on/.test(ev)) types[types.length] = ev;
let elements = [];
for (let i = 0; i < allElements.length; i++) {
johngrib /
Created Dec 31, 2018
Show github contribution graph on terminal
#! /usr/local/bin/bash
curl -s$MYGITHUB/ > $RAW
TITLE=`cat /tmp/johngrib-github | pcregrep -M '[0-9,]+ contributions\s*\n\s*in the last year'`
omarryhan / Sanic-Gino-Alembic migrations Setup
Last active May 30, 2020
Sanic/Gino/Alembic migrations
View Sanic-Gino-Alembic migrations Setup
# Do the first 6 steps only once.
1. pip install --user alembic
2. bash: ``cd {{my_project}} && alembic init alembic``
3. bash: ``text_editor {{my_project}}/alembic.ini``
4. Change: "sqlalchemy.url = postgres://{{username}}:{{password}}@{{address}}/{{db_name}}"
5. bash: ``text_editor {{my_project}}/alembic/``
6. Now, import your metadata/db object from your app.:
# {{my_project}}/{{my_project_dir}}/
# Darkify Slack on Mac OS or Linux.
# curl | sh
if [ "`uname -s`" = "Darwin" ]; then
nirizr /
Last active Dec 22, 2020
sqlalchemy upsert supporting delayed ORM insertion and duplicate removal (inside a single query)
def upsert(session, model, rows):
table = model.__table__
stmt = postgresql.insert(table)
primary_keys = [ for key in inspect(table).primary_key]
update_dict = { c for c in stmt.excluded if not c.primary_key}
if not update_dict:
raise ValueError("insert_or_update resulted in an empty update_dict")
stmt = stmt.on_conflict_do_update(index_elements=primary_keys,
slowkow /
Created Jul 19, 2018
Remove all traces of emoji from a text file.
#!/usr/bin/env python
Remove emoji from a text file and print it to stdout.
python input.txt > output.txt
lifehome /
Last active Jan 13, 2021 — forked from benkulbertis/
Cloudflare API v4 Dynamic DNS Update in Bash

Cloudflare DDNS bash client with systemd

This is a bash script to act as a Cloudflare DDNS client, useful replacement for ddclient.

Look out!

A newer version is available!

This gist will no longer update, instead please go to for more updated versions.

How to use?

  1. Put the cfupdater files to /usr/local/bin
  • If you are using IPv4 for A record, append -v4 to cfupdater in the following systemd service unit.
austinjp /
Last active Jan 11, 2021
Enabling wifi on Ubuntu server 18

Wifi on Ubuntu 18 server


  1. Install wpasupplicant
  2. Turn on wifi radios: sudo nmcli radio wifi on
  3. Check your devices are recognised even if they're not "managed": sudo iwconfig
  4. Check your wifi (here called "wlp3s0") is capable of detecting nearby routers: sudo iwlist wlp3s0 scan
  5. Configure netplan by dropping a file called 01-netcfg.yaml into /etc/netplan/ or edit existing file there. See example below.
  6. netplan try, netplan generate, netplan apply.
kstrauser /
Last active Nov 23, 2020
Using the "black" Python formatter in VS Code

This is how to use the Black Python code formatter in VS Code.

Make a Python 3.6 virtualenv for running Black

Black itself requires Python 3.6 to run, but few of our projects are on that version. The VS Code plugin conveniently lets you run black from its own virtualenv.

I had to give a specific version of black this morning. I didn't yesterday. Don't specify the version unless it makes you (and if you do, give the current version, not the one from this doc).

$ cd ~/Envs