Skip to content

Instantly share code, notes, and snippets.

View alittlesliceoftom's full-sized avatar

Tom O'Neill alittlesliceoftom

  • London
View GitHub Profile
WITH customers AS (
SELECT 'Customer1' AS customer_id UNION ALL
SELECT 'Customer2' AS customer_id UNION ALL
SELECT 'Customer3' AS customer_id UNION ALL
SELECT 'Customer4' AS customer_id
)
SELECT
c.customer_id,
CONVERT(BIGINT, SUBSTRING(HASHBYTES('MD5', c.customer_id), 1, 5)) % 100 AS assigned_bucket
FROM customers c;
@robfraz
robfraz / using_ssh_keys_with_github.md
Created April 4, 2018 09:30
Using SSH keys with GitHub

1. Generate an SSH key-pair

First up, generate yourself an SSH key pair - unless you already have one you can reuse, in which case skip this step.

Notes on this step:

  • Replace anything in block caps below with something meaningful - it's just a comment that gets stored with the key to help you tell what it's used for in the future.
  • It will ask you if you want to password-protect (i.e. encrypt) the private half of the key pair. If you're using a Mac, I recommend you set a password as Git integrates with the MacOS keychain really nicely. I'm not familiar with how to setup 'transparent' password-protected private keys on other operating systems, so best to just set no password unless you know what you're doing.
ssh-keygen -t rsa -b 4096 -C "YOUR_NAME github key [email protected]" -f ~/.ssh/id_rsa_github
@alimanfoo
alimanfoo / find_runs.py
Created November 5, 2017 23:53
Find runs of consecutive items in a numpy array.
import numpy as np
def find_runs(x):
"""Find runs of consecutive items in an array."""
# ensure array
x = np.asanyarray(x)
if x.ndim != 1:
raise ValueError('only 1D array supported')
# Set folder names
input_folder = r'output_csvs_from_mPEnergy'
output_folder = r'reformatted_tpnhhd_data'
archive_folder = r'archive'
# find directory of python script
cPath = os.path.dirname(os.path.abspath(__file__))
# go up one level
folder = os.path.dirname(cPath)
/**
* Execute the following T-SQL scripts in Microsoft SQL Server Management Studio (SSMS)
* Query Editor to demonstrate T-SQL CONVERT and CAST functions in transforming string SQL
* date formats, string time & string datetime data to datetime data type. Practical examples
* for T-SQL DATE / DATETIME functions.
* source: http://www.sqlusa.com/bestpractices/datetimeconversion/
*/
-- SQL Server string to date / datetime conversion - datetime string format sql server
-- MSSQL string to datetime conversion - convert char to date - convert varchar to date