Skip to content

Instantly share code, notes, and snippets.

View rgrannell1's full-sized avatar
💻

R*Grannell rgrannell1

💻
View GitHub Profile
@rgrannell1
rgrannell1 / Monic Polynomial Solver 1.0.r
Created June 16, 2012 02:12
A simple R script containing functions to generate solutions to monic polynomials
MonicSolve = function(
order = 5, # the order of the monic polynomials being solved
n = 5, # n, in (n,n-1,...,-n), the acceptable coefficient values
iterations = 1000, # the number of equations to solve
random = FALSE # if m!= FALSE, use randomly generated polynomial coefficients
)
{
@rgrannell1
rgrannell1 / Game of Life
Created June 21, 2012 03:50
An R implementation of Game of Life
AutonomaGenerate = function(
dims = 25 # the size of the autonomaton
)
{
# Ryan Grannell, 2012
# A function to generate random autonoma (tend to be square,
require(ggplot2)
require(grid)
shinyServer(function(input, output) {
parameters <- NULL
processs_follow <- function(input){
if(input$user_ids != ''){
paste0('follow=', gsub(' ', '', input$user_ids))
monic <- function (max, order, a = 1, digits = 3) {
P <- matrix(0, order-1, order-2)
P[row(P)-1 == col(P)] <- 1
join_table <- function (a, b) {
n <- intersect(names(a), names(b))
require(XML)
require(stringr)
raw <- paste0(readHTMLTable('http://www.w3schools.com/tags/')$`NULL`$Tag)
processed <- unname(c(Filter(Negate(is.null),
Map (
function (name) {
if (str_detect(name, '<h1> to')) NULL else str_replace(name, 'New.*$', '')
@rgrannell1
rgrannell1 / forkbomb.r
Created May 30, 2013 17:12
A forkbomb implemented in R for POSIX-compliant operating systems,
forkbomb <- function (...) {
# you probably shouldn't run this; your pc will crash
require (parallel)
parallel::mclapply(1:2, forkbomb, mc.cores = 2)
}
forkbomb()
@rgrannell1
rgrannell1 / gist:5836273
Created June 22, 2013 07:59
An expression that returns itself by accessing the call stack. Useless but interesting.
(function () {
sys.call()
})()
prod <- function (coll) {
# callCC lets you jump out of ANY function early,
# by specifying a breakpoint function (often called 'k').
# if I used return instead of breakpoint here the
# program would take a long time to terminate.
# 1; breakpoint jumps up to this level if it is called, evalulating to zero
callCC(
function (breakpoint) {
@rgrannell1
rgrannell1 / gist:8194408
Created December 31, 2013 09:19
get the type signatures and parametres for an r package.
signify <- function (package) {
# environment -> [singatures: [string], params: [string]]
# gets the type-signature of every function in
# an environment, and every unique parameter.
data <- Map(
function (name) {
func <- get(name)
# this script is poorly-written, so use at your own risk.
# ---------------------------------------------------------------
#
# THIS HAS A VERY GOOD CHANCE OF COMPLETELY DESTROYING YOUR REPO;
# ONLY RUN THIS ON A COPY OF THE REPO!!!
#
# ----------------------------------------------------------------