Skip to content

Instantly share code, notes, and snippets.

View kshefchek's full-sized avatar

Kent Shefchek kshefchek

View GitHub Profile
@EcZachly
EcZachly / groups.sql
Created November 6, 2023 21:11
How to write an algorithm to group people in optimized groups based on timezone and track
-- first query all the users
WITH offsets AS (SELECT a.*,
EXTRACT(hour FROM ptn.utc_offset) AS utc_offset
FROM bootcamp.attendees a
JOIN pg_timezone_names ptn ON a.timezone = ptn.name
WHERE a.bootcamp_version = 3
AND a.timezone IS NOT NULL
AND a.content_delivery = 'Live'::text
),
-- then aggregate the users by track and offset, we want matching timezones to fill up first
@alexpreynolds
alexpreynolds / pandas_df_to_tabix_via_libraries.py
Last active April 25, 2024 13:26
Create an indexed tabix file from a Pandas dataframe via "pure" Python
#!/usr/bin/env python
'''
Create an indexed tabix file from a Pandas dataframe
via "pure" Python (i.e., no subprocess)
'''
import os
import io
import pandas as pd
@huitseeker
huitseeker / numberToWords.scala
Created March 31, 2016 10:48
Converting numbers to words in Scala
def speak(num: Int, printZero: Boolean = true): String = {
if (num < 0) s"negative ${speak(-num)}"
else if (num >= 1000000000) s"${speak(num / 1000000000)} billion ${speak(num % 1000000000, false)}"
else if (num >= 1000000) s"${speak(num / 1000000)} million ${speak(num % 1000000, false)}"
else if (num >= 1000) s"${speak(num / 1000)} thousand ${speak(num % 1000, false)}"
else if (num >= 100) s"${speak(num / 100)} hundred ${speak(num % 100, false)}"
else if (num >= 20) (num/10) match {
case 2 => s"twenty ${speak(num % 10, false)}"
case 3 => s"thirty ${speak(num % 10, false)}"
case 5 => s"fifty ${speak(num % 10, false)}"
@pypt
pypt / pyyaml-duplicates.py
Created September 9, 2015 22:10
PyYAML: raise exception on duplicate keys on the same document hierarchy level
import yaml
from yaml.constructor import ConstructorError
try:
from yaml import CLoader as Loader
except ImportError:
from yaml import Loader
def no_duplicates_constructor(loader, node, deep=False):