Skip to content

Instantly share code, notes, and snippets.

View heysamtexas's full-sized avatar

Sam Texas heysamtexas

View GitHub Profile
@heysamtexas
heysamtexas / Makefile
Created August 24, 2018 12:38
Read variables from an env file inside a makefile target
dev-test:
export $(shell grep -v '^#' env.test | xargs) && \
cd src && \
python manage.py test -k --failfast -v2 $(TARGET)
@heysamtexas
heysamtexas / read-access.sql
Created August 23, 2018 15:27 — 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;
reddit.com
news.ycombinator.com
businessinsider.com
nytimes.com
chron.com
expressen.se
dn.se
aftonbladet.se
wsj.com
usatoday.com
from __future__ import division
import numpy as np
RADIUS_OF_EARTH_IN_KM = 6371.01
def haversine(lat1, lon1, lat2, lon2):
"""
Utility to calcutlate distance between two pointtodo explain regarding height
coverting from geodisc co-ordinate to cartestian gives errors when distances are further apart
@heysamtexas
heysamtexas / docker-secrets-peeker.sh
Last active October 19, 2017 08:00
An excellent little one-liner to peek at your docker secrets
# this is a little "one-liner" to peek at all my docker secrets.
# I use this on development and test machines when debugging
echo ""
echo "-------------------------"
echo "Peek at docker secrets..."
echo "-------------------------"
docker service create --name peeker \
$(docker secret ls | sed '1d'| awk '{print "--secret " $2}'|sort -k2|xargs echo) busybox \
sh -c 'for i in `ls /run/secrets/*`; do echo "$(basename $i): $(cat $i)"; done' > /dev/null 2>&1 && \
sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
sudo echo "/swapfile none swap sw 0 0" >> /etc/fstab;
@heysamtexas
heysamtexas / Makefile
Created March 24, 2017 22:24
Default help command for Makefile
###############################################################################
# HELP / DEFAULT COMMAND
###############################################################################
.PHONY: help
help:
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
@heysamtexas
heysamtexas / zeromq_demo_publisher.py
Created February 23, 2017 14:57 — forked from ramn/zeromq_demo_publisher.py
Python ZeroMQ pub/sub example
import time.sleep
import zmq
context = zmq.Context()
socket = context.socket(zmq.PUB)
socket.bind('tcp://127.0.0.1:2000')
# Allow clients to connect before sending data
sleep(10)
socket.send_pyobj({1:[1,2,3]})
@heysamtexas
heysamtexas / semver.sh
Last active February 1, 2017 23:05 — forked from loa/semver.sh
Bash Git SemVer Util
#!/bin/bash
# Author: Carl Loa Odin <[email protected]>
# https://gist.github.com/loa/435da12af9494a112daf
test_res=0
function get_git_version() {
version=$(git describe --tags 2> /dev/null)
if [ $? -eq 128 ]; then
# Return initial version incase no tags is found
@heysamtexas
heysamtexas / init.lua
Created January 17, 2017 14:13
Hammerspoon snippet to autologin on a simple form
--[[
Author: Mark Anderson (https://github.com/undernewmanagement)
This is for users of hammerspoon, a neat little utility to script your OSX environment
This is a little snippet I use for autologin on applications that I develop.
I find that saving a few keystrokes here and there 100 times a day makes me a little happier.
]]--