Skip to content

Instantly share code, notes, and snippets.

View soumyaray's full-sized avatar

Soumya Ray soumyaray

View GitHub Profile
require 'rubygems'
require 'bcrypt'
require 'haml'
require 'sinatra'
enable :sessions
userTable = {}
helpers do
require 'json'
hstr = ["name=ytutyu&email=tyutyu&bio=tyutyu"]
params = hstr[0].split(/\&/).reduce({}) do |all, p|
name, value = p.split(/=/)
all.merge(name => value)
end.to_json
@soumyaray
soumyaray / ruby_objects.rb
Created September 21, 2014 16:44
Ruby Arrays, Hashes
# Good documentation and examples: http://ruby-doc.org/core-2.1.1/
# Contents:
# - EVERYTHING IS AN OBJECT
# - OBJECT COMPARISON
# - STRINGS
# - ARRAYS
# - HASH
# - HASH AND ARRAY CONVERSION
@soumyaray
soumyaray / async_http.rb
Last active April 11, 2023 06:26
Async and Sync HTTP calls in Ruby
require 'net/http'
def sync_call(urls)
urls.each do |u|
u['content'] = Net::HTTP.get( URI.parse(u['link']) )
end
end
def async_call(urls)
threads = urls.map do |u|
@soumyaray
soumyaray / ruby-language-unless.md
Last active August 29, 2015 14:16
Ruby: unless conditional

Ruby: Unless conditional

Yes, unless is pretty much syntactic sugar for if !

It may seem a bit weird if you are used to if ! but it actually reads much nicer.

Take a look:

unless results_found()

puts "No results found"

-----BEGIN PGP MESSAGE-----
Version: GnuPG/MacGPG2 v2.0.27
Comment: GPGTools - http://gpgtools.org
hQIMAywH8gmncouzARAAuSGA0bwr9lftD/S5yJCqv5Y0kmYUn8zXdgbl2W/dmJNR
T/3KNo1iKyI127UfhZxwl8/U8qW9lx8hjzj2wllpIOpK6qJF36/5V3ISQHwjUIUx
gr3TzKbNLKBuLzxLNWoKZLmMw/ESEeNtFTfr7LLgR9pIQBJyPMT6OhS4fFWxLcSB
MRmKB7QtQ9vNEp1DNtUgbWrW2nrp2uokbUPLA8val7qfZGUs2c0Wr3zK8GtbP4iD
Tihe4WolnApSdu4SHKE5Y324S0I6VMLtV1yx+lyNuFwLJ4wANZBB/c44ja/0dGDk
57BcAsCE96uqQC0EUkRmNTq40rxvO2rIyQNb56N6RHBYLVxKfrlB/cjoGNuzfGTY
@soumyaray
soumyaray / 632_bootstrap_mean.r
Created April 18, 2016 02:51
First attempt of .632 bootstrap on mean estimation
adj_test <- function() {
a <- rnorm(n=100, mean=50, sd=10)
b <- rnorm(n=100, mean=60, sd=5)
c <- rnorm(n=100, mean=65, sd=2)
abc <- c(a,b,c)
data <- data.frame(key=c(1:300), vals=abc)
boot_mean <- c()
boot_mean_adj <- c()
for(i in 1:2000) {
> pca
Principal Components Analysis
Call: principal(r = agg.data.clean, nfactors = 17, rotate = "none",
scores = TRUE)
Standardized loadings (pattern matrix) based upon correlation matrix
PC1 PC2 PC3 PC4 PC5 PC6 PC7 PC8 PC9 PC10 PC11 PC12 PC13 PC14 PC15 PC16 PC17
alive.days 0.73 -0.35 0.10 -0.04 -0.16 -0.07 0.04 0.18 -0.04 -0.16 -0.13 0.30 0.03 0.01 0.35 -0.12 0.00
average.downloads -0.12 0.26 0.29 -0.18 0.28 -0.24 0.29 0.33 0.68 0.02 -0.11 -0.03 0.01 0.00 0.01 -0.01 0.00
total.commits 0.63 0.51 -0.26 0.08 -0.08 -0.06 -0.02 0.03 0.05 -0.17 0.09 -0.04 0.01 0.46 -0.02 0.01 0.00
weekday.commits.percentage 0.19 -0.22 -0.01 0.12 -0.32 0.35 -0.58 -0.07 0.55 0.17 0.06 0.02 0.01 0.00 0.01 0.01 0.00

Keybase proof

I hereby claim:

  • I am soumyaray on github.
  • I am soumyaray (https://keybase.io/soumyaray) on keybase.
  • I have a public key whose fingerprint is 8542 E525 71ED 93CB 27C4 925E 15D9 AACD CE51 0594

To claim this, I am signing this object:

@soumyaray
soumyaray / scatter_play.R
Last active August 24, 2016 05:12
Create live x-y scatter plot with correlation and regression line
scatter_play <- function() {
# create a blank plot (use and then remove a fake point)
points = data.frame(x=c(-99), y=c(-99))
plot(points, xlim=c(-5,50), ylim=c(-5,50))
points = data.frame(x=c(), y=c())
cat("Click on plot to add points; [Esc] to quit")
repeat {
location <- locator(1)