Skip to content

Instantly share code, notes, and snippets.

Avatar

Oren Ben-Kiki orenbenkiki

View GitHub Profile
@orenbenkiki
orenbenkiki / slant.r
Last active Jun 4, 2020
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.
View slant.r
#' 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 Aug 12, 2019
Plotly Dash Fast Large Heatmap
View plotly_fast_large_heatmap.py
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 Dec 20, 2015
macro_export not working?
View code.rs
mod code {
use macros; // compiler warning: unused import :-(
#[test]
fn asserts() {
assert_eq!(1, 1);
assert_ne!(1, 2); // compiler error: macro undefined :-(
}
}
View Upgrade read lock to write lock - take 1
/// 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()) {
View Errors
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
View Shell Results
$ 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 Mar 18, 2013
Enhanced mix cover (generate index.html, and more)
View gist:5189329
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 Oct 19, 2020
Elixir module inheritance
View enhanced_extension.ex
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
@orenbenkiki
orenbenkiki / http.ex.patch
Created Feb 23, 2013
Patch expm http.ex to pass http proxy settings to hackney
View http.ex.patch
diff --git a/lib/repositories/http.ex b/lib/repositories/http.ex
index 2dae690..bdb1ece 100644
--- a/lib/repositories/http.ex
+++ b/lib/repositories/http.ex
@@ -9,7 +9,7 @@ defrecord Expm.Repository.HTTP, url: "https://expm.co", username: nil, password:
{"accept", "text/html"},
{"user-agent", "expm/#{Expm.version}"},
],
- "", [follow_redirect: true, force_redirect: true])
+ "", Expm.Repository.HTTP.Decoder.proxy(follow_redirect: true, force_redirect: true))
@orenbenkiki
orenbenkiki / gist:4027328
Created Nov 6, 2012
lein autodoc can't find "sh"
View gist:4027328
Exception in thread "main" java.lang.IllegalAccessError: sh does not exist
at clojure.core$refer.doInvoke(core.clj:3778)
at clojure.lang.RestFn.applyTo(RestFn.java:139)
at clojure.core$apply.invoke(core.clj:603)
at clojure.core$load_lib.doInvoke(core.clj:5279)
at clojure.lang.RestFn.applyTo(RestFn.java:142)
at clojure.core$apply.invoke(core.clj:603)
at clojure.core$load_libs.doInvoke(core.clj:5298)
at clojure.lang.RestFn.applyTo(RestFn.java:137)
at clojure.core$apply.invoke(core.clj:605)
You can’t perform that action at this time.