Skip to content

Instantly share code, notes, and snippets.

View bparanj's full-sized avatar

Bala Paranj bparanj

View GitHub Profile
@bparanj
bparanj / delegate_matcher.rb
Created November 3, 2015 23:55 — forked from txus/delegate_matcher.rb
RSpec matcher for delegations
# RSpec matcher to spec delegations.
#
# Usage:
#
# describe Post do
# it { should delegate(:name).to(:author).with_prefix } # post.author_name
# it { should delegate(:month).to(:created_at) }
# it { should delegate(:year).to(:created_at) }
# end
@bparanj
bparanj / wait_until.rb
Created December 12, 2015 05:55 — forked from metaskills/wait_until.rb
Never sleep() using Capybara!
# Have you ever had to sleep() in Capybara-WebKit to wait for AJAX and/or CSS animations?
describe 'Modal' do
should 'display login errors' do
visit root_path
click_link 'My HomeMarks'
within '#login_area' do
fill_in 'email', with: '[email protected]'
fill_in 'password', with: 'test'
@bparanj
bparanj / verify_s3_file.rb
Created July 19, 2017 23:02 — forked from hartfordfive/verify_s3_file.rb
Check if file exists in S3 bucket with Ruby aws-sdk gem
require 'aws-sdk'
s3 = Aws::S3::Resource.new(
region: 'us-east-1',
credentials: Aws::InstanceProfileCredentials.new()
)
bucket = s3.bucket('my-daily-backups')
file = (DateTime.now).strftime("%Y.%m.%d-backup")
if bucket.object(file).exists?
@bparanj
bparanj / setup.sh
Created November 23, 2017 04:36 — forked from r00k/setup.sh
#!/bin/sh
# Set up Rails app. Run this script immediately after cloning the codebase.
# Exit if any subcommand fails
set -e
# Copy over configs
if ! [ -f .env ]; then
cp .sample.env .env
@bparanj
bparanj / config.yml
Created November 17, 2018 15:38 — forked from henrypoydar/config.yml
Rails 5.1 CircleCI 2.0 Configuration
version: 2
jobs:
build:
environment:
working_directory: ~/circleci-myapp
docker:
- image: circleci/ruby:2.4.2-node-browsers
environment:
CC_TEST_REPORTER_ID: XXXYYY
RAILS_ENV: test
@bparanj
bparanj / gist:42c9848fa8ae02be0c05d0e7978f9f82
Created January 8, 2019 06:18 — forked from Miserlou/gist:11500b2345d3fe850c92
1000 Largest US Cities By Population
Largest 1000 Cities in America
2013 popuation data - Biggest US Cities By Population
rank,city,state,population,2000-2013 growth
1,New York,New York,8405837,4.8%
2,Los Angeles,California,3884307,4.8%
3,Chicago,Illinois,2718782,-6.1%
4,Houston,Texas,2195914,11.0%
5,Philadelphia,Pennsylvania,1553165,2.6%
Interval Operations
There are a few operations that can be performed on intervals:
1. Merge interval[] s.t. the all intervals are disjoint.
[0,5],[5,7] ==> [0,7]
2. Insert interval into interval[] s.t. all intervals are disjoint.
3. Find intersection between two interval[].
[0,5],[5,7] => [5,5]
In order to perform these operations, it is important to understand the 6
# 1004: Max ConsecutiveOnes III
maxLength = 0
numZeros = 0
# 1052: Grumpy Bookstore Owner
maxCustWhenGrumpy = 0
idxOfStartX = 0
custWhenGrumpy = 0
# 1456: Max Number of Vowels in Substring of given length
class Solution(object):
def insert(self, intervals, newInterval):
"""
:type intervals: List[List[int]]
:type newInterval: List[int]
:rtype: List[List[int]]
"""
'''
Test cases
i) [], [2,5] => [[2,5]]
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution:
def lowestCommonAncestor(self, root: 'TreeNode', p: 'TreeNode', q: 'TreeNode') -> 'TreeNode':
'''