Skip to content

Instantly share code, notes, and snippets.

@gauravtiwari
gauravtiwari / convention.js
Last active February 19, 2017 10:42
folder structure
// entry: app/javascript/packs/calendar.js
require('calendar') or import 'calendar'; // in es6 world
// 1. Angular app
// Main index file that loads all dependent code and bootstraps module to DOM if required
require('./components/calendar.js') or import './components/calendar.js';
require('./models/calendar.js') or import './models/calendar.js';
// app/javascript/calendar/index.js
// Modular js much like rails app folder
@gauravtiwari
gauravtiwari / Gemfile
Last active March 26, 2017 09:07
Gemfile_edge
source 'https://rubygems.org'
ruby '2.2.6'
gem 'rails', '~> 5.1.x'
gem 'sprockets', '~> 4.x'
@gauravtiwari
gauravtiwari / stackexchange_client_oauth.es6.js
Created November 19, 2016 11:29
Stackexchange client side oauth
/* global window SE */
import $ from 'jquery';
export default class StackExchange {
constructor() {
$.getScript(window.STACKOVERFLOW_JS_SDK_URL, (data, textStatus) => {
if (textStatus === 'success') {
SE.init({
clientId: `${window.STACKOVERFLOW_CLIENT_ID}`,
@gauravtiwari
gauravtiwari / linkedin_client_oauth.es6.js
Created November 19, 2016 11:29
Use linkedin client side sdk for oauth2
/* global window IN Routes */
import $ from 'jquery';
export default class Linkedin {
constructor() {
$.getScript(window.LINKEDIN_JS_SDK_URL, (data, textStatus) => {
if (textStatus === 'success') {
IN.init({
api_key: window.LINKEDIN_CLIENT_ID,
@gauravtiwari
gauravtiwari / google_client_oauth.es6.js
Created November 19, 2016 11:28
Use google client side sdk to authenticate a user and retreive access token.
/* global window document gapi */
import $ from 'jquery';
export default class Google {
constructor() {
$.getScript(window.GOOGLE_JS_SDK_URL, (data, textStatus) => {
if (textStatus === 'success' && gapi !== undefined) {
gapi.load('client:auth2', this.initClient);
}
@gauravtiwari
gauravtiwari / window-auth-popup.es6.js
Last active April 12, 2024 00:56
Promise based popup window for server oAuth
/* global window */
const popup = (url) => {
const windowArea = {
width: Math.floor(window.outerWidth * 0.8),
height: Math.floor(window.outerHeight * 0.5),
};
if (windowArea.width < 1000) { windowArea.width = 1000; }
if (windowArea.height < 630) { windowArea.height = 630; }
@gauravtiwari
gauravtiwari / sinatra_graphql_erb.rb
Created October 2, 2016 10:28
A minimal sinatra app to execute queries against GraphQL server.
class SinatraGraphqlErb < Sinatra::Base
set public_folder: 'public', static: true
use Rack::Session::Cookie, secret: 'super_secret_client_key'
use Rack::Protection
use Rack::Protection::RemoteReferrer
use Sass::Plugin::Rack
private
def query(definition, variables = {})
@gauravtiwari
gauravtiwari / graphql_client_queries.rb
Created October 2, 2016 10:23
A list of queries declared in ruby to execute against given graphql server
IndexQuery = API::Client.parse <<-'GRAPHQL'
query {
root {
id,
tags,
posts(first: 10) {
edges {
node {
id,
title,
@gauravtiwari
gauravtiwari / graphql_client.rb
Created October 2, 2016 10:21
Initialise graphql client
module API
HTTPAdapter = GraphQL::Client::HTTP.new(ENV['API_URL'])
#
# Pass block to send auth token
# def headers(context)
# {
# "Authorization" => "Bearer #{ENV['ACCESS_TOKEN']}"
# }
# end
@gauravtiwari
gauravtiwari / renderer.js
Created August 13, 2016 15:31
A dynamic react relay component renderer
/*
Mount and Unmount react components at nodes
*/
/* global Turbolinks, ReactHelper */
import ReactDOM from 'react-dom';
import Relay from 'react-relay';
import React from 'react';