Skip to content

Instantly share code, notes, and snippets.

@Sh4pe
Sh4pe / build.zig
Last active February 21, 2022 20:59
Zig compilation problem. Place main.zig in folder src.
const std = @import("std");
pub fn build(b: *std.build.Builder) void {
const exe = exe: {
const target = b.standardTargetOptions(.{});
const mode = b.standardReleaseOptions();
const e = b.addExecutable("foo", "src/main.zig");
e.setTarget(target);
// Count unique values for each tag in a bucket
import "influxdata/influxdb/schema"
cardinalityByTag = (bucket) =>
schema.tagKeys(bucket: bucket)
|> map(fn: (r) => ({
tag: r._value,
_value:
if contains(set: ["_stop","_start"], value:r._value) then 0
else (schema.tagValues(bucket: bucket, tag: r._value)
import Random
function generate_pairs(names)
while true
candidates = zip(names, Random.shuffle(names)) |> collect
# Only take those permutations without fixed point, i.e.
# noone has to buy a present for herself/himself
if findfirst(p -> p[1] == p[2], candidates) === nothing
return candidates
ERROR: LoadError: Call to XGBoost C function XGBoosterPredict failed: [21:13:09] /workspace/srcdir/xgboost/src/c_api/c_api.cc:498: DMatrix/Booster has not been intialized or has already been disposed.
Stack trace:
[bt] (0) /home/XXX/.julia/artifacts/51760a35c00d03a1b2ee373a49af64d08700a64a/lib/libxgboost.so(dmlc::LogMessageFatal::~LogMessageFatal()+0x61) [0x7f7b0fddb2d1]
[bt] (1) /home/XXX/.julia/artifacts/51760a35c00d03a1b2ee373a49af64d08700a64a/lib/libxgboost.so(XGBoosterPredict+0x183) [0x7f7b0fdd4303]
[bt] (2) [0x7f7b1040bfd9]
[bt] (3) [0x7f7b1040c679]
[bt] (4) [0x7f7b1040c79e]
[bt] (5) /opt/julia/julia-1.5.2/bin/../lib/libjulia.so.1(jl_apply_generic+0x6f3) [0x7f7b45a1c163]
[bt] (6) [0x7f7b1040bee1]
[bt] (7) [0x7f7b1040bf5d]
### A Pluto.jl notebook ###
# v0.11.8
using Markdown
using InteractiveUtils
# ╔═╡ 0b752c76-e6fa-11ea-3929-835e1cde79d8
begin
import Pkg; Pkg.activate(".")
using DataFrames
@Sh4pe
Sh4pe / draw.jl
Created June 30, 2020 14:01
Draw on background image in Julia using Cairo.jl
using FileIO
using Images
import Cairo
function with_background(f, filename::String)
ctx = nothing
surf = nothing
try
img_raw = load(filename)
@Sh4pe
Sh4pe / reduce_df.py
Created April 26, 2019 18:39
Reduce over DataFrames with the same index
import numpy.random as npr
import pandas as pd
from functools import reduce
def get_dfs():
for i in range(10):
yield pd.DataFrame(index=npr.permutation(10), data={f'c_{i}': npr.rand(10)})
def reducer(acc, x):
merged = acc.merge(x, left_index=True, right_index=True, indicator=True, how='outer')
@Sh4pe
Sh4pe / compile_error.txt
Created April 28, 2018 18:22
Problems with clippy
% cargo +nightly build --features "clippy"
Compiling clippy_lints v0.0.195
error[E0432]: unresolved import `syntax::abi`
--> /Users/david/.cargo/registry/src/github.com-1ecc6299db9ec823/clippy_lints-0.0.195/src/functions.rs:8:13
|
8 | use syntax::abi::Abi;
| ^^^ Could not find `abi` in `syntax`
error[E0432]: unresolved import `syntax::abi`
--> /Users/david/.cargo/registry/src/github.com-1ecc6299db9ec823/clippy_lints-0.0.195/src/needless_pass_by_value.rs:9:13
@Sh4pe
Sh4pe / Vagrantfile
Last active April 27, 2018 06:13
Problems with bcc inside virtual machine
# -*- mode: ruby -*-
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/xenial64"
config.vm.provider "virtualbox" do |vb|
vb.memory = "8192"
vb.cpus = 4
end
# These env vars are not important for my example, contained here
concatLeft :: Char -> C.ByteString -> C.ByteString
concatLeft delim a = go $ C.uncons a
where bsa = C.singleton delim
go Nothing = bsa
go (Just (delim, r)) = concatLeft delim r
go (Just (x, r)) = C.concat [bsa, r]
-- Warning:
-- Pattern match(es) are overlapped
-- In an equation for ‘go’: go (Just (x, r)) = ...