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 / 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 / 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 / yml_to_markdown.md
Created August 16, 2015 21:06
yml_to_markdown
@jasdeepsingh
jasdeepsingh / recent_files_spec.rb
Last active August 29, 2015 14:24
recent_files_spec.rb
#====== Implement your solution below:
# class RecentFiles
# end
#====== Solution implementation ends
require 'rspec'
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
@jasdeepsingh
jasdeepsingh / recent.md
Last active August 29, 2015 14:15
Recent Files Tracker

Let's build a Recent File Tracker

  • Implement a Class, name it RecentFiles

  • You can start implementing your class from 2nd line onwards.

  • You can run the test code, which will test your code using the following command: rspec file_name.rb

  • You can replace the file_name.rb with your actual file which you are working with.

  • If you get any errors such as rspec not found etc, please do: sudo gem install rspec

  • The class should be able to handle the following scenarios:

    • Output a list of most recent accessed files.
@jasdeepsingh
jasdeepsingh / notifier_proxy.rb
Created September 21, 2014 22:29
notifier_proxy.rb
class Notifier
def notify(user)
if user.student?
send_sms(user.number)
elsif user.parent?
send_email(user.email)
end
end