Skip to content

Instantly share code, notes, and snippets.

View cdiener's full-sized avatar
👨‍🔬
Researching 'em microbes...

Christian Diener cdiener

👨‍🔬
Researching 'em microbes...
View GitHub Profile
@cdiener
cdiener / setup_qiime2.py
Last active August 10, 2023 13:57
Set up Qiime 2 on Google colab
#!/usr/bin/env python3
"""Set up Qiime 2 on Google colab.
Do not use this on o local machine, especially not as an admin!
"""
import os
import sys
import shutil
@cdiener
cdiener / asciinator.py
Last active January 5, 2023 17:24
Convert image to ascii art
import sys; from PIL import Image; import numpy as np
chars = np.asarray(list(' .,:;irsXA253hMHGS#9B&@'))
if len(sys.argv) != 4: print( 'Usage: ./asciinator.py image scale factor' ); sys.exit()
f, SC, GCF, WCF = sys.argv[1], float(sys.argv[2]), float(sys.argv[3]), 7/4
img = Image.open(f)
S = ( round(img.size[0]*SC*WCF), round(img.size[1]*SC) )
img = np.sum( np.asarray( img.resize(S) ), axis=2)
@cdiener
cdiener / overload.R
Last active July 7, 2022 19:37
R operator overloading
a = "bla"
b = "so on"
class(a) = append("my_class", class(a))
'+.my_class' = function(x,y) paste(x,y,sep=" and ")
print(a+b)
@cdiener
cdiener / per_sample.ipynb
Created June 10, 2021 18:18
MICOM per sample diets
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@cdiener
cdiener / asciinator.py
Created April 13, 2014 03:11
asciinator.py now with documentation
# This line imports the modules we will need. The first is the sys module used
# to read the command line arguments. Second the Python Imaging Library to read
# the image and third numpy, a linear algebra/vector/matrix module.
import sys; from PIL import Image; import numpy as np
# This is a list of characters from low to high "blackness" in order to map the
# intensities of the image to ascii characters
chars = np.asarray(list(' .,:;irsXA253hMHGS#9B&@'))
# Check whether all necessary command line arguments were given, if not exit and show a
@cdiener
cdiener / install_python.md
Last active January 20, 2018 15:14
Como instalar Python y Jupyter

Como instalar Python y Jupyter

Para las siguientes clases vamos a usar Python como nuestro lenguaje de programación preferido. En particular, vamos a usar la versión 3 de Python y las libretas de Jupyter. Para ya tener una instalación funcional en la clase, aquí hay unas pistas para la instalación. Para la instalación en Windows y Mac vamos a usar la versión de Anaconda mientras que para Linux usamos la versión nativa de Python.

Para Windows

@cdiener
cdiener / install.md
Last active November 9, 2017 04:25
Como instalar docker para la clase de Desafio LatAm.

Instalación de Docker

Lo primero que tienes que saber sobre la instalación de docker es que para Mac y windows hay dos versiones de docker:

  1. una versión legacy que usa maquinas virtuales (VM) para correr docker adentro de una maquina virtual.
  2. una versión nativa que usa una capa de compatibilidad (HyperKit + Hypervisor en Mac y Hyper-V en Windows) para correr docker directamente con el kernel nativo

La versión nativa (opción 2) tiene menos overhead y corre más rapido pero pone mas restricciones a su OS. Por el momento yo recomiendo que usan esta versión en Mac y Linux y la version legacy (opcion 1) en Windows.

@cdiener
cdiener / orlitsky.R
Created September 1, 2017 21:40
Source code for my blog post
library(data.table)
library(ggplot2)
library(magrittr)
library(pbapply)
large <- fread("ERR260132_genes.csv")
#' Sample a rarefied version of a count vector.
#'
#' @param x A named vector of counts.
@cdiener
cdiener / settings.json
Created June 16, 2017 20:46
My vscode settings....
{
"workbench.colorTheme": "Sublime Material Theme - Dark",
"workbench.iconTheme": "material-icon-theme",
"editor.fontFamily": "'Fira Mono', monospace",
"editor.fontSize": 17,
"editor.rulers": [80],
"window.zoomLevel": 0,
"window.menuBarVisibility": "toggle",
// Settings for Python
@cdiener
cdiener / compare.py
Last active March 6, 2017 18:55
Compare pytest benchmarks
import json
import pandas as pd
from sys import argv, exit
def benchmark_to_df(json_file):
with open(json_file) as jf:
content = json.load(jf)
df = pd.DataFrame(columns=("test", "time [ms]"))
for b in content["benchmarks"]: