Skip to content

Instantly share code, notes, and snippets.

@jdesilvio
jdesilvio / D3sankeyData.R
Created June 5, 2015 23:55
This script is designed to create a JSON formatted for the D3 Sankey Diagram
##################################################################################################
### This script is designed to create a JSON formatted for the D3 Sankey Diagram. The JSON ###
### consists of nodes and links. The script can take in 2 or more categorical variables and ###
### and 1 numerical value variable. ###
##################################################################################################
# import libraries
library(reshape2)
library(plyr)
library(rjson)
@jdesilvio
jdesilvio / shinyTemplate.R
Last active February 24, 2021 04:09
Template for a basic R Shiny app
# import libraries
library(shiny)
##########
# SERVER #
##########
#generic line initiating the SERVER
server <- shinyServer(function(input, output) {
@jdesilvio
jdesilvio / URLverifier.rb
Created June 6, 2015 16:06
Simple script to verify URLs (for use in Rails apps)
#!/usr/bin/ruby
require 'uri'
#enter URL here
url = 'https://www.google.com'
#verify URL
if url =~ /\A#{URI::regexp(['http', 'https'])}\z/
puts “URL Verified"
@jdesilvio
jdesilvio / BitnamiAMI_pyScrape_setup.sh
Created June 6, 2015 19:45
Setup script for the Bitnam LAMP AMI on Amazon AWS for Python Webscraping
#!/bin/bash
# Setup script for the Bitnam LAMP AMI on Amazon AWS
## This script sets up Python 2.7 and installs libraries critical to webscraping
apt-get update
sudo apt-get install python2.7-dev
apt-get install python-pip
@jdesilvio
jdesilvio / sankeyDiagram.html
Last active August 29, 2015 14:23
D3.js Sankey diagram - Modified from Mike Bostock's example
<!DOCTYPE html>
<!-- Credit to http://bost.ocks.org/mike/sankey/ and http://bl.ocks.org/d3noob/5028304 -->
<html lang="en">
<head>
<meta charset="utf-8">
<title>Page Title</title>
@jdesilvio
jdesilvio / chordDiagram.html
Created June 21, 2015 00:29
D3.js Chord Diagram - Modified from Mike Bostock's example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Chord Diagram</title>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<style type="text/css">
@jdesilvio
jdesilvio / getFolderInfo.R
Created June 21, 2015 00:30
R - Get contents and information for all files in a directory
#list all files from a folder
getFolderContent = function(path) {
pathNow = getwd()
setwd(path)
files = list.files()
setwd(pathNow)
files
}
#create helper function to paste path and file, then get info
@jdesilvio
jdesilvio / d3bar.html
Created September 13, 2015 02:44
D3.js Bar Chart - Modified from Mike Bostock's example
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.bar {
fill: steelblue;
}
.incomplete {
opacity: 0.5;
@jdesilvio
jdesilvio / renameColumn.R
Last active December 21, 2015 15:44
Rename column
# Rename a column
renameCol = function(df, oldName, newName) {
names(df)[names(df) == oldName] = newName
df
}
@jdesilvio
jdesilvio / plyr_dplyr_test.R
Last active June 4, 2016 03:41
plyr to dplyr
df <- data.frame(id = seq(1, 500),
attr1 = rep(c("up", "up", "down", "down")),
attr2 = rep(c("left", "right", "left", "right")),
attr3 = rep(c("b", "a", "select", "start")),
attr4 = sample(c("c", "o", "n", "t", "r", "a"), 100, replace=T),
x = rnorm(100))
dfChar = df
dfChar[, names(dfChar)] <- lapply(dfChar[, names(dfChar)], as.character)
dt = as.data.table(df)