Skip to content

Instantly share code, notes, and snippets.

@orenbenkiki
orenbenkiki / Bug.jl
Created July 6, 2021 11:35
Julia Mixing Worker Processes and Threads Bug
using Distributed
@assert size(ARGS)[1] == 3
@assert ARGS[3] == "verbose" || ARGS[3] == "quiet"
local_processes = parse(Int, ARGS[1])
local_iterations = parse(Int, ARGS[2])
local_verbose = ARGS[3] == "verbose"
Distributed.addprocs(local_processes)
@orenbenkiki
orenbenkiki / closed.trace.txt
Created July 5, 2021 10:32
Errors running dt_foreach test in Snarl.jl commit 8d82051
Activating environment at `~/julia/Snarl/Project.toml`
Testing Snarl
Status `/tmp/jl_DAlxOw/Project.toml`
[d06fb421] Snarl v0.1.0 `~/julia/Snarl`
[ade2ca70] Dates `@stdlib/Dates`
[8ba89e20] Distributed `@stdlib/Distributed`
[56ddb016] Logging `@stdlib/Logging`
[9a3f8284] Random `@stdlib/Random`
[1a1011a3] SharedArrays `@stdlib/SharedArrays`
[8dfed614] Test `@stdlib/Test`
@orenbenkiki
orenbenkiki / slant.r
Last active June 4, 2020 09:37
R code for visualization of similarity matrices, by reordering them so high values move to the diagonal (become "slanted"), and optionally apply order-preserving clustering to the result.
#' Compute rows and columns orders which move high values close to the diagonal.
#'
#' For a matrix expressing the cross-similarity between two (possibly different)
#' sets of entities, this produces better results than clustering (e.g. as done
#' by \code{pheatmap}). This is because clustering does not care about the order
#' of each two sub-partitions. That is, clustering is as happy with \code{((2, 1),
#' (4, 3))} as it is with the more sensible \code{((1, 2), (3, 4))}. As a result,
#' visualizations of similarities using naive clustering can be misleading.
#'
#' @param data A rectangular matrix.
@orenbenkiki
orenbenkiki / plotly_fast_large_heatmap.py
Last active August 12, 2019 14:46
Plotly Dash Fast Large Heatmap
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import plotly.graph_objs as go
import pandas as pd
import numpy as np
from math import ceil
from math import floor
@orenbenkiki
orenbenkiki / code.rs
Last active December 20, 2015 22:49
macro_export not working?
mod code {
use macros; // compiler warning: unused import :-(
#[test]
fn asserts() {
assert_eq!(1, 1);
assert_ne!(1, 2); // compiler error: macro undefined :-(
}
}
/// Intern a string using the task local interner.
pub fn intern(burrowed: &str) -> Intern {
do local_data::get(KEY_ARC_INTERNER) |maybe_arc_interner| {
match maybe_arc_interner {
None => fail!("no task local ARC for global interner"),
Some(arc_interner) => {
// TRICKY: Only obtain a read lock for the common case
// where the string was previously interned.
do arc_interner.read |interner| {
match interner.str_to_intern.find(&burrowed.to_str()) {
src/anthill/intern.rs:71:24: 73:25 error: instantiating a type parameter with an incompatible type `intern::intern::Interner`, which does not fulfill `Send+Freeze`
src/anthill/intern.rs:71 do arc_interner.read |interner| {
src/anthill/intern.rs:72 interner.id_to_str[self.id].clone()
src/anthill/intern.rs:73 }
src/anthill/intern.rs:88:20: 108:21 error: instantiating a type parameter with an incompatible type `intern::intern::Interner`, which does not fulfill `Send+Freeze`
src/anthill/intern.rs:88 do arc_interner.read |interner| {
src/anthill/intern.rs:89 match interner.str_to_intern.find(&burrowed.to_str()) {
src/anthill/intern.rs:90 Some(intern) => *intern,
src/anthill/intern.rs:91 None => {
src/anthill/intern.rs:92 // TRICKY: If we didn't find it above, we need
$ rustc --lib src/atom/crate.rs
src/anthill/atom.rs:3:4: 5:5 warning: missing documentation for a struct
src/anthill/atom.rs:3 pub struct Atom {
src/anthill/atom.rs:4 priv id: int,
src/anthill/atom.rs:5 }
src/anthill/crate.rs:4:7: 4:18 note: lint level defined here
src/anthill/crate.rs:4 #[warn(missing_doc)]
^~~~~~~~~~~
warning: missing crate link meta `name`, using `crate` as default
warning: missing crate link meta `vers`, using `0.0` as default
@orenbenkiki
orenbenkiki / gist:5189329
Created March 18, 2013 18:01
Enhanced mix cover (generate index.html, and more)
defmodule Mix.Tasks.Test do
use Mix.Task
@shortdoc "Run a project's tests"
@moduledoc """
Run the tests for a project.
This task will preload the `test/test_helper.exs` which
should do all testing setup and then require all files
@orenbenkiki
orenbenkiki / enhanced_extension.ex
Last active September 12, 2024 04:08
Elixir module inheritance
defmodule Extension do
defmacro extends(module) do
# As above...
end
defmacro implements(module, protocol: protocol) do
quote do
defimpl unquote(protocol), for: unquote(module) do
import Extension