Skip to content

Instantly share code, notes, and snippets.

@nico-zck
nico-zck / argsort.h
Last active February 1, 2023 05:07
Parallel argsort via c++ built-in parallel mode.
// #include <algorithm> // std::sort, std::stable_sort
#include <parallel/algorithm>
void argsort(unsigned long *pidx, const double *parr, unsigned long length)
{
// Sort indexes based on comparing values in v
// Because Cython pass data blob as pointer, so access the array as pointer style.
unsigned long *pidx2 = pidx + length;
// double *parr2 = parr + length;
__gnu_parallel::sort(pidx, pidx2,
@nico-zck
nico-zck / parallelsort.md
Last active February 1, 2023 05:58
Make Python could access c++ built-in parallel in-place sort via Cython.

build:

python3 setup.py build_ext -if

using:

from parallelsort import parallelsort
import numpy as np

arr = np.random.uniform(0,100,100000000)
@nico-zck
nico-zck / bash-history-to-zsh-history.py
Last active March 10, 2021 08:15 — forked from op/bash-history-to-zsh-history.py
Bash history to Zsh history
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''simply copy to python command line and press enter.'''
import time
from os.path import expanduser
timestamp = None
@nico-zck
nico-zck / 1pass_to_bitwarden.py
Created February 2, 2021 06:14
Convert 1pass exported file to Bitwarden supported csv file.
import json
import pandas as pd
try:
with open("data.1pif", "r") as f:
lines = f.readlines()
lines = [l for l in lines if not l.startswith("***")]
data = json.loads("[" + ",".join(lines) + "]")
except: