Skip to content

Instantly share code, notes, and snippets.

// Please find the full, tested version in
// https://github.com/influxdata/influxdb_iox/blob/fe155e15fb2ad166aee66b0458e63c24a8128dd4/query/src/exec/task.rs#L101-L118
pub struct DedicatedExecutor {
state: Arc<Mutex<State>>,
}
/// Runs futures (and any `tasks` that are `tokio::task::spawned` by
/// them) on a separate Tokio Executor
struct State {
# -*- coding: utf-8 -*-
""" Deletes all tweets below a certain retweet threshold.
"""
import tweepy
from datetime import datetime
# Constants
CONSUMER_KEY = ''
@lu4nm3
lu4nm3 / main.rs
Last active January 16, 2024 09:38
Tokio Async: Concurrent vs Parallel
use futures::StreamExt;
use std::error::Error;
use tokio;
use tokio::macros::support::Pin;
use tokio::prelude::*;
use tokio::time::{Duration, Instant};
pub fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut multi_threaded_runtime = tokio::runtime::Builder::new()
.threaded_scheduler()
@danr
danr / plug.kak
Created March 5, 2017 16:57
simple Kakoune plugin manager
def plug -params 1 %{
%sh{
# Check out the repo to ~/build if it does not exist
if [[ ! -d $HOME/build/$1 ]]; then
(cd $HOME/build; git clone https://github.com/$1)
fi
# Source all .kak files in it
for file in $(echo $HOME/build/$(basename $1)/*.kak); do
echo source "$file"
done
@rjurney
rjurney / apply.py
Created December 21, 2016 21:23
Plot a pyspark.RDD.histogram as a pyplot histogram (via bar)
%matplotlib inline
buckets = [-87.0, -15, 0, 30, 120]
rdd_histogram_data = ml_bucketized_features\
.select("ArrDelay")\
.rdd\
.flatMap(lambda x: x)\
.histogram(buckets)
create_hist(rdd_histogram_data)
Generativity Thought Experiment
Suppose I want to generate something, maybe:
- a number
- a string
- a list of numbers
- a set of parameters that define a 3d model
- a game level
- a poem
- a story
@ttsiodras
ttsiodras / protocol_via_coroutines.py
Last active January 1, 2024 06:03
The cleanest way (I've ever seen) to implement state machines in Python
#!/usr/bin/env python3
# Based on a great article from Eli Bendersky:
#
# http://eli.thegreenplace.net/2009/08/29/co-routines-as-an-alternative-to-state-machines/
#
# I just "ported" to Python3 (still using plain old yield) and added the proper type annotations,
# since Python 3.5 can now support them (and mypy can check them):
#
# $ mypy --disallow-untyped-defs protocol_via_coroutines.py
{-# LANGUAGE TemplateHaskell #-}
module Data.Integer.FibonacciStack where
import Control.Monad.State
import Control.Lens
naiveFib :: Int -> Integer
naiveFib 0 = 0
naiveFib 1 = 1
naiveFib n = naiveFib (n-1) + naiveFib (n-2)
module Data.Vector.FindMax where
import Data.Vector (Vector, (!), (!?))
import qualified Data.Vector as V
import Data.Maybe (fromMaybe)
findMax :: Vector Int -> Maybe Int
findMax v
| V.null v = Nothing
| pivotValue > leftValue && pivotValue > rightValue = Just pivotValue
module Data.Integer.EveryOther where
genericEveryOther :: Monoid a => [a] -> [a]
genericEveryOther [] = []
genericEveryOther xs = zipWith mappend (scanl mappend mempty (init xs)) (scanr mappend mempty (tail xs))
everyOther :: [Int] -> [Int]
everyOther [] = []
everyOther xs = zipWith (*) (scanl (*) 1 (init xs)) (scanr (*) 1 (tail xs))