Skip to content

Instantly share code, notes, and snippets.

View ritchie46's full-sized avatar

Ritchie Vink ritchie46

View GitHub Profile
@ritchie46
ritchie46 / example.py
Last active February 23, 2023 14:47
Example of polars multithreading third party work pool
import polars as pl
import numpy as np
df = (pl.DataFrame({
"a": np.random.randint(0, 100, int(1e8))
}).groupby("a").agg(
pl.col("a").alias("list")
))
# prints
@ritchie46
ritchie46 / question.py
Created November 19, 2021 11:00
answering a question
size = 10 ** 2
df = pl.DataFrame({
"groupid": [floor(i*0.1)for i in range(size)],
"vectors": [[i,i+1,i-1] for i in range(size)],
"numbers": [i for i in range(size)]
})
print(df)
@ritchie46
ritchie46 / pokemon.csv
Created September 1, 2021 14:45
first 150 pokemon
# Name Type 1 Type 2 Total HP Attack Defense Sp. Atk Sp. Def Speed Generation Legendary
1 Bulbasaur Grass Poison 318 45 49 49 65 65 45 1 False
2 Ivysaur Grass Poison 405 60 62 63 80 80 60 1 False
3 Venusaur Grass Poison 525 80 82 83 100 100 80 1 False
3 VenusaurMega Venusaur Grass Poison 625 80 100 123 122 120 80 1 False
4 Charmander Fire 309 39 52 43 60 50 65 1 False
5 Charmeleon Fire 405 58 64 58 80 65 80 1 False
6 Charizard Fire Flying 534 78 84 78 109 85 100 1 False
6 CharizardMega Charizard X Fire Dragon 634 78 130 111 130 85 100 1 False
6 CharizardMega Charizard Y Fire Flying 634 78 104 78 159 115 100 1 False
@ritchie46
ritchie46 / example.py
Created June 21, 2021 09:33
use CEMS API without client library
# $ pip install requests
import requests
username = "my-username"
password = "my-little-secret"
r = requests.post(
"https://crux-nuclei.com/login",
json={"username": username, "password": password},
)
ACCESS_TOKEN = r.json()["access_token"]
@ritchie46
ritchie46 / gist:4366135d5bdc61bdf69307001a249a99
Created January 10, 2021 15:20
run_gb_5GB_polars_10-01-2021
nodename,batch,timestamp,task,data,in_rows,question,out_rows,out_cols,solution,version,git,fun,run,time_sec,mem_gb,cache,chk,chk_time_sec,comment,on_disk
instance-2,,1610130993.9517767,groupby,G1_1e7_1e2_0_0,10000000,sum v1 by id1,100,2,polars,0.4.0,unknown,.groupby,1,0.296,0.855,TRUE,30001016,0.0,,FALSE
instance-2,,1610130994.2619028,groupby,G1_1e7_1e2_0_0,10000000,sum v1 by id1,100,2,polars,0.4.0,unknown,.groupby,2,0.287,0.847,TRUE,30001016,0.0,,FALSE
instance-2,,1610130994.8431137,groupby,G1_1e7_1e2_0_0,10000000,sum v1 by id1:id2,10000,3,polars,0.4.0,unknown,.groupby,1,0.575,0.92,TRUE,30001016,0.0,,FALSE
instance-2,,1610130995.4009216,groupby,G1_1e7_1e2_0_0,10000000,sum v1 by id1:id2,10000,3,polars,0.4.0,unknown,.groupby,2,0.552,0.924,TRUE,30001016,0.0,,FALSE
instance-2,,1610130995.930853,groupby,G1_1e7_1e2_0_0,10000000,sum v1 mean v3 by id3,100000,3,polars,0.4.0,unknown,.groupby,1,0.522,0.832,TRUE,[30001016. 5001212.36305564],0.001,,FALSE
instance-2,,1610130996.471266,groupby,G1_1e7_1e2_0_0,10000
@ritchie46
ritchie46 / gist:e81ff8816af3dd06a1515cf23f79b805
Created March 23, 2020 10:34
Remove file from git history w/ git filter-branch
git filter-branch --force --index-filter \
"git rm --cached --ignore-unmatch PATH-TO-YOUR-FILE-WITH-SENSITIVE-DATA" \
--prune-empty --tag-name-filter cat -- --all
@ritchie46
ritchie46 / rnn_minibatch.py
Created June 20, 2018 09:28
minibatches in pytorch
"""
How to do minibatches for RNNs in pytorch
Assume we feed characters to the model and predict the language of the words.
"""
def prepare_batch(x, y):
# determine the maximum word length per batch and zero pad the tensors
n_max = max([a.shape[0] for a in x])
@ritchie46
ritchie46 / index.html
Created April 30, 2018 09:23
vue-navigation_html-side
<navigator :navs="[
{name: 'page 1', id: 'link-page1'},
{name: 'page 2', id: 'link-page2'},
{name: 'page 3', id: 'link-page3'},
]" active="link-page1">
</navigator>
<div v-show="activePage === 'link-page1'">
<p>Some content</p>
</div>
@ritchie46
ritchie46 / index.js
Created April 30, 2018 09:19
vue-navigation_vue-side
import navigator from './components/navigator.vue'
let vm = new Vue({
el: "#app",
components: {
navigator
},
data: {
activePage: 'link-page1',
},
@ritchie46
ritchie46 / navigator.vue
Last active April 30, 2018 09:17
vue-navigation_component-side
<template>
<nav>
<ul class="pagination">
<li v-for="page in navs" class="page-item"
v-bind:class="{active: activeId === page.id}" v-bind:id="page.id">
<a class="page-link" v-on:click="toggle">
{{ page.name }}
</a>
</li>
</ul>