Skip to content

Instantly share code, notes, and snippets.

@logworthy
logworthy / postgres_binning.sql
Created August 19, 2020 01:06
Using width_bucket function to bin in postgres
with example as (
select 399 as num, width_bucket(399, 400, 990, 59) as buk
union all
select 400 as num, width_bucket(400, 400, 990, 59) as buk
union all
select 401 as num, width_bucket(401, 400, 990, 59) as buk
union all
select 409 as num, width_bucket(409, 400, 990, 59) as buk
union all
select 410 as num, width_bucket(410, 400, 990, 59) as buk
@logworthy
logworthy / boilerplate.py
Last active January 16, 2020 02:18
Python boilerplate with logging and argparse
# -*- coding: utf-8 -*-
""" TODO: Update package docstring
"""
import logging
import argparse
def str2bool(val):
""" string to boolean conversion for argparse
@logworthy
logworthy / gist:c896b77a51168ebb8338ee78740180d8
Created August 13, 2019 23:18
Removing a program via powershell
Install-Module -Name PowerShellCookbook
$app = Get-InstalledSoftware | Where-Object { $_.Publisher -like '*Anaconda*' }
$app.UninstallString
@logworthy
logworthy / install_tex_packages.sh
Created October 7, 2018 23:12
Installing TeX Packages
export TEXLIB=/usr/share/texlive/texmf-dist/
export packagename=tabu
wget http://mirrors.ctan.org/macros/latex/contrib/$packagename.zip
unzip $packagename.zip
cd $packagename
latex *.ins
sudo mkdir $TEXLIB/tex/latex/$packagename
sudo cp *.sty $TEXLIB/tex/latex/$packagename
cd ..
@logworthy
logworthy / RSetup.R
Last active March 1, 2018 15:26
R Setup
# To get setup quickly just run the below line:
# (note that it changes with revisions to the file... will try to keep it up to date)
# source('https://gist.githubusercontent.com/logworthy/695f037e79ca4a2c49f2bdbe3502a0c5/raw/459be6d79c7e2762cae9b5c981a18dfde24da4ba/RSetup.R')
# set up R with desired pacakges and load them by default
# install packages
packages_required <- c(
'data.table',
'RODBC',
@logworthy
logworthy / linear programming example
Created May 9, 2015 05:36
linear programming example
/*****
EXAMPLE OF A LINEAR PROGRAMMING PROBLEM
*****/
/* classes of things */
set CATEGORIES;
/* function discretised over these points */
set POINTS;
@logworthy
logworthy / Logistic Simulations
Created May 6, 2015 13:49
Simulation of how simple logistic regresion can fail to model binomial response when the underlying function is more complicated.
# Simulation of how simple logistic regression can fail to model
# binomial response when the underlying function is more complicated
install.packages(c('data.table', 'plyr', 'ggplot2', 'drc'))
library(data.table)
library(plyr)
library(ggplot2)
library(drc)
# Generalised logistic function
logistic_function <- function(x) {
df <- read.csv("stations.csv", nrows=1000000, colClasses=c("integer","NULL","POSIXct", "NULL","NULL","NULL","NULL","integer","NULL","NULL","NULL","NULL","integer","NULL","NULL","NULL"))
create table parking_events (
id integer,
areaname text,
streetname text,
betweenstreet1 text,
betweenstreet2 text,
sideofstreet text,
streetmarker text,
arrivaltime timestamp,