Skip to content

Instantly share code, notes, and snippets.

View jasdeepsingh's full-sized avatar
🏠
Working from home

jasdeep singh jasdeepsingh

🏠
Working from home
View GitHub Profile
@jasdeepsingh
jasdeepsingh / installing-redis1.sh
Created May 22, 2013 15:40
Installing Redis on Mac OS X
$ cd ~/Downloads/redis-2.4.14
$ make test
$ make
@jasdeepsingh
jasdeepsingh / demo.rb
Created August 19, 2021 18:29
Equality Operator Override for Embedded Associations
# [5] pry(main)> r.exclusion_rules
# => [#<ExclusionRule _id: 611e94fa7d8fbc102109e5cd, type: "wday", value: [1], exclusionary: true>]
# [6] pry(main)> r.exclusion_rules = [ExclusionRule.new(id: '611e94fa7d8fbc102109e5cd', type: 'wday', value: [2])]
# => [#<ExclusionRule _id: 611e94fa7d8fbc102109e5cd, type: "wday", value: [2], exclusionary: true>]
# [7] pry(main)> r.save
# => true
# [8] pry(main)> r.exclusion_rules
# => [#<ExclusionRule _id: 611e94fa7d8fbc102109e5cd, type: "wday", value: [1], exclusionary: true>]
@jasdeepsingh
jasdeepsingh / gale-shapley.py
Created May 13, 2020 17:21
Gale Shapley Algorithm
from collections import defaultdict
def stableMatching(n, menPreferences, womenPreferences):
# Initially, all n men are unmarried
unmarriedMen = list(range(n))
# None of the men has a spouse yet, we denote this by the value None
manSpouse = [None] * n
# None of the women has a spouse yet, we denote this by the value None
womanSpouse = [None] * n
# Each man made 0 proposals, which means that
class ApplicationController
before_action :authenticate_user
def authenticate_user
response = TokenAuthService.call(token: request.headers['Api-Token'] || params[:api_token])
if response.failure?
render json: {
error: 'Not Authorized',
message: response.error
@jasdeepsingh
jasdeepsingh / aws-s3.rb
Created October 10, 2011 05:04
/config/initializers/s3.rb:1:in `<top (required)>': uninitialized constant AWS (NameError) - AWS-S3 Gem not working Mac OS X Lion
# If you are facing such an Error while installing/working with the aws-s3 gem
# /config/initializers/s3.rb:1:in `<top (required)>': uninitialized constant AWS (NameError)
# try adding this to your Gemfile instead..
gem 'aws-s3', :require => 'aws/s3'
# I was having this issue on Mac OS X Lion with aws-s3 gem 0.6.2
@jasdeepsingh
jasdeepsingh / component.js
Created April 27, 2017 15:34
react component
class Component extends React.Component {
component___Mount() { // didMount? willMount?
window.api.asyncCallToBackend() // returns promise
}
render() {
return (<data here that depends on response of async call in one lifecycle methods>)
}
@jasdeepsingh
jasdeepsingh / README.MD
Last active April 3, 2017 15:03
FriendInviter

FriendInviter

FriendInviter is a web based application that can be used to, well, wait for it: Invite Friends :P. The goal of the application is to allow a user to invite a maximum of 3 of their friends using their email addresses. Here are some requirements:

  1. Initial user can be either hardcoded or seeded manually in the application from a console etc.
  2. Initial user sends out an email invite to 3 of his/her friends aka Recepients.
  3. Recepients receive email invitations to join FriendInviter.
  4. Upon acceptance of each invite, the person who sent the Invite is credited with points. Each successful invite yields 50 points.
  5. If all 3 invites are successfully accepted, a bonus of 200 points is also awarded.
  6. Invites should be valid for a maximum of 15 minutes.
@jasdeepsingh
jasdeepsingh / Gemfile
Created December 18, 2011 17:38
Setting up Rails TDD Environment with Rspec
# In console:
# Ignores the setting up of Test::Unit by default
$ rails new app_name -T
# In Gemfile add the following gems:
group :test, :development do
gem 'turn'
gem 'rspec-rails'
gem 'capybara'
gem 'guard-rspec'
@jasdeepsingh
jasdeepsingh / work_report.rb
Created December 13, 2013 18:24
work_report bug
previous_work_report.visits.active.select('schedule_visits.id, schedule_visits.uuid').select_all.each do |v|
Schedule::SimpleVisit.verify_and_clone_with_schedule(self, v['id'].to_i, v['uuid'].to_i)
end
@jasdeepsingh
jasdeepsingh / spec_style.rb
Last active December 25, 2015 19:19
spec_style
describe Class do
# let blocks are always single line blocks.
let(:variable) { value }
# context blocks always have a string description.
context "when something" do
before(:each) do
# before blocks are always multilined