Skip to content

Instantly share code, notes, and snippets.

View xevix's full-sized avatar

Alejandro Wainzinger xevix

  • California
  • 14:01 (UTC -08:00)
View GitHub Profile
import pandas as pd
import duckdb
import pygrib
import sys
# Testing data from: https://data.ecmwf.int/forecasts/20250211/00z/aifs/0p25/oper/
# ECMWF is the European Centre for Medium-Range Weather Forecasts.
def grib_to_df(grb):
attrs = str(grb).split(":")
-- Tested on 2024 MBP M4 Max 128G RAM 16 cores (12P, 4E), DuckDB 1.1.3, Sequoia 15.1
-- Taxi data set: https://www.nyc.gov/site/tlc/about/tlc-trip-record-data.page
-- Inspired by: https://duckdb.org/2024/10/16/driving-csv-performance-benchmarking-duckdb-with-the-nyc-taxi-dataset.html
-- taxi_data_2019: ~84M rows
-- UNPIVOT (naive)
-- ~5500ms (1.1.3)
-- ~4500ms (1.2)
-- ~330ms (2025/02/13 git HEAD) https://github.com/duckdb/duckdb/pull/16221
WITH locations AS (
fname = 'pwned-passwords-2.0.txt'
# Change me
# echo -n password | shasum -a 1 | awk '{print toupper($1)}'
password = '7C4A8D09CA3762AF61E59520943DC26494F8941B'
search = password
with open(fname) as f:
for line in f:
sha = line[:40]
if search == sha:

Keybase proof

I hereby claim:

  • I am xevix on github.
  • I am xevix (https://keybase.io/xevix) on keybase.
  • I have a public key ASDKzeeW4q_b8UXMKqF-posWghvBE63A41Msr3QCiHTrxwo

To claim this, I am signing this object:

@xevix
xevix / foldl1_ish.rs
Last active September 10, 2017 05:50
trait Folder {
type Item;
fn foldl1<F>(self, f: F) -> Option<Self::Item>
where
F: FnMut(Self::Item, &Self::Item) -> Self::Item;
}
impl<T: Clone> Folder for Vec<T> {
type Item = T;
fn foldl1<F>(self, mut f: F) -> Option<Self::Item>
@xevix
xevix / loop.rs
Last active September 10, 2017 02:53
pub fn combine_all_option<T>(xs: &Vec<T>) -> Option<T>
where
T: Semigroup + Clone,
{
match xs.first() {
Some(head) => {
// Dear lord this reads horribly
xs[1..].iter().fold(Some((*head).clone()), |acc, x| acc.combine(&Some((*x).clone())))
}
_ => None
@xevix
xevix / iterator_leak.py
Last active June 22, 2017 18:40
Iterator accessible after its scope ends
def main():
ary = ['I should never print']
for elem in ary:
pass
other_ary = ['other']
for other_elem in other_ary:
# "elem" hould not be defined here, but this works, because of Python's awful scoping rules
def foo(a, b={}):
if a == 1:
b["oops"] = "boom"
return b
for i in xrange(3):
print "foo: {}".format(foo(i))
# Output:
def foo(bob, **kwargs):
pass
kwargs = {'bob': 'first param is also bob, when splatted, they clash...'}
foo('bar', **kwargs) # KABOOM!
# Traceback (most recent call last):
# File "<stdin>", line 1, in <module>
# TypeError: foo() got multiple values for keyword argument 'bob'
@xevix
xevix / rust_lifetimes.rs
Created March 2, 2016 08:36
Rust Lifetimes
struct Foo {
x: i32,
}
struct Bar<'a> {
foo: &'a Foo,
// Uncomment to disallow drop()
x: ::std::cell::RefCell<() /* Option<&'a Bar<'a>>*/>,
}