Skip to content

Instantly share code, notes, and snippets.

Researching 'em microbes...

Christian Diener cdiener

Researching 'em microbes...
View GitHub Profile
cdiener / cache.R
Last active Aug 29, 2015
cache operator for R
View cache.R
# Caching operator executes command if there is no saved version of the data
# just delete the saved file and code will be run again
'%c%' = function(ex, file) if(file.exists(file), env=parent.frame(4)) load(file) else evalq(ex))
# Example
# first execution
{ x <- rnorm(1e6); save(x, file="cache.Rd") } %c% "cache.Rd" # executes the sampling
cdiener / points
Last active Aug 29, 2015
ggplot2 grouped points with horizontal means
View points
emsa_plot = ggplot(emsa, aes(x=Name, y=intensity, shape=charge_ratio, col=charge_ratio, width=0.8)) +
geom_point(size=3, position=position_dodge(width=0.8)) +
stat_summary(, mult=0, color="black", geom="errorbar", size=1, position=position_dodge(width=0.8)) +
scale_color_grey(start=0, end=0.5,name="charge ratio") +
scale_shape(name="charge ratio") +
scale_y_continuous(limits=c(-0.05,1), breaks=seq(0,1,by=0.2), label=percent) +
cdiener / overload.R
Last active Aug 23, 2019
R operator overloading
View overload.R
a = "bla"
b = "so on"
class(a) = append("my_class", class(a))
'+.my_class' = function(x,y) paste(x,y,sep=" and ")
cdiener /
Last active Aug 29, 2015
Learning Topics

Learning List

Next topics to learn:

  • webservers
  • node.js
  • Django or Pyramid [maybe Jinja2+Tornado a better option for smaller projects]
  • Plone plugins [too complex, substituded by FormGen]
  • D3
  • Python testing frameworks
cdiener /
Created Apr 13, 2014 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 /
Last active May 20, 2020
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: ./ image scale factor' ); sys.exit()
f, SC, GCF, WCF = sys.argv[1], float(sys.argv[2]), float(sys.argv[3]), 7/4
img =
S = ( round(img.size[0]*SC*WCF), round(img.size[1]*SC) )
img = np.sum( np.asarray( img.resize(S) ), axis=2)
You can’t perform that action at this time.