Skip to content

Instantly share code, notes, and snippets.

View carbocation's full-sized avatar

James Pirruccello carbocation

View GitHub Profile
@carbocation
carbocation / invnorm.R
Last active September 16, 2021 13:49
invnorm
# See Yang et al Nature 2012 https://www.nature.com/articles/nature11401
# supplement page 18
invnorm <- function(x) {
qnorm((rank(x, na.last="keep")-0.5)/sum(!is.na(x)))
}
@carbocation
carbocation / install-shairport-sync.md
Created July 10, 2021 01:02
Install shairport-sync on RPi

Simple Installation Instructions

Here are simple instructions for building and installing Shairport Sync on a Raspberry Pi B, 2B, 3B, 3B+ or 4B. It is assumed that the Pi is running Raspbian Buster Lite – a GUI isn't needed, since Shairport Sync runs as a daemon program. For a more thorough treatment, please go to the README.md page.

In the commands below, note the convention that a # prompt means you are in superuser mode and a $ prompt means you are in a regular unprivileged user mode. You can use sudo ("SUperuser DO") to temporarily promote yourself from user to superuser, if permitted. For example, if you want to execute apt-get update in superuser mode and you are in user mode, enter sudo apt-get update.

Configure and Update

Do the usual update and upgrade:

# apt-get update
@carbocation
carbocation / roundFormatC.R
Created June 21, 2021 21:14
Blends round() and formatC() for my specific needs.
roundFormatC <- function(x, digits) {
formatCDigits <- digits
if(digits <= 0) {
formatCDigits <- 0
}
formatC(round(x, digits), formatCDigits, format = "f")
}
@carbocation
carbocation / extreme-P.R
Last active December 16, 2023 21:50
Compute extreme P values from Z scores or T scores and degrees of freedom. Note: these are two-tailed (log(2) + ...) where two-tailed tests are appropriate. The Z and T functions can be run online at https://tools.carbocation.com/ExtremeP
# Via https://stackoverflow.com/a/46416222/199475
pvalue.extreme.z <- function(z) {
log.pvalue <- log(2) + pnorm(abs(z), lower.tail = FALSE, log.p = TRUE)
log10.pvalue <- log.pvalue/log(10) ## from natural log to log10
mantissa <- 10^(log10.pvalue %% 1)
exponent <- log10.pvalue %/% 1
return(list(mantissa=mantissa,exponent=exponent))
}
# Modified to the t-score approach from the Z-score based approach on https://stackoverflow.com/a/46416222/199475
@carbocation
carbocation / multi-face.ipynb
Created January 3, 2020 17:13 — forked from yang-zhang/multi-face.ipynb
Multi-task Deep Learning Experiment using fastai Pytorch
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@carbocation
carbocation / Fast.ai install script.py
Last active September 27, 2018 05:02 — forked from gilrosenthal/Fast.ai install script
Fast.ai Install on Google Colab
!pip install pathlib
!pip install fastai
!apt-get -qq install -y libsm6 libxext6 && pip install -q -U opencv-python
import cv2
from os import path
from wheel.pep425tags import get_abbr_impl, get_impl_ver, get_abi_tag
platform = '{}{}-{}'.format(get_abbr_impl(), get_impl_ver(), get_abi_tag())
accelerator = 'cu80' if path.exists('/opt/bin/nvidia-smi') else 'cpu'
@carbocation
carbocation / Subtitle.go
Created July 13, 2018 14:35 — forked from bemasher/Subtitle.go
Subtitle decoder basic functionality written in Golang.
package main
import (
"io"
"os"
"fmt"
"log"
"bytes"
"image"
"image/png"
@carbocation
carbocation / loghistplot.R
Last active February 14, 2018 02:22 — forked from sckott/loghistplot.R
Plot logistic regression with bar plots for distribution of 0 and 1 values on top and bottom x-axes.
# Define the function
loghistplot <- function(data) {
require(ggplot2); require(gridExtra) # load packages
names(data) <- c('x','y') # rename columns
# get min and max axis values
min_x <- min(data$x)
max_x <- max(data$x)
2006-1 8.040729483282673
2006-2 8.00303951367781
2006-3 8.016413373860182
2006-4 8.010334346504559
2006-5 8.012765957446808
2006-6 7.9969604863221875
2006-7 7.999392097264437
2006-8 7.982370820668692
2006-9 8.0370820668693
2006-10 8.038297872340424
@carbocation
carbocation / gist:17af347fd38bb302dafc21f77832e4b5
Last active October 22, 2017 16:50 — forked from bigsnarfdude/gist:95c19664f5f8aa5b8b403308c5d42b23
training tensorflow and saving my MNIST model
import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
#import data
mnist = input_data.read_data_sets("data/", one_hot=True)
sess = tf.InteractiveSession()
# Create the model
x = tf.placeholder(tf.float32, [None, 784])