Skip to content

Instantly share code, notes, and snippets.

View pulkit21's full-sized avatar
🎯
Focusing

Pulkit Agarwal pulkit21

🎯
Focusing
View GitHub Profile
DROP TABLE if exists d_date;
CREATE TABLE d_date
(
date_dim_id INT NOT NULL,
date_actual DATE NOT NULL,
epoch BIGINT NOT NULL,
day_suffix VARCHAR(4) NOT NULL,
day_name VARCHAR(9) NOT NULL,
day_of_week INT NOT NULL,
@pulkit21
pulkit21 / create_applicant
Last active April 18, 2018 12:52
These are the following request i made but sure, why its not working! http://take.ms/JMbfT
curl https://api.onfido.com/v2/applicants \
-H 'Authorization: Token token=api_key' \
-d 'title=Mr' \
-d 'first_name=John' \
-d 'last_name=Smith' \
-d 'gender=male' \
-d 'dob=1980-01-22' \
-d 'country=GBR' \
-d 'addresses[][building_number]=100' \
-d 'addresses[][street]=Main Street' \
@pulkit21
pulkit21 / flat_array.rb
Created August 31, 2017 17:02
Write some code, that will flatten an array of arbitrarily nested arrays of integers into a flat array of integers. e.g. [[1,2,[3]],4] -> [1,2,3,4]
def flatten_array(array)
array.each_with_object([]) do |element, flat|
flat.push *(element.is_a?(Array) ? flatten_array(element) : element)
end
end
@pulkit21
pulkit21 / bike
Last active February 27, 2017 05:07
http://bangalore.quikr.com/2016-Bajaj-Avenger-1900-kms-driven-W0QQAdIdZ287494816
http://bangalore.quikr.com/Bajaj-Avenger-street-220.-2016-W0QQAdIdZ285620738
http://bangalore.quikr.com/Bajaj-avenger-street-220cc-bike-for-sale-W0QQAdIdZ284486524
http://bangalore.quikr.com/Bajaj-Avenger-2016-model-bike-for-sale-W0QQAdIdZ286438662
source 'https://rubygems.org'
ruby '2.2.1'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.1'
# Use postgresql as the database for Active Record
gem 'pg'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.3'
@pulkit21
pulkit21 / length_encode.rb
Created April 11, 2016 04:35
Run length encoding
def run_encode(string)
print string.chars.chunk{|i| i}.map{|k, a| a.length == 1 ? k : k + a.length.to_s }.join
end
INPUT STRING
aaaaabbbbbbbbbccccpqrstuv
OUTPUT
a5b9c4pqrstuv
@pulkit21
pulkit21 / google_validation.rb
Created April 8, 2016 14:33
Validating the request
require 'json/jwt'
require 'jwt'
module GoogleValidation
GOOGLE_CERTS_URI = 'https://www.googleapis.com/oauth2/v3/certs'
REQUIRED_AUDIENCE = ''
REQUIRED_CLIENT_ID = ''
def self.token_validation(token)
@pulkit21
pulkit21 / sign_token.rb
Created April 8, 2016 14:30
Encrypt and decrypt data
require 'json/jwt'
require 'jwt'
module SignToken
extend self
def encrypt_data(payload)
rsa_private = OpenSSL::PKey::RSA.generate 2048
rsa_public = rsa_private.public_key
token = JWT.encode payload, rsa_private, 'RS256'
@pulkit21
pulkit21 / gist:5781531fbf6f49ce3b32
Created March 11, 2016 09:33 — forked from ryansobol/gist:5252653
15 Questions to Ask During a Ruby Interview

Originally published in June 2008

When hiring Ruby on Rails programmers, knowing the right questions to ask during an interview was a real challenge for me at first. In 30 minutes or less, it's difficult to get a solid read on a candidate's skill set without looking at code they've previously written. And in the corporate/enterprise world, I often don't have access to their previous work.

To ensure we hired competent ruby developers at my last job, I created a list of 15 ruby questions -- a ruby measuring stick if you will -- to select the cream of the crop that walked through our doors.

What to expect

Candidates will typically give you a range of responses based on their experience and personality. So it's up to you to decide the correctness of their answer.

@pulkit21
pulkit21 / digital_ocean_setup.md
Created March 4, 2016 14:09 — forked from ChuckJHardy/digital_ocean_setup.md
DigitalOcean Ubuntu 14.04 x64 + Rails 4 + Nginx + Unicorn + PostgreSQL + Capistrano 3 Setup Instructions