Skip to content

Instantly share code, notes, and snippets.

Gaurav Tiwari gauravtiwari

View GitHub Profile
View create_heroku_ruby_with_node.sh
heroku create
heroku addons:create heroku-postgresql:hobby-dev
git push heroku master
@gauravtiwari
gauravtiwari / index.js
Created Feb 19, 2017
Counter index initializer
View index.js
// Initialize the counter code when DOM is ready
import './style.sass';
import counter from './counter';
document.addEventListener('DOMContentLoaded', () => {
counter.initialize();
});
View style.sass
$grey: #f2f2f2
.counter-wrapper
max-width: 500px
margin: 100px auto
padding: 10px
border: 1px solid $grey
form
@gauravtiwari
gauravtiwari / counter.js
Created Feb 19, 2017
Counter entry file
View counter.js
// Require or import the counter module
import '../counter';
@gauravtiwari
gauravtiwari / index.js
Created Feb 19, 2017
Initialise counter on DOM ready
View index.js
// Initialize the counter code when DOM is ready
import counter from './counter';
document.addEventListener('DOMContentLoaded', () => {
counter.initialize();
});
@gauravtiwari
gauravtiwari / counter.js
Created Feb 19, 2017
A simple counter example using vanilla JS
View counter.js
// A simple counter example
// The setup will be more complicated in modern apps built using React
const incrementNode = document.getElementById('increment');
const decrementNode = document.getElementById('decrement');
const inputNode = document.getElementById('counter');
const counter = {
initialize() {
incrementNode.addEventListener('click', (event) => {
@gauravtiwari
gauravtiwari / production.js
Last active Feb 19, 2017
Production webpack config
View production.js
// Note: You must restart bin/webpack-watcher for changes to take effect
var webpack = require('webpack')
var merge = require('webpack-merge')
var sharedConfig = require('./shared.js')
module.exports = merge(sharedConfig.config, {
output: { filename: '[name]-[hash].js' },
@gauravtiwari
gauravtiwari / development.js
Created Feb 19, 2017
Development webpack config
View development.js
// Note: You must restart bin/webpack-watcher for changes to take effect
var webpack = require('webpack')
var merge = require('webpack-merge')
var sharedConfig = require('./shared.js')
module.exports = merge(sharedConfig.config, {
devtool: 'sourcemap',
@gauravtiwari
gauravtiwari / shared.js
Last active Feb 22, 2017
Shared webpack config
View shared.js
// Note: You must restart bin/webpack-watcher for changes to take effect
var path = require('path');
var glob = require('glob');
var extname = require('path-complete-extname');
var distPath = process.env.WEBPACK_DIST_PATH;
if (distPath === undefined) {
distPath = 'packs'
}
@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
You can’t perform that action at this time.