Skip to content

Instantly share code, notes, and snippets.

View cravindra's full-sized avatar
👨‍💻
Focus mode on

Chirag Ravindra cravindra

👨‍💻
Focus mode on
View GitHub Profile
/* global grecaptcha */
/* global $ */
/* global window */
import Ember from 'ember';
/**
* Component to handle Render and Forward Result of the reCaptcha Challenge
*/
export default Ember.Component.extend({
/**
@cravindra
cravindra / aspect_ratio_div.txt
Last active December 5, 2017 06:29
Padding Bottom Values for Fixed Aspect Ratio Divs
Source: http://stackoverflow.com/questions/1495407/maintain-the-aspect-ratio-of-a-div-with-css
aspect ratio | padding-bottom value
--------------|----------------------
16:9 | 56.25%
4:3 | 75%
3:2 | 66.66%
8:5 | 62.5%
@cravindra
cravindra / utils.js
Last active October 19, 2023 05:45
Vanilla JS Utils
/**
* Useful common operations wrttien in vanilla JS. Found, borrowed, created and modified from various sources on the internet.
*/
/**
* Helper to test if an element has a given class
* @param {*} el Element to test
* @param {*} className Class to test
*/
function hasClass(el, className) {
@cravindra
cravindra / youtube.js
Created August 30, 2017 11:35
Framework code to instantiate one or more youtube videos on a page
/**
* YouTube API helper for instantiating multiple videos on a page
* https://developers.google.com/youtube/iframe_api_reference
*/
/**
* Helper to queue a youtube video to be instantiated with the YouTube API
* @param {*} videoId The YouTube Video ID
* @param {*} elementId The Element ID to instantiate as a YouTube player
* @param {*} callback The callback to be called once the player object is available
@cravindra
cravindra / request.js
Created November 7, 2017 11:48
Express Middleware to augment the Request and Response Object with some helpful methods and attributes
/**
* Middleware to add the following helpers to the req object
* 1. wantsJSON
* 2. getAllParams
* @param req - The Express Request Object for the current request
* @param res - The Express Response Object for the current request
* @param next
*/
function enhanceReq(req, res, next) {
@cravindra
cravindra / nocookie-session.js
Created November 7, 2017 11:53
Middleware arrangement for using Express Session with session ID which can be overriden by a URL query parameter
const express = require('express');
const router = express.Router();
const session = require('express-session');
const MemcachedStore = require('connect-memcached')(session);
const _ = require('lodash');
const utils = require('../../services/application/utils');
const config = utils.getConfiguration();
/**
* Middleware which goes in before Express Session to enable overriding session ID assignment through a query parameter
* or a request header `uid`
@cravindra
cravindra / browser-ajax.js
Last active November 7, 2017 12:03
A wrapper around fetch to do common ajax operations on the server and client
require('../../vendor/js/fetch');
/**
* The defaultOptions properties used in fetching API
* @typedef {Object} defaultOptions
* @property {string} method - Indicates the http request method
* @property {string} url - request Url
* @property {Object|null} body - holds the http request body information to be used in post or put request
*/
const fetchConfig = {
@cravindra
cravindra / google-auth.js
Last active November 7, 2017 11:59
A wrapper which uses lasso-loader to enable google oauth flow asynchronously
const lassoLoader = require('lasso-loader');
/* globals gapi, _sdk */
/**
* Performs a one time OAuth 2.0 authorization.
* Depending on the parameters used, this will open a popup to the Google sign-in flow
* or try to load the requested response silently, without user interaction.
*/
function authenticate() {
return new Promise(function (resolve, reject) {
@cravindra
cravindra / facebook-auth.js
Created November 7, 2017 12:01
Simple wrapper which uses lasso-loader to enable facebook oauth asynchronously
const lassoLoader = require('lasso-loader');
/* globals FB, _sdk */
/**
* Performs a one time OAuth 2.0 authorization.
* Depending on the parameters used, this will open a popup to the Google sign-in flow
* or try to load the requested response silently, without user interaction.
*/
function authenticate() {
return new Promise(function (resolve, reject) {
/**
* Helper to inject the YouTube iFrame API script and initialise a YouTube video
* @param container {DOMElement | string} A Dom element or a string which is the id of the element to make a youtube video
* @param [playerOptions={}] {Object} An object as defined by the [YT iFrame API](https://developers.google.com/youtube/player_parameters)
*/
export default function inject(container, playerOptions={}) {
// Extract Player vars if available
const playerVars = {...(playerOptions.playerVars || {})};
delete playerOptions.playerVars;