Skip to content

Instantly share code, notes, and snippets.

@alendit
alendit / CMakeLists.txt
Last active November 20, 2018 06:49
Building 1kk string of 10 chars each in arrow-cpp
cmake_minimum_required(VERSION 3.10)
LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/arrow/cpp/cmake_modules")
find_package(Arrow)
include_directories(${ARROW_INCLUDE_DIR})
MESSAGE( STATUS ${ARROW_INCLUDE_DIR})
@alendit
alendit / gist:32ebfbc1e5a4c2ff3190ed8b77e0a990
Created November 19, 2018 15:47
Build 1kk string with 10 chars each using numba builder.
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import numpy as np"
@alendit
alendit / handle.cpp
Created October 8, 2018 16:26
`new_handle` / `from_handle` example script
// compile with g++ -fpic -shared handle.cpp -o libhandle.so
#include <cstdint>
extern "C" {
using LuaHandle = uint64_t;
LuaHandle maybe(LuaHandle h, bool ret) {
if (ret) return h;
return 0;
}
}
@alendit
alendit / call_printf.py
Last active March 9, 2024 16:49
Call c `printf` from llvmlite
import llvmlite.ir as ir
import llvmlite.binding as llvm
from ctypes import CFUNCTYPE
def main():
m = ir.Module()
func_ty = ir.FunctionType(ir.VoidType(), [])
i32_ty = ir.IntType(32)
func = ir.Function(m, func_ty, name="printer")
@alendit
alendit / composable.py
Created April 24, 2018 09:12
Haskell-like composition for python functions
def composable(func, contains=None):
class Wrapper:
@wraps(func)
def __call__(self, *args, **kwargs):
return func(*args, **kwargs)
def __getattr__(self, name):
if name in locals():
comp = locals[name]
elif name in globals():
comp = globals()[name]
@alendit
alendit / rb_stream_rw.cpp
Created April 17, 2018 08:00
RecordBatch stream writing and reading
#include <arrow/buffer.h>
#include <arrow/builder.h>
#include <arrow/io/memory.h>
#include <arrow/ipc/reader.h>
#include <arrow/ipc/writer.h>
#include <arrow/memory_pool.h>
#include <arrow/record_batch.h>
#include <arrow/type.h>
@alendit
alendit / buffer_slices2.cpp
Created April 11, 2018 11:39
MutableSlices failing after dealloc
#include <arrow/buffer.h>
#include <memory>
#include <iostream>
using namespace arrow;
using namespace std;
auto main(int argc, char* argv[]) -> int {
int64_t size = 16;
auto* memory = static_cast<uint8_t*>(malloc(size));
@alendit
alendit / buffer_test.cpp
Last active April 11, 2018 06:59
BufferSlices crash
#include <arrow/buffer.h>
#include <memory>
#include <iostream>
using namespace arrow;
using namespace std;
auto main(int argc, char* argv[]) -> int {
auto pool_buffer = make_shared<PoolBuffer>(default_memory_pool());
pool_buffer->Resize(16);
@alendit
alendit / status_benchmark.cpp
Last active April 5, 2018 13:17
Benchmark for the arrow::Status destructor slowdown. Must be compiled with `-lbenchmark` (google benchmark).
#include <arrow/status.h>
#include <benchmark/benchmark.h>
#include <string>
#include <iostream>
using namespace arrow;
#define REPEAT_N(N, BODY) \
for (int idx=0;idx<N;++idx) { \
BODY \
@alendit
alendit / gist:4a3b456f7092f1d6c94b5c357f944ac3
Created October 1, 2017 14:18
Bundestagswahl 2017: der Bundeswahlleister-Scrapper
{
"cells": [
{
"cell_type": "code",
"execution_count": 32,
"metadata": {},
"outputs": [],
"source": [
"import requests\n",
"import bs4\n",