Skip to content

Instantly share code, notes, and snippets.


Ram Narasimhan Ram-N

View GitHub Profile
Ram-N / equi_buckets.R
Last active Jan 7, 2021
Slice a skewed distribution into buckets with equal populations
View equi_buckets.R
#' num_bkts should be a non-zero integer
#' col should contain numeric values
equi_bucket <- function(col, num_bkts){
warning("Values passed to Equibucket are not numeric")
xmin = min(col, na.rm = TRUE)
eps = 1/(num_bkts-1)
View pax.R
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 /
Created Aug 27, 2020
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 /
Created Aug 24, 2020
How to Draw a Cardioid using
w, h = 800, 800
def setup():
size(w, h)
stroke(0, 0, 250) # blue
num_steps = 200
step = TWO_PI / num_steps
Ram-N /
Created Jul 9, 2020
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 = _id
self.dir = _dir #'UP', 'DOWN', "RIGHT", "LEFT"
self.av = 0
Ram-N /
Last active Jul 7, 2020
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 /
Last active Jun 29, 2020
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 = _id
#store the starting coords of each ball. For relaunching.
self.startx, self.starty = _x, _y = False
Ram-N /
Last active Jun 30, 2020
Py Processing Scripts - Basics
radius = 100
def setup():
size(800, 600)
fill(0, 0, 200)
Ram-N /
Created Jul 9, 2018
Find Songs given a list of words
import pandas as pd
def print_songs_found(songs_column, clue_words):
for song in songs_column:
songwords = [x.lower() for x in song.split()]
if all(word in clue_words for word in songwords):
Ram-N / ColNames.R
Created May 30, 2018
Using paste0 with length=option
View ColNames.R
i <- 1:50
b <- 1:5
ColNames <- paste0("X_", i, "_", rep(b, each=length(i)))