Skip to content

Instantly share code, notes, and snippets.

How do I convert an expression back into a series

I'd like to convert an expression into its output, particularly as a series. I couldn't find anything in the docs for doing so. I've got the following:

import polars as pl
from polars_general_plugin import get_len_keep_odd
@bnm3k
bnm3k / knapsack.rs
Created February 10, 2024 17:54
Solve knapsack in rust
struct Input {
values: Vec<u32>,
weights: Vec<u32>,
num_items: usize,
capacity: u32,
}
// returns a vector containing the indices of items selected
fn solve_knapsack(ip: &Input) -> (u32, Vec<usize>) {
let mut table = Vec::with_capacity(ip.num_items + 1);
@bnm3k
bnm3k / stitch_sso_python.md
Created August 24, 2022 12:01
Stitch.money SSO with Python

Using Python for Stitch SSO

Overview

This post goes through user Stitch SSO for python-based backends. It covers pretty much the same ground as the Stitch docs but uses Python instead of browser-based Javascript. It should be of help for anyone trying to integrate Stitch in their backend server. Before proceeding, make sure you have both a client_id and client_secret- they are provided by Stitch

This is directly based on the Redpanda docs for Data Transforms link.

You should probably start from there to get a rough idea of where data transforms fit in.
The following steps are for if you want to try out transforms within a single-node docker container, e.g. as part of a testing pipeline. Some if not most of the steps can be moved into the image building stage.

Start the RedPanda container:

IMAGE_TAG_REDPANDA:='docker.redpanda.com/vectorized/redpanda:latest'
CONTAINER_TAG_REDPANDA:=redpanda-1

If you're using the neovim plugin aerial and want to override the default key bindings without modifying ftplugin/aerial.vim, replace the keys table as follows:

require("aerial.bindings").keys = {
	{ "<CR>", "<cmd>lua require'aerial'.select()<CR>", "Jump to the symbol under the cursor" },
  -- and so on for the rest
}

Make sure to use the format that aerial uses in aerial/binding.lua. Also make sure that setup is called after, not before overriding keys, and that default_bindings is set to true

@bnm3k
bnm3k / ts_indexing.md
Last active January 11, 2022 14:24
Postgres indexing for overlaps operator doesn't work
@bnm3k
bnm3k / ex3.sql
Created January 9, 2022 20:01
SQL Recursive queries: solution for exercise 3 (https://habr.com/en/company/postgrespro/blog/490228/)
with recursive p(hops, flights, last_stop, last_arrival, total_duration, closest, found) as (
select *
from (
select
array[departure_airport, arrival_airport] as hops,
array[flight_no] as flights,
arrival_airport as last_stop,
scheduled_arrival as last_arrival,
scheduled_arrival - scheduled_departure as total_duration,
rank() over(
@bnm3k
bnm3k / radix.go
Created June 28, 2021 23:53
radix sort adopted from questdb
// RadixSort ...
// credits QuestDB impl for radix sort (7104a57)
// core/src/main/c/share/ooo.cpp
func RadixSort(array []uint64) {
if len(array) <= 100 {
insertionSort(array)
return
}
// counts
type rscounts struct {
@bnm3k
bnm3k / mqtt_generate_topics_V3.go
Created July 21, 2020 14:14
Most space-efficient MQTT topic generation. This one skips the tree building step entirely and goes straight to emitting. Compare with V1 and V2 gists
package main
import (
"fmt"
"strings"
)
func generateTopicStrings(tokens []string) (generatedTopics []string) {
// the expected no. of generated topics. See either of the previous
// gists for explanation as to why this formula is used
@bnm3k
bnm3k / mqtt_generate_topics_V2.go
Created July 21, 2020 14:03
An even more space-efficient means of generating all the possible combination of MQTT wildcards and token arrangements for a given. Uses structural sharing of nodes wherever possible. Compare with first version
package main
import (
"fmt"
"strings"
)
type node struct {
val string
exact *node