Skip to content

Instantly share code, notes, and snippets.

@logworthy
logworthy / postgres_binning.sql
Created Aug 19, 2020
Using width_bucket function to bin in postgres
View postgres_binning.sql
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 Jan 16, 2020
Python boilerplate with logging and argparse
View boilerplate.py
# -*- 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 Aug 13, 2019
Removing a program via powershell
View gist:c896b77a51168ebb8338ee78740180d8
Install-Module -Name PowerShellCookbook
$app = Get-InstalledSoftware | Where-Object { $_.Publisher -like '*Anaconda*' }
$app.UninstallString
View install_tex_packages.sh
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 ..
View RSetup.R
# 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',
View 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
Simulation of how simple logistic regresion can fail to model binomial response when the underlying function is more complicated.
View Logistic Simulations
# 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) {
View BikeShare CSV Import With R
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"))
View parking event copying
create table parking_events (
id integer,
areaname text,
streetname text,
betweenstreet1 text,
betweenstreet2 text,
sideofstreet text,
streetmarker text,
arrivaltime timestamp,
You can’t perform that action at this time.