Skip to content

Instantly share code, notes, and snippets.

View tchakravarty's full-sized avatar

Tirthankar Chakravarty tchakravarty

View GitHub Profile
library(tidyverse)
library(FinancialMath)
library(FinCal)
library(writexl)
# loan parameters
loan_amount = 4.8e6
roi_0 = 0.0925
tenure_0 = 48
@tchakravarty
tchakravarty / Rename mutate_each.R
Created November 7, 2016 06:20
Add names to multiple new variables created using mutate_each
library(wakefield)
df_foo = r_series(rnorm, 10, 1000)
# create quantized versions of base variables
df_foo %>%
mutate_each(
funs(Quantized = . > 0)
)
@tchakravarty
tchakravarty / Sample Dataset.R
Created October 22, 2016 20:19
Create sample datasets with lots of similar variables
library(tidyverse)
library(modelr)
library(lazyeval)
library(purrr)
# create the dataset
df_foo = wakefield::r_data_frame(
n = 100,
wakefield::r_series(wakefield::r_sample, j = 5, name = "cat"),
Y = wakefield::normal()
library(ggplot2)
library(dplyr)
library(scales)
df_foo = data_frame(
var1 = sample(LETTERS[1:4], size = 100, replace = TRUE),
var2 = sample(letters[1:4], size = 100, replace = TRUE)
)
# stacked absolute bar chart
@tchakravarty
tchakravarty / Dual Y-Axis ggplot2.R
Last active August 18, 2016 09:03
Dual Y-Axis ggplot2
library(ggplot2)
library(grid)
library(tidyr)
library(gtable)
library(dplyr)
gg_foo3_colors = c("#F8766D", "#00BFC4")
df_foo = read.csv(text = ",Russia,World
1996,0,423
Once, Fermat contrariated Gauss, and the result was "The Last Fermat Theorem" (bye bye Fermat!)
Gauss had already known the website 'Gauss Facts', so he saved his time for an autobiography.
Gauss can walk through Konigsberg crossing its bridges once and only once
Gauss knows an algorithm to compute the class group of any normal variety.
Gauss once proved the Fundamental Theorem of Algebra by explicitly writing out every nonconstant polynomial over the complex numbers and writing each as a product of linear factors.
Gauss once determined whether P = NP, but didn't think it was important enough to publish.
Gauss can prove axioms.
A mathematician, a physicist, and an engineer walk into a bar. The bartender says, "Hello, Professor Gauss."
Gauss can invert matrices even if its determinant is zero.
Gauss solves Navier-Stokes equations by hand.
@tchakravarty
tchakravarty / nginx.conf
Created June 13, 2016 11:03
nginx.conf to proxy Shiny server in Docker container
user www-data;
worker_processes 4;
pid /run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
alabaster==0.7.7
awscli==1.6.2
Babel==2.3.3
backports-abc==0.4
backports.shutil-get-terminal-size==1.0.0
backports.ssl-match-hostname==3.4.0.2
bcdoc==0.12.2
boto==2.33.0
botocore==0.73.0
certifi==2015.4.28
@tchakravarty
tchakravarty / 1 - Excel Name to Number.R
Last active February 22, 2016 13:20
R: Convert Excel Column Name into Column Number
#==============================================================================
# purpose: get the column number from the column name in Excel
# author: tirthankar chakravarty
# created: 22nd february 2016
# revised: 22nd february 2016
# comments:
# - based on this SO answer: http://stackoverflow.com/a/1004624/1414455
#==============================================================================
excel_name_to_number = function(name) {
@tchakravarty
tchakravarty / onthefly.py
Last active January 23, 2016 12:42
Python: Mutating objects created on-the-fly
# http://chat.stackoverflow.com/transcript/message/28317173#28317173
# the list() invocation creates a list but that is not assigned to the
# local namespace. append() changes it but does not return the
# the original object which is now lost
bar = list(range(0,8)).append(23)
print(bar)
# this breaks down the creation and the mutation into two
foo = list(range(0,8))
foo.append(23)