36 karma · joined March 6, 2022
def to_minutes(df, col):
df[col] = df[col].dt.minutes
return df
(
pd
.read_csv('data.csv')
.assign(dur=df.finish-df.start)
.pipe(to_minutes, col='dur')
.query('dur < 30')
.sort_values(by='dur')
.pipe(
seaborn.relplot,
x='dur',
y='distance',
hue='city'
)
)
It's a simple snippet but the code structure is clever in many ways. The enclosure of the whole expression, starting with pd, into () makes it possible to split method chaining into multiple lines without backslashes and start each line with ".". Now we can treat DataFrame methods similarly to verbs from dplyr data grammar and "." similarly to %>% operator. Its now easy to rearrange, add and delete whole lines without thinking if we forgot to add "." to the line above or below. Everything is immutable, no side effects, it's safe to copy the code in a new notebook cell and tweak it a little without worrying about tens of temporary df2_copy1 variables. The .pipe method allows to avoid "df = df[...]" junk, to reuse code fragments and even to use plotting libraries in ggplot fashion. If the chain becomes huge, just put it in a function and apply in to df using pipe method, etc... I wonder if it's possible to add memorization to pipe method to avoid recalculating the whole construction every time when rerunning the cell during debugging.When I was in high school I read about perlin noise landscape generation technique in a random blog post. I shared the technique with a friend and he was very excited. A week later he presented a program which rendered Minecraft-style landscapes in ortho projection. A few more weeks passed and he added 3D perspective (using alien tech called "projection matrices"), water reflections, grass and day-night cycle animation with shadows from Sun and stars. All this using Pascal and some primitive bundled-in 2D graphics lib.
Another related high school memory is Audiosurf game, where the road and environment are generated using an algorithm based on music tempo. What if we replace this algo with a modern generative model? Probably literally a bad trip.
https://vc.ru/life/189035-doooooom-2-s-shestyu-nulyami-kak-y...
1. Put the encrypted exploit file into some kind of Blockchain 2. Create a crypto wallet and announce a fundraising 3. As soon as the sum on the wallet reaches, say, $5M, the exploit is automatically and consensually decrypted by the Blockchain system and released to the public.