Skip to content

Instantly share code, notes, and snippets.

@andrewnguyen42
andrewnguyen42 / pi_viz.R
Created February 24, 2019 17:15
Visualize the first million digits of pi as a phone background
library(dplyr)
library(ggplot2)
library(httr)
library(stringr)
my_pi <- GET(url = 'https://www.angio.net/pi/digits/pi1000000.txt') %>%
content(as="text")
n <- 1000000
library(lme4)
library(blme)
library(arm)
cps <- read.csv('cps.csv')
cps <- subset(cps,wageworkerlastyear==1 & !is.na(lhourlywage))
cps$state<-as.integer(cps$statefip)
cps$nchildnum<-as.integer(cps$nchild)-1
cps$statefip<-as.factor(cps$statefip)
dataframe <- read.csv('rushing.csv', header = TRUE,sep = ",")
#filter for 16 game seasons and running backs
sixteenGamesdf <- dataframe %.% filter(Pos == 'TB' | Pos =='rb' | Pos == 'RB' , Year >= 1978)
sixteenGamesdf$Tm[sixteenGamesdf$Tm=="RAM"]<-"STL"
sixteenGamesdf$Tm[sixteenGamesdf$Tm=="PHO"]<-"ARI"
sixteenGamesdf$Tm[sixteenGamesdf$Tm=="RAI"]<-"OAK"
@andrewnguyen42
andrewnguyen42 / waterFill
Last active December 29, 2015 23:49
An imperative solution to the waterflow problem: http://philipnilsson.github.io/Badness10k/articles/waterflow/
public static int waterFill(int[] arr){
int rainCount=0;
int max=arr[0];
for(int i=0;i<arr.length;i++){
max=(arr[i]>max)?arr[i]:max;
}
//fill it up
@andrewnguyen42
andrewnguyen42 / Java post
Last active December 16, 2015 05:19
Send an xml string to a url Requires 5 jars: commons-httpclient-3.0.1.jar , httpclient-4.0-alpha2.jar , httpcore-4.0-alpha6.jar , commons-codec-1.7.jar , commons-logging-1.1.2.jar
/**
* Actually takes care of posting data to a service
* @param xml The xml data in the form of a Java String
* @param url The address to post data to
*/
private static boolean postData(String xml, String url){
//PostMethod post=new PostMethod();
HttpPost pst=null;
@andrewnguyen42
andrewnguyen42 / FileLister
Created April 11, 2013 18:07
Quick example of file traversal
import java.io.File;
public class FileLister {
public static void main(String[] args) {
list(new File("/"));
}
/**
* Display a list of the specified file and all its descendants.
*/