Skip to content

Instantly share code, notes, and snippets.

View Ram-N's full-sized avatar

Ram Narasimhan Ram-N

View GitHub Profile
@Ram-N
Ram-N / equi_buckets.R
Last active January 7, 2021 21:50
Slice a skewed distribution into buckets with equal populations
#' num_bkts should be a non-zero integer
#' col should contain numeric values
equi_bucket <- function(col, num_bkts){
if(!is.numeric(col)){
warning("Values passed to Equibucket are not numeric")
return(NA)
}
xmin = min(col, na.rm = TRUE)
eps = 1/(num_bkts-1)
@Ram-N
Ram-N / pax.R
Created January 6, 2021 02:26
pax_plot
plot_pax_wrap <- function(df, num_pax){
pax_rows <- round(sqrt(num_pax), -1)
pax_cols <- as.integer(num_pax/pax_rows)
df2 <- arrange(df, -Rev)
curr_pax <- 1
for (py in 1:pax_cols){
for (px in 1:pax_rows){
if (curr_pax <= num_pax){
df2[curr_pax, 'plot_col'] = px
@Ram-N
Ram-N / wordcloud.py
Created August 27, 2020 14:50
Create a Simple Wordcloud using Donald Trump's Tweets
import json
from wordcloud import WordCloud
import matplotlib.pyplot as plt
with open('data/trump_tweets/condensed_2018.json') as f:
data = json.load(f)
type(data), len(data)
@Ram-N
Ram-N / cardioid.py
Created August 24, 2020 03:30
How to Draw a Cardioid using Processing.py
w, h = 800, 800
def setup():
size(w, h)
stroke(0, 0, 250) # blue
num_steps = 200
step = TWO_PI / num_steps
@Ram-N
Ram-N / Ball_trapeze_gif_loop.py
Created July 9, 2020 21:31
Ball_trapeze_gif_loop.py
w, h = 1000, 800
class Ball(object):
def __init__(self,_id, _x, _y, _vx=0, _vy=0, _dir='UP'):
self.x, self.y = _x, _y
self.vx, self.vy = _vx, _vy
self.id = _id
self.dir = _dir #'UP', 'DOWN', "RIGHT", "LEFT"
self.av = 0
@Ram-N
Ram-N / bw_noise_color.py
Last active July 7, 2020 00:10
Perlin Noise Coloring
# The noise value was calculated at each pixel,
# using Processing’s built-in noise function.
# This value was scaled up (by a factor of 10 to 100) and rounded,
# yielding an integer for every pixel in the frame.
# Colors were designated based on this number using a switch.
# Finally, a point/dot was drawn at each pixel, in the assigned color.
# The greater the scaling factor, the thinner and more numerous the noise bands.
# Creates a 2D List of 0's, nCols x nRows large
@Ram-N
Ram-N / ball.py
Last active June 29, 2020 15:02
Processing_py - Balls criss-crossing
class Ball(object):
def __init__(self,_id, _x, _y, _vx=0, _vy=0):
self.x, self.y = _x, _y
self.vx, self.vy = _vx, _vy
self.id = _id
#store the starting coords of each ball. For relaunching.
self.startx, self.starty = _x, _y
self.active = False
@Ram-N
Ram-N / 2_circles_rotating_around_a_point.py
Last active June 30, 2020 21:29
Py Processing Scripts - Basics
radius = 100
def setup():
size(800, 600)
background(255)
smooth()
noStroke()
fill(0, 0, 200)
frameRate(100)
@Ram-N
Ram-N / Song_Finder.py
Created July 9, 2018 23:40
Find Songs given a list of words
import pandas as pd
def print_songs_found(songs_column, clue_words):
for song in songs_column:
try:
songwords = [x.lower() for x in song.split()]
#print(songwords)
if all(word in clue_words for word in songwords):
print(songwords)
except:
@Ram-N
Ram-N / ColNames.R
Created May 30, 2018 17:58
Using paste0 with length=option
i <- 1:50
b <- 1:5
ColNames <- paste0("X_", i, "_", rep(b, each=length(i)))