Skip to content

Instantly share code, notes, and snippets.

View duncangh's full-sized avatar
💭
👨‍💻

Graham Duncan duncangh

💭
👨‍💻
View GitHub Profile

SHORTCUTS

Key/Command Description
Tab Auto-complete files and folder names
Ctrl + A Go to the beginning of the line you are currently typing on
Ctrl + E Go to the end of the line you are currently typing on
Ctrl + U Clear the line before the cursor
Ctrl + K Clear the line after the cursor
Ctrl + W Delete the word before the cursor
Ctrl + T Swap the last two characters before the cursor
@duncangh
duncangh / bootstrap-navbar-nested-hover.html
Last active October 10, 2018 17:12
HTML and CSS Snippets
<html>
<head>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://codepen.io/jstneg/pen/vbfqy" rel="stylesheet" />
<style>
.dropdown-submenu{ position: relative; }
.dropdown-submenu>.dropdown-menu{
top:0;
left:100%;
@duncangh
duncangh / app.py
Created September 30, 2018 05:40 — forked from Sniedes722/app.py
Upload A File to an S3 Bucket with Flask
import os
import boto3
from flask import Flask, render_template, request, url_for, redirect
app = Flask(__name__)
AWS_ACCESS_KEY_ID = os.environ['AWS_ACCESS_KEY_ID']
AWS_SECRET_ACCESS_KEY = os.environ['AWS_SECRET_ACCESS_KEY']
S3_BUCKET = os.environ['S3_BUCKET']
@duncangh
duncangh / read-access.sql
Created October 9, 2018 21:01 — forked from oinopion/read-access.sql
How to create read only user in PostgreSQL
-- Create a group
CREATE ROLE readaccess;
-- Grant access to existing tables
GRANT USAGE ON SCHEMA public TO readaccess;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO readaccess;
-- Grant access to future tables
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO readaccess;
@duncangh
duncangh / bootstrap-navbar-with-submenus.markdown
Created October 10, 2018 15:21
Bootstrap: Navbar with submenus
@duncangh
duncangh / postgres-cheatsheet.md
Created October 26, 2018 01:16 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h or --help depending on your psql version):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)
import pandas as pd
import numpy as np
import re
# ================================================
class option_parser:
def __init__(self, symbol, response):
self.symbol = symbol
self.response = response
# ------------------------------------------------
@duncangh
duncangh / wget
Created November 3, 2018 00:27 — forked from bueckl/wget
Wget examples
#Spider Websites with Wget – 20 Practical Examples
Wget is extremely powerful, but like with most other command line programs, the plethora of options it supports can be intimidating to new users. Thus what we have here are a collection of wget commands that you can use to accomplish common tasks from downloading single files to mirroring entire websites. It will help if you can read through the wget manual but for the busy souls, these commands are ready to execute.
1. Download a single file from the Internet
wget http://example.com/file.iso
2. Download a file but save it locally under a different name
wget ‐‐output-document=filename.html example.com
@duncangh
duncangh / README.md
Created November 9, 2018 22:09 — forked from quiver/README.md
Who says PostgreSQL can't Pub/Sub like Redis?

Pub/Sub pattern with PostgreSQL's LISTEN/NOTIFY command

This is a simple chat-like program using pub-sub pattern, backed by PostgreSQL's LISTEN/NOTIFY command.

Publish

publish message to foo channel from user nickname.

$ python pub.py foo nickname
PUBLISH to channel #foo
# coding=UTF-8
from __future__ import division
import re
# This is a naive text summarization algorithm
# Created by Shlomi Babluki
# April, 2013
class SummaryTool(object):