Skip to content

Instantly share code, notes, and snippets.

@acthp
acthp / fizzbizz
Last active August 29, 2015 14:09
clojure fizzbizz
(defn fizzbizz [x]
(reduce (fn [a [s d]] (get [s] (mod x d) a))
x
[["bizz" 5]["fizz" 3]["fizzbizz" 15]]))
@acthp
acthp / bean.clj
Last active August 29, 2015 14:10
clojure bean macro
(let [t (fn [type prop] ; type hint a property
(with-meta prop {:tag type}))
cc (fn [prop] ; camel-case a property
(str (.toUpperCase (subs (str prop) 0 1)) (subs (str prop) 1)))
m (fn [prop method] ; construct method name for property
(symbol (str method (cc prop))))
bean-interface (fn [bean-name & props] ; define interface for bean
(let [set (fn [type prop]
`(~(m prop 'set) [~(t type 's)]))
@acthp
acthp / spark.clj
Created November 25, 2014 01:28
experimental clojure wrapper for SparkSQL
(ns try-spark.spark
(:refer-clojure :exclude [map filter reduce first name take min distinct max count])
(:require [clojure.core :as core])
(:require [clojure.reflect :as r])
(:import org.apache.spark.sql.api.java.JavaSchemaRDD))
; Parameter classes that we have to wrap in order to
; call rdd methods with plain clojure functions.
(def func-types
(into #{}
@acthp
acthp / loaderPlugin.js
Created August 31, 2012 19:14
requirejs (AMD) loader plugin for jstestdriver
(function() {
var loadSource = function(file, onSourceLoad) {
if (!file.fileSrc.match(/js-test/)) {
return false;
}
require([file.fileSrc], function() {
onSourceLoad({file: file, success: true, message: ''});
}, function(err) {
@acthp
acthp / haml.js
Created February 10, 2013 04:08
Wrap requirejs text plugin so it will compile haml templates during development. Doesn't work during build.
define(['text', 'lib/haml'], function(text, haml) {
var plugin = Object.create(text); // inherit methods of the text loader
function wrapload(fn) {
return function(value) {
fn(haml.compileHaml({source: value}));
}
}
function load(name, req, onload, config) {
@acthp
acthp / haml2.js
Created February 10, 2013 21:15
Wrap requirejs text plugin for compiling haml. Works around dependency loading problems in r.js by detecting node and using the node loader. However the resulting javascript blob appears to deadlock. The callback for the request() call never executes.
// haml loader for requirejs
(function() {
function register(text, haml) {
var plugin = Object.create(text); // inherit methods of the text loader
function wrapload(fn) {
return function(value) {
fn(haml.compileHaml({source: value}));
}
describe.only('example', function () {
it('should find visible element, low arity', function () {
browser.execute(function () {
document.body.innerHTML = '<div id="a" class="a">foo</div><div id="b">blah</div>';
});
// We pretend we're waiting on a list of dom elements to be
// created.
browser.waitUntil(
() => browser.elements('//*[@class="a"]').value.length > 0,
@acthp
acthp / core_test.clj
Created October 16, 2017 00:06
test.check shrinking of 2d matrix
(ns matrix-test.core-test
(:require [clojure.test :refer :all]
[clojure.test.check :as tc]
[clojure.test.check.generators :as gen]
[clojure.test.check.properties :as prop]
[matrix-test.core :refer :all]))
(def element gen/int)
(defn matrix-size [[w h]]
@acthp
acthp / pancan_example.py
Created April 13, 2018 19:06
fetch gene expression and mutation from Pancan Atlas cohort
import xenaPython as xena
host = xena.PUBLIC_HUBS["pancanAtlasHub"]
cohort ="TCGA PanCanAtlas"
samples = xena.cohort_samples(host, cohort, None)
genes = ["FOXM1", "TP53"]
expression_dataset = "EB++AdjustPANCAN_IlluminaHiSeq_RNASeqV2.geneExp.xena"
[foxm1_expresssion_by_sample, tp53_expression_by_sample] = xena.dataset_fetch(host, expression_dataset, samples, genes)
@acthp
acthp / example.ipynb
Last active September 20, 2023 06:14
pancan and toil notebook
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.