This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
class Student(): | |
x = 17 | |
def __init__(self): | |
self.age = random.randint(0, 20) | |
s = Student() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def make_id( v, bit_map ): | |
bits_used = 0 | |
_id = 0 | |
for pair in zip( v, bit_map ): | |
_id += pair[0] * (2 ** bits_used ) | |
bits_used += pair[1] | |
return _id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gen_id <- function( v, silent=FALSE ) { | |
v = sort(v) | |
z <- unlist(lapply( which( chars %in% v) - 1, FUN=function(x) { bitwShiftL(1, x)})) | |
total <- sum(z) | |
if(!silent) { | |
print(v) | |
print(z) | |
print(total) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = 5 | |
g = sample(1:n, 20, replace=T) | |
c = sapply(g, FUN=function(x) rainbow( n )[[x]]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
namespace ConsoleApplication1 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggplot2) | |
df <- data.frame(x=rnorm(1000), y=rnorm(1000)) | |
jet.colors <- colorRampPalette(c("#00007F", "blue", "#007FFF", "cyan", "#7FFF7F", "yellow", "#FF7F00", "red", "#7F0000")) | |
ggplot(df[sample(1:nrow(df), 1000), ], aes(x, y)) + | |
stat_density2d(geom="tile", aes(fill=..density.., alpha=sqrt(sqrt(..density..))), contour=FALSE, n=100) + | |
scale_alpha(range = c(0.5, 1.0)) + scale_fill_gradientn(colours = jet.colors(10), trans="sqrt") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(RCurl) | |
library(reshape2) | |
library(plyr) | |
library(ggplot2) | |
pokemon <- read.csv(text = getURL("https://raw.github.com/veekun/pokedex/master/pokedex/data/csv/pokemon_species.csv", ssl.verifypeer=FALSE)) | |
pokemon_stats <- read.csv(text = getURL("https://raw.github.com/veekun/pokedex/master/pokedex/data/csv/pokemon_stats.csv", ssl.verifypeer=FALSE)) | |
stat_names <- read.csv(text = getURL("https://raw.github.com/veekun/pokedex/master/pokedex/data/csv/stat_names.csv", ssl.verifypeer=FALSE)) | |
pokemon <- ddply(pokemon, .(evolution_chain_id), subset, evolves_from_species_id == max(evolves_from_species_id, na.rm=T)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fight <- function(numZombieDie, numHumanDie) { | |
zd <- expand.grid(rep(list(1:6), numZombieDie)) | |
hd <- expand.grid(rep(list(1:6), numHumanDie)) | |
results <- vector() | |
for (z in 1:nrow(zd)) { | |
for (h in 1:nrow(hd)) { | |
zroll <- as.numeric(zd[z, ]) | |
hroll <- as.numeric(hd[h, ]) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cumProb <- function(min, trials, prob) { | |
x = 0 | |
if(min == 0) { | |
error("Mininum must be greater than 0") | |
} | |
if(min > trials) { | |
return(0) | |
} |