Skip to content

Instantly share code, notes, and snippets.

View channprj's full-sized avatar

Heechan Park channprj

View GitHub Profile
@johngrib
johngrib / contribution.sh
Created December 31, 2018 14:58
Show github contribution graph on terminal
#! /usr/local/bin/bash
MYGITHUB=johngrib
RAW=/tmp/$MYGITHUB-github
TABLE=/tmp/$MYGITHUB-github-table
COLORS=/tmp/$MYGITHUB-github-colors
curl -s https://github.com/$MYGITHUB/ > $RAW
TITLE=`cat /tmp/johngrib-github | pcregrep -M '[0-9,]+ contributions\s*\n\s*in the last year'`
@canokay
canokay / decorators.py
Last active May 29, 2022 17:44
Django Custom View Decorators
from django.http import HttpResponseRedirect
from django.core.exceptions import PermissionDenied
from django.urls import reverse
from django.shortcuts import render
from django.shortcuts import redirect
def role_required(allowed_roles=[]):
def decorator(view_func):
def wrap(request, *args, **kwargs):
@omarryhan
omarryhan / Sanic-Gino-Alembic migrations Setup
Last active May 30, 2020 15:49
Sanic/Gino/Alembic migrations
# 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/env.py``
6. Now, import your metadata/db object from your app.:
# {{my_project}}/{{my_project_dir}}/app.py
@npearce
npearce / install-docker.md
Last active April 19, 2024 12:35
Amazon Linux 2 - install docker & docker-compose using 'sudo amazon-linux-extras' command

UPDATE (March 2020, thanks @ic): I don't know the exact AMI version but yum install docker now works on the latest Amazon Linux 2. The instructions below may still be relevant depending on the vintage AMI you are using.

Amazon changed the install in Linux 2. One no-longer using 'yum' See: https://aws.amazon.com/amazon-linux-2/release-notes/

Docker CE Install

sudo amazon-linux-extras install docker
sudo service docker start
@ryanpcmcquen
ryanpcmcquen / darkify_slack.sh
Last active February 23, 2023 16:08
Darkify your Slack.
#!/bin/sh
# Darkify Slack on Mac OS or Linux.
# curl https://gist.githubusercontent.com/ryanpcmcquen/8a7ddc72460eca0dc1f2dc389674dde1/raw/darkify_slack.sh | sh
if [ "`uname -s`" = "Darwin" ]; then
SLACK_INTEROP_JS="/Applications/Slack.app/Contents/Resources/app.asar.unpacked/dist/ssb-interop.bundle.js"
else
SLACK_INTEROP_JS="/usr/lib/slack/resources/app.asar.unpacked/dist/ssb-interop.bundle.js"
fi
@jolexa
jolexa / invalidate-all.py
Created October 24, 2018 14:07
Invalidate CloudFront Cache with boto3
from time import time
import sys
import boto3
client = boto3.client('cloudfront')
# Uncomment this to pass a URL to the script
#def get_id(url):
# print("get_id args: {0}".format(url))
# # url: asdf.cloudfront.net
# # return: E2134123ASDF
@nirizr
nirizr / full_upsert.py
Last active September 28, 2023 23:19
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 = [key.name for key in inspect(table).primary_key]
update_dict = {c.name: 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
slowkow / remove-emoji.py
Created July 19, 2018 14:10
Remove all traces of emoji from a text file.
#!/usr/bin/env python
"""
Remove emoji from a text file and print it to stdout.
Usage
-----
python remove-emoji.py input.txt > output.txt
"""
@lifehome
lifehome / README.md
Last active February 25, 2024 06:34 — forked from benkulbertis/cloudflare-update-record.sh
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 https://github.com/lifehome/systemd-cfddns 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
austinjp / wifi-on-ubuntu-server-18.md
Last active February 10, 2023 10:10
Enabling wifi on Ubuntu server 18

Wifi on Ubuntu 18 server

TLDR

  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.