Skip to content

Instantly share code, notes, and snippets.

View jlisic's full-sized avatar

Jonathan Lisic jlisic

View GitHub Profile
library(cdlTools)
library(dplyr)
library(magrittr)
library(ggplot2)
years <- 2008:2023
state <- 'maryland'
# Terra!
cdl.raster <- getCDL(state,years,location="~/CDL",returnType = 'terra')
@jlisic
jlisic / 538_pseudo_cast.R
Created January 19, 2021 03:50
A quick R script to convert a 538 chat to an mp3 file using voices in MacOS. Requires ffmpeg, you would also need to update some of the file locations.
library('rvest')
library('dplyr')
library('magrittr')
setwd('~/src/538/')
# this is the blog post we are interested in
#URL <- "https://fivethirtyeight.com/features/who-killed-the-health-care-bill/"
#URL <- "https://fivethirtyeight.com/features/which-gop-senators-might-resurrect-the-health-care-bill/"
URL <- "https://fivethirtyeight.com/features/how-has-the-radical-right-evolved-under-trump/"
@jlisic
jlisic / Sample_Tessellation.R
Created January 16, 2018 18:23
Create a tessellation from a subset of sampled data.
# create a tessalation
sampleVoronoi <- function(x, sampled,rw=NULL) {
require(raster)
vor <- tile.list( deldir(x[sampled,1], x[sampled,2],rw=rw) )
vorPoly <- lapply( 1:length(vor) ,
function(i) {
@jlisic
jlisic / meltdown_test.c
Created January 6, 2018 20:14
A simple program that shows the impact of meltdown.
/* a simple program that invokes the kernel */
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <sys/syscall.h>
#include <linux/random.h>
int main() {
@jlisic
jlisic / App.R
Created November 17, 2017 13:56
Map Shiny Gist
library(shiny)
library(ggmap)
library(rgdal)
library(sp)
library(broom)
library(dplyr)
library(magrittr)
library(raster)
library(rgeos)
# fun with sp objects
library(sp)
set.seed(100)
n <- 8
m <- rpois(lambda=2,n)+1
x_range <- c(0,100)
@jlisic
jlisic / atp.sh
Last active September 3, 2016 07:32
ATP Live Stream Recorder or Something Like That!
#!/bin/bash
# script to use with cron to capture the live stream
# this script is under no real license, and may give your dog
# lice, catch you on file, and is not warranted for any purpose
# what-so-ever
# to use with cron every 10min use
# crontab -e
@jlisic
jlisic / downloadRate.R
Last active October 28, 2015 15:27
A tool to get CDL state level accuracies from R.
#Copyright (c) 2015, Jonathan Lisic
#All rights reserved.
#
#Redistribution and use in source and binary forms, with or without
#modification, are permitted provided that the following conditions are met:
#
#1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
@jlisic
jlisic / sas2csv.R
Created May 27, 2015 02:15
Convert a sas binary file to a cvs without sas (but with R).
#!/usr/local/bin/Rscript
# get the usual argv
args <- commandArgs(trailingOnly == TRUE)
# get the input sas file name
inFile <- args[1]
# get the output csv file name
inFile <- args[1]
@jlisic
jlisic / rasterTool.R
Last active June 28, 2017 14:44
Simple tools to use gdal to polygonize and rasterize
library(cdlTools)
library(rgdal)
library(raster)
library(rgeos)
# rasterize in the R 'raster' package is really slow, depending on your needs this may work better
# Author: Jonathan Lisic
# License BSD
polyExtract <- function(x) {