Skip to content

Instantly share code, notes, and snippets.

@isomorphisms
isomorphisms / -mitx.Rmd
Last active August 29, 2015 14:02
MITx and HarvardX course data
`> sort( round(sapply( split( HX, HX$course_id ), function(x) sum(x$viewed) / sum(x$registered) *100 )), decreasing=T)`
Programming
77
Mechanical Engineering
71
Structural Engineering
68
E&M
67
Computer Science
@isomorphisms
isomorphisms / tensors.html
Created June 3, 2014 18:05
tensors in QM
http://math.ucr.edu/home/baez/photon/tensor.htm:
<blockquote>Both direct sum and tensor product are standard ways of <b>putting together little Hilbert spaces to form big ones.</b> They are used for different purposes. Suppose we have two physical systems.... Roughly speaking, if ... a physical system's ... states are either of A OR of B, its Hilbert space will be [a] direct sum.... If we have a system whose states are states of A AND states of B, its Hilbert space will be [a] tensor product....
<pre>
<b>MEASURE SPACE</b> disjoint union Cartesian product
<b>HILBERT SPACE</b> direct sum tensor product
</pre>
</blockquote>
require File.expand_path(File.dirname(__FILE__) + '/neo')
require 'pry'
# Greed is a dice game where you roll up to five dice to accumulate
# points. The following "score" function will be used to calculate the
# score of a single roll of the dice.
#
# A greed roll is scored as follows:
#
# * A set of three ones is 1000 points
@isomorphisms
isomorphisms / peek.R
Last active August 29, 2015 14:05
don't use head and tail … always be sampling from the middle of the data.frame
taste <- function(soup, ladle=5L) sample.int(x=soup, size=ladle, replace=TRUE)
peek <- function(df,n=5L) df[ taste(nrow(df),n) , ] #dataframe[r,c] means "subset of dataframe row #r, column #c"
p <- function(df,n=5L) rbind(head(df,1L), peek(df,n), tail(df,1L))
#SAMPLE OUTPUT
require(bigvis)
data(movies)
@isomorphisms
isomorphisms / fibonacci.R
Created August 27, 2014 07:12
Fibonacci series matrix version
#with expm
require(expm)
matrix( c(0,1,1,1), 2,2 ) -> fibonacci
c(1L,1L) -> start
start %*% (fibonacci %*% 1337) #1337'th term-pair in Fibonacci series
# [,1] [,2]
#[1,] 1.887894e+279 3.054677e+279
@isomorphisms
isomorphisms / fizzbuzz.R
Created August 29, 2014 07:02
fizzbuzz
fb = function(n) {
f = ""
b = ""
if (!n %%3) f="fizz"
if (!n %%5) b="buzz"
print(paste0(f,b))
}
@isomorphisms
isomorphisms / _.vim
Created August 31, 2014 01:59
swap - and _ keys in vim
" RATIONALE:
" _ is used all the time in programming
" - is only used for "minus −" operator
" chords hurt my hands
" I avoid naming things with _ because it hurts
" I don't mind hitting <SHIFT> for "minus"
" because it's an operator
" and therefore requires more thought than
" "spacebar in a variable name".
"360852405690179584","","","2013-07-26 20:01:32 +0000","<a href=""http://www.floodgap.com/software/ttytter/"" rel=""nofollow"">TTYtter</a>","Define ""clear"" Mogadishu: http://t.co/fr4NwFlMq2","","","","http://downloads.bbc.co.uk/podcasts/radio4/thpop/thpop_20130723-1000b.mp3"
"334368922310676480","","","2013-05-14 18:05:38 +0000","<a href=""http://www.floodgap.com/software/ttytter/"" rel=""nofollow"">TTYtter</a>","Romans &amp; medieval Xtians both thought women were sexually insatiable. So where did ""Lie back and think of your country"" come from? #radio4","","","",""
"334365448063823873","","","2013-05-14 17:51:49 +0000","<a href=""http://www.floodgap.com/software/ttytter/"" rel=""nofollow"">TTYtter</a>","Only within the last 200 years that a European city has overtaken the size (1mm people) of Juvenalian Rome. #radio4","","","",""
"334359389601419265","","","2013-05-14 17:27:45 +0000","<a href=""http://www.floodgap.com/software/ttytter/"" rel=""nofollow"">TTYtter</a>","ancient Romans slipping Greek into t
@isomorphisms
isomorphisms / setOutputColors.R
Last active August 29, 2015 14:06
formatting for colorOut
library(colorout)
# The function takes numeric vectors of at most three elements each.
# The three numbers indicate, respectively, formating, background
# color and foreground color. If a vector has only one element, the
# number will be used to set the foreground color; if it has two
# elements, they will be used to set the background and foreground
# colors.
#
# The table below shows valid values and their meanings as both
@isomorphisms
isomorphisms / wegert.R
Last active February 1, 2019 14:26
make complex-plane Wegert plots (plot only the argument, knowing that the length=modulus works the same as in a "regular" Cartesian plot)
#run convenience functions first....
plat <- function(space,FUN,cex=2,chroma=45,a=66,b=4,c=3){ #a,b,c are tuning parameters
func=FUN(space) #eval for speedup
coleur=arg(func)%%360
light=a+b*mod(func)+c*l(coleur)
plot(space, pch=46,cex=cex, col=hcl( h=coleur, c=chroma, l=light ) )
}
#what this function does, is plot a boring series of points with nothing on them,
# moving the REAL ACTION to the colour parameter.