Skip to content

Instantly share code, notes, and snippets.

@undernewmanagement
undernewmanagement / 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;
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
@undernewmanagement
undernewmanagement / 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]})
@undernewmanagement
undernewmanagement / semver.sh
Last active February 1, 2017 23:05 — forked from loa/semver.sh
Bash Git SemVer Util
#!/bin/bash
# Author: Carl Loa Odin <carl.loa.odin@gmail.com>
# 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
@undernewmanagement
undernewmanagement / transmission-ssl
Created February 10, 2016 12:50 — forked from Belphemur/transmission-ssl
Configuration to use nginx as reverse proxy for Transmission BT with SSL protected with auth
upstream transmission {
server 127.0.0.1:9091; #Transmission
}
server {
listen 443 ssl spdy;
server_name example.com;
auth_basic "Server Restricted";
auth_basic_user_file /var/www/myWebSite/web/.htpasswd;
# Path to the root of your installation
#!/bin/bash
if swapon -s | grep -q /mnt/swapfile
then
echo "Swapfile already mounted"
else
if [ -e /mnt/swapfile ]
then
echo "Mounting swapfile"
swapon /mnt/swapfile
// You create your bookmarklet by instantiating
// a new Bookmarklet function, then pass in the options like so.
// This example checks to see if the var is already defined, and makes
// sure not to overwrite it. This could happen if the user clicks on
// the bookmarklet more than once.
MyBookmarklet = MyBookmarklet || (MyBookmarklet = new Bookmarklet({
// debug: true, // use debug to bust the cache on your resources
css: ['/my/style.css'],
js: [],
@undernewmanagement
undernewmanagement / transliterate.sql
Created April 10, 2012 04:46 — forked from chanmix51/transliterate.sql
transliteration in plpgsql
CREATE OR REPLACE FUNCTION transliterate(my_text VARCHAR) RETURNS varchar AS $$
DECLARE
text_out VARCHAR DEFAULT '';
BEGIN
text_out := my_text;
text_out := translate(text_out, 'àâäåáăąãā', 'aaaaaaaaa');
text_out := replace(text_out, 'æ', 'ae');
text_out := translate(text_out, 'çċćčĉ', 'ccccc');
text_out := translate(text_out, 'éèėëêēĕ', 'eeeeeee');
text_out := translate(text_out, 'îïìíī', 'iiiii');
@undernewmanagement
undernewmanagement / slugify.sql
Created April 10, 2012 03:56 — forked from chanmix51/slugify.sql
slugification in plpgsql
CREATE OR REPLACE FUNCTION slugify(title VARCHAR) RETURNS varchar AS $$
BEGIN
RETURN trim(both '-' from regexp_replace(lower(transliterate(title)), '[^a-z0-9]+', '-', 'g'));
END;
$$ LANGUAGE plpgsql;