Skip to content

Instantly share code, notes, and snippets.

View jagdeepsingh's full-sized avatar

Jagdeep Singh jagdeepsingh

  • Mohali
View GitHub Profile
@jagdeepsingh
jagdeepsingh / README.md
Last active April 13, 2017 08:01
Javascript, jQuery, Coffeescript

Javascript

forEach

ary = [11, 22, 33, 44, 55]
ary.forEach(function(value, index, array){
  // ...
});
@jagdeepsingh
jagdeepsingh / reservation_helper.rb
Created December 26, 2015 13:54
Define a helper in rails
module ReservationHelper
def show_advanced_num_people_fields?(reservation)
show_num_people_senior?(reservation) ||
show_num_people_child?(reservation) ||
show_num_people_baby?(reservation)
end
end
@jagdeepsingh
jagdeepsingh / reservation_service.rb
Created December 26, 2015 14:00
Create a service in rails
class ReservationService
class CustomError < StandardError; end
def initialize(options = {})
add_logic_here
end
def validate!
raise CustomError unless valid?
end
@jagdeepsingh
jagdeepsingh / http_request_service.rb
Created December 27, 2015 13:50
Ruby service to send http requests
require 'net/http'
class HttpRequestService
attr_reader :uri
def do_post(url, headers, data)
set_uri(url)
post = build_post(uri, headers, data)
net_http(uri).start { |http| http.request(post) }
end
@jagdeepsingh
jagdeepsingh / outlook_calendar_service.rb
Last active June 24, 2016 13:45
Ruby service for Microsoft Outlook calendar API
class OutlookCalendarService
APP_ID = your_app_id
APP_SECRET = your_app_secret
LOGIN_API_DOMAIN = 'https://login.microsoftonline.com'
AUTHORIZE_PATH = '/common/oauth2/v2.0/authorize'
TOKEN_PATH = '/common/oauth2/v2.0/token'
CALENDAR_API_DOMAIN = 'https://outlook.office365.com'
VERSION_PATH = '/api/v2.0'
@jagdeepsingh
jagdeepsingh / cavity_finder.rb
Last active June 1, 2016 18:02
Ruby practices
#!/bin/ruby
class CavityFinder
def initialize(grid)
@grid = grid
end
def cavities
cavities = []
i = 1
@jagdeepsingh
jagdeepsingh / README.md
Last active June 7, 2018 06:54
rubocop
@jagdeepsingh
jagdeepsingh / README.md
Last active June 29, 2017 06:33
NihaoPay Payment Gateway