Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View slowkow's full-sized avatar
🐄
moooooo

Kamil Slowikowski slowkow

🐄
moooooo
View GitHub Profile
@hypercompetent
hypercompetent / pearson_residuals.R
Last active January 7, 2021 16:53
Pearson residuals function in R, from Lause, Berens, and Kobak
pearson_residuals <- function(counts, theta = 100) {
counts_sum0 <- as(matrix(Matrix::colSums(counts),nrow=1),"dgCMatrix")
counts_sum1 <- as(matrix(Matrix::rowSums(counts),ncol=1),"dgCMatrix")
counts_sum <- sum(counts@x)
#get residuals
mu <- (counts_sum1 %*% counts_sum0) / counts_sum
z <- (counts - mu) / sqrt(mu + mu^2/theta)
#clip to sqrt(n)
@slowkow
slowkow / needleman-wunsch.py
Last active April 3, 2024 19:46
A simple version of the Needleman-Wunsch algorithm in Python.
#!/usr/bin/env python
"""
The Needleman-Wunsch Algorithm
==============================
This is a dynamic programming algorithm for finding the optimal alignment of
two strings.
Example
-------
@jimjam-slam
jimjam-slam / tips-highlight-features.r
Last active February 13, 2022 22:58
Use case_when with geom_text to automatically label points that mmeet certain conditions (extrema, significance, etc.) #rstatstips
library(tidyverse)
library(ggrepel) # substitude geom_text for geom_text_repel if you don't want to bother with this!
mydata =
data_frame(
x = 1:10,
y = rnorm(10),
name = c('Apple', 'Banana', 'Kiwi', 'Orange', 'Watermelon',
'Grapes', 'Pear', 'Cantelope', 'Tomato', 'Satsauma')) %>%
mutate(
@1wheel
1wheel / README.md
Last active April 26, 2018 15:10
conventions-layers

d3-jetpack's d3.conventions can now create canvas and html elements. Here d3.conventions({layers: 'csd'}) makes an canvas ctx, svg and div with a shared coordinate system. Yellow shapes are drawn on canvas, cyan on svg and purple on html.

Layers are position absolutely on top of each other in the order listed in the layer string. To create an svg with two canvas elements on top:

var {layers: [svg, bg_ctx, fg_ctx]} = d3.conventions({layers: 'scc'})

Hurricane How-To describes using multiple renders for something more practical than bouncing circles.

@mcburton
mcburton / jupyter-on-a-supercomputer.md
Last active April 9, 2024 12:03
A short(ish) guide on how to get Jupyter Notebooks up and running on the Bridges supercomputer.

Running Jupyter on a Supercomputer

This quick guide for getting a Jupyter Notebook up and running on Bridges, a supercomputer managed by the Pittsburgh Supercomputing Center. Bridges is a new machine designed to accommodate non-traditional uses of High Performance Computing (HPC) resources like data science and digital humanities. Bridges is available through XSEDE, which is the system that manages access to multiple supercomputing resources. Through XSEDE, Bridges is available researchers or educators at US academic or non-profit research institutions (see the XSEDE eligibility policies) Allocations are free, but there is a somewhat difficult to understand application process filled with jargon and acronyms that take time to understand. See the XSEDE getting started guide for more information about getting acc

@slowkow
slowkow / optimize_html.py
Last active November 21, 2022 23:04
Optimize base64 encoded PNG images in an HTML file.
#!/usr/bin/env python
"""
optimize_html.py
Kamil Slowikowski
November 14, 2016
Optimize base64 encoded PNG images in an HTML file.
USAGE
@nicksantamaria
nicksantamaria / fork-example.php
Created October 20, 2016 22:35
Example: Parallel processing in PHP using pcntl_fork()
<?php
/**
* @file
* Basic demonstration of how to do parallel threads in PHP.
*/
// This array of "tasks" could be anything. For demonstration purposes
// these are just strings, but they could be a callback, class or
// include file (hell, even code-as-a-string to pass to eval()).
#AUROC calculation code
auroc<-function(score,cls){
n1<-sum(!cls); sum(cls)->n2;
U<-sum(rank(score)[!cls])-n1*(n1+1)/2;
return(1-U/n1/n2);
}
#... as a cryptic one-liner
auroc1l<-function(score,cls)
mean(rank(score)[cls]-1:sum(cls))/sum(!cls)
@mikelove
mikelove / tsne.R
Last active April 6, 2024 01:11
Exploring behavior of t-SNE on linear data
n <- 200
m <- 40
set.seed(1)
x <- runif(n, -1, 1)
library(rafalib)
bigpar(2,2,mar=c(3,3,3,1))
library(RColorBrewer)
cols <- brewer.pal(11, "Spectral")[as.integer(cut(x, 11))]
plot(x, rep(0,n), ylim=c(-1,1), yaxt="n", xlab="", ylab="",
col=cols, pch=20, main="underlying data")
@adamrecsko
adamrecsko / highlight.pipe.ts
Created May 1, 2016 20:28
Angular2 text highlight pipe
import {PipeTransform, Pipe} from 'angular2/core';
@Pipe({ name: 'highlight' })
export class HighLightPipe implements PipeTransform {
transform(text: string, [search]): string {
return search ? text.replace(new RegExp(search, 'i'), `<span class="highlight">${search}</span>`) : text;
}
}
/** Usage: