Skip to content

Instantly share code, notes, and snippets.

@gauravtiwari
gauravtiwari / convention.js
Last active Feb 19, 2017
folder structure
View convention.js
// 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 Mar 26, 2017
Gemfile_edge
View Gemfile
source 'https://rubygems.org'
ruby '2.2.6'
gem 'rails', '~> 5.1.x'
gem 'sprockets', '~> 4.x'
View stackexchange_client_oauth.es6.js
/* 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 Nov 19, 2016
Use linkedin client side sdk for oauth2
View linkedin_client_oauth.es6.js
/* 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 Nov 19, 2016
Use google client side sdk to authenticate a user and retreive access token.
View google_client_oauth.es6.js
/* 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 Sep 27, 2021
Promise based popup window for server oAuth
View window-auth-popup.es6.js
/* 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 Oct 2, 2016
A minimal sinatra app to execute queries against GraphQL server.
View sinatra_graphql_erb.rb
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 Oct 2, 2016
A list of queries declared in ruby to execute against given graphql server
View graphql_client_queries.rb
IndexQuery = API::Client.parse <<-'GRAPHQL'
query {
root {
id,
tags,
posts(first: 10) {
edges {
node {
id,
title,
@gauravtiwari
gauravtiwari / graphql_client.rb
Created Oct 2, 2016
Initialise graphql client
View graphql_client.rb
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 Aug 13, 2016
A dynamic react relay component renderer
View renderer.js
/*
Mount and Unmount react components at nodes
*/
/* global Turbolinks, ReactHelper */
import ReactDOM from 'react-dom';
import Relay from 'react-relay';
import React from 'react';