Skip to content

Instantly share code, notes, and snippets.

View yoavram's full-sized avatar

Yoav Ram yoavram

View GitHub Profile
We couldn’t find that file to show.
@yoavram
yoavram / params.R
Created October 29, 2012 14:47
Override default parameters in R from command line with 4 lines of code
# Override default parameters in R from command line with 4 lines of code (the numbered lines)
# Run from command line:
# R --slave -f demo.r --args p.success=0.9 num.of.tests=1000
# R --slave -f demo.r --args p.success=0.5 num.of.tests=10000
# R --slave -f demo.r --args p.success=0.3 num.of.tests=10
#
# Created 29/10/12 by Yoav Ram (www.yoavram.com), licenced under the WTFPL free software license
# default parameter values
num.of.tests <- 100
@yoavram
yoavram / iphone-pandoc-template.latex
Created October 30, 2012 09:38
A Pandoc template to create PDFs suitable for mobile phones - see discussion http://tex.stackexchange.com/questions/78920/generating-smartphone-readable-pdf
\documentclass[10pt,$if(lang)$$lang$,$endif$]{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{amssymb,amsmath}
\usepackage{ifxetex,ifluatex}
\usepackage{fixltx2e} % provides \textsubscript
% use microtype if available
\IfFileExists{microtype.sty}{\usepackage{microtype}}{}
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
\usepackage[utf8]{inputenc}
@yoavram
yoavram / bit.to.uint.R
Created November 1, 2012 13:53
a function that transforms a vector of bits ( c(0,1,1,0,0) ) to an unsigned integer (6). Includes a test as an example at the bottom.
bits.to.uint <- function(bits) {
s=0
for (i in 1:length(bits)) {
s = s + 2^(i-1) * bits[i]
}
return(s)
}
cat(bits.to.uint( c(0,1,1,0,0) ) == 6)
cat(bits.to.uint( c(0,1,0,0,1) ) == 18 )
library(shiny) # http://rstudio.github.com/shiny/tutorial/#hello-shiny
library(Rgraphviz) # http://www.bioconductor.org/packages/2.11/bioc/html/Rgraphviz.html
shinyServer(function(input, output) {
output$graphPlot <- reactivePlot(function() {
g <- randomGraph(1:input$V, 1:input$M, input$p)
plot(g)
})
})
@yoavram
yoavram / choose k from n benchmark.ipynb
Created November 23, 2012 08:53
choose k from n benchmark
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@yoavram
yoavram / The Zen of Python.ipynb
Created November 26, 2012 09:44
The Zen of Python ipython notebook
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@yoavram
yoavram / js-for-science.html
Created December 13, 2012 23:39
Comparing Code highlighters in JS
<html>
<head>
<!-- LaTeX support-->
<!--extensions: ["tex2jax.js"],
jax: ["input/TeX", "output/HTML-CSS"],
tex2jax: {
inlineMath: [ ['$','$'], ["\\(","\\)"] ],
displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
processEscapes: true
},-->
@yoavram
yoavram / creating-pdfs-with-pandoc.md
Created December 16, 2012 09:00
How to create PDF, EPUB and mobile-PDF with Pandoc

% Creating PDFs with Pandoc % Yoav Ram % 2012-12-16 11:36:00 +2

Overview

This post will show how to convert a [Markdown] document to PDF, mobile-PDF and EPUB documents using [Pandoc]. The guide is not exhastive but rather a walkthrough of my own experiments. The mobile-PDF especially is lacking - it is based on somewhat advanced $LaTeX$, and I'm a novice user of that language.

The source [Markdown] file use for this post, [creating-pdfs-with-pandoc.md], is available as a gist.

@yoavram
yoavram / client.py
Created December 21, 2012 08:41
Example of uploading binary files programmatically in python, including both client and server code. Client implemented with the requests library and the server is implemented with the flask library.
import requests
#http://docs.python-requests.org/en/latest/user/quickstart/#post-a-multipart-encoded-file
url = "http://localhost:5000/"
fin = open('simple_table.pdf', 'rb')
files = {'file': fin}
try:
r = requests.post(url, files=files)
print r.text