Skip to content

Instantly share code, notes, and snippets.

View x's full-sized avatar
🐦

Devon Peticolas x

🐦
View GitHub Profile
@x
x / query.sql
Created February 9, 2024 23:47
CREATE TABLE tbl AS SELECT strptime(dt_iso, '%x %X %z %Z') AS dt, temp_min, temp, temp_max, feels_like FROM "nyc_weather.csv";
CREATE TABLE averages AS SELECT date_part('month', dt) AS month, date_part('day', dt) AS day, date_part('hour', dt) AS hour, avg(temp_min), avg(temp), avg(temp_max), avg(feels_like) FROM tbl GROUP BY month, day, hour ORDER BY month, day, hour;
SELECT * FROM averages WHERE month = 2 AND day = 9;
┌───────┬───────┬───────┬────────────────────┬────────────────────┬────────────────────┬────────────────────┐
│ month │ day │ hour │ avg(temp_min) │ avg("temp") │ avg(temp_max) │ avg(feels_like) │
│ int64 │ int64 │ int64 │ double │ double │ double │ double │
├───────┼───────┼───────┼────────────────────┼────────────────────┼────────────────────┼────────────────────┤
│ 2 │ 9 │ 0 │ 28.441458333333333 │ 29.88333333333333 │ 31.296875000000004 │ 20.9225 │
│ 2 │ 9 │ 1 │ 27.859555555555552 │ 29.6
@x
x / game_images.py
Created December 23, 2023 01:29
Extract game images from OpenEmu with rom-based names
#! python
import argparse
import sqlite3
import os
import shutil
import sys
from urllib.parse import unquote
QUERY = """
SELECT ZGAME.ZNAME, ZIMAGE.ZRELATIVEPATH, ZIMAGE.ZSOURCE, ZROM.ZLOCATION
.DEFAULT: setup
SHELL = /bin/bash
NAME := coreml_stable_diffusion
PYMAJOR := 3
PYREV := 8
PYPATCH := 10
PYVERSION := ${PYMAJOR}.${PYREV}.${PYPATCH}
PYENV := ~/.pyenv/versions/${PYVERSION}
#!python
"""
extract_and_merge_csv_cols.py is a script to extract a target column from a set
of csvs and merge them into a single csv where each column name is the filename
of the original csv.
Usage:
extract_and_merge_csv_cols.py <target_col> <csvs>...
"""
@x
x / wordl.py
Last active January 12, 2022 22:01
from pathlib import Path
from enum import Enum
from collections import defaultdict
SYSTEM_DICTIONARY = "/usr/share/dict/words"
class Hint(Enum):
GRAY = 0
YELLOW = 1
GREEN = 2
@x
x / cowsay_server.sh
Created August 16, 2021 17:02
A simple webapp
while true; do { echo -e 'HTTP/1.1 200 OK\r\n'; fortune -s | cowsay; } | nc -l 8080; done
@x
x / petscii.sh
Created August 16, 2021 16:47
PETSCII Maze in One-Line Python
python3 -c "while 1: print(chr(int(9585.5 + __import__('random').random())), end='')"
@x
x / windows.java
Created August 1, 2021 22:03
Apache Beam Summit - Windowing Example
package io.oden.laser.common.transforms;
import org.apache.beam.sdk.transforms.windowing.*;
import org.apache.beam.sdk.transforms.windowing.Window.OnTimeBehavior;
import org.joda.time.Duration;
public class Windows {
/*
* The Window described attempts to both be prompt but not needlessly retrigger.
* It's designed to account for the following cases...
@x
x / inner_join.py
Created April 30, 2021 07:10
pandas range inner join
In [3]: df1 = pd.DataFrame({"start": [1,2,6], "end": [2,6,9]})
...: df2 = pd.DataFrame({"foo": [1,2,3,4,5,6,7,8,9]})
...: dfm = pd.merge(df1, df2, how="cross")
...: dfm.loc[(dfm.foo >= dfm.start) & (dfm.foo < dfm.end)]
Out[3]:
start end foo
0 1 2 1
10 2 6 2
11 2 6 3
12 2 6 4
@x
x / decode_anything_probably.py
Created April 1, 2021 22:28
Decode anything probably
In [1]: import chardet
In [2]: s = b'200 \xb5l Ultra Po'
In [3]: chardet.detect(s)
Out[3]: {'encoding': 'ISO-8859-1', 'confidence': 0.73, 'language': ''}
In [4]: s.decode(chardet.detect(s)['encoding'])
Out[4]: '200 µl Ultra Po'