Skip to content

Instantly share code, notes, and snippets.

View martinholub's full-sized avatar

Martin Holub martinholub

View GitHub Profile
# !/usr/bin/env python
# encoding: utf-8
from enum import Enum
import serial
import argparse
import logging
import Colorer
import csv
@deehzee
deehzee / autoreload.md
Last active December 1, 2021 19:48
Auto reload of modules in jupyter notebook

Module autoreload

To auto-reload modules in jupyter notebook (so that changes in files *.py doesn't require manual reloading):

# for auto-reloading external modules
# see http://stackoverflow.com/questions/1907993/autoreload-of-modules-in-ipython
%load_ext autoreload
%autoreload 2
@danijar
danijar / blog_tensorflow_scope_decorator.py
Last active January 17, 2023 01:58
TensorFlow Scope Decorator
# Working example for my blog post at:
# https://danijar.github.io/structuring-your-tensorflow-models
import functools
import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
def doublewrap(function):
"""
A decorator decorator, allowing to use the decorator to be used without
@brandoncurtis
brandoncurtis / AnalogReadSerial.ino
Last active January 29, 2024 20:47
Realtime Data Acquisition and Plotting with Arduino and Python
/*
AnalogReadSerial
Reads an analog input on pin 0, prints the result to the serial monitor.
Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
This example code is in the public domain.
Upload this to the Arduino using the Arduino IDE!
*/
@1pakch
1pakch / line_profiler_usage.py
Created April 14, 2015 11:08
Python: using line_profiler on functions outside top-level module/script
# A standard way to use Robert Kern's line profiler
# https://github.com/rkern/line_profiler
# is to wrap a function of interest using the @profile decorator
# and then to run the script via
# kernprof -l script_to_profile.py
# or
# python -m line_profiler script_to_profile.py.lprof
#
# This approach does not work, however if the function of interest
# is defined outside of the top-level script (or module) since @profile
@Zearin
Zearin / python_decorator_guide.md
Last active March 30, 2024 12:28
The best explanation of Python decorators I’ve ever seen. (An archived answer from StackOverflow.)

NOTE: This is a question I found on StackOverflow which I’ve archived here, because the answer is so effing phenomenal.


Q: How can I make a chain of function decorators in Python?


If you are not into long explanations, see [Paolo Bergantino’s answer][2].

@killercup
killercup / pandoc.css
Created July 3, 2013 11:31
Add this to your Pandoc HTML documents using `--css pandoc.css` to make them look more awesome. (Tested with Markdown and LaTeX.)
/*
* I add this to html files generated with pandoc.
*/
html {
font-size: 100%;
overflow-y: scroll;
-webkit-text-size-adjust: 100%;
-ms-text-size-adjust: 100%;
}
@stephenturner
stephenturner / ensembl-biomart.r
Created March 14, 2012 15:31
Using biomaRt in R to retrieve Ensembl annotations
# Fit your model on your expressionset and design matrix
fit <- lmFit(eset, design)
fit2 <- contrasts.fit(fit, contrast.matrix)
fit2 <- eBayes(fit2)
results <- topTable(fit2)
# get biomart annotation
library(biomaRt)
mart <- useMart("ensembl", dataset="mmusculus_gene_ensembl")
attributes <- c("affy_mogene_1_0_st_v1", "chromosome_name",
@brendano
brendano / autolog.py
Created October 10, 2008 23:00
python decorators to log all method calls, show call graphs in realtime too
# Written by Brendan O'Connor, brenocon@gmail.com, www.anyall.org
# * Originally written Aug. 2005
# * Posted to gist.github.com/16173 on Oct. 2008
# Copyright (c) 2003-2006 Open Source Applications Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#