Skip to content

Instantly share code, notes, and snippets.

(function () {
var root = $(document.getElementsByTagName('body'));
var watchers = [];
var f = function (element) {
if (element.data().hasOwnProperty('$scope')) {
angular.forEach(element.data().$scope.$$watchers, function (watcher) {
watchers.push(watcher);
});
}
@g-patel
g-patel / parasitic-combination-inheritance.js
Last active February 12, 2018 21:59
Javascript oop. This example illustrates that es5 constructors and es6 classes are interoperable in an inheritance chain. So es6 classes are sugar syntax, while the prototype based inheritance is still the underlying implementation by the language.
class Car {
constructor (config) {
this.make = config.make || 'Unknown';
this.model = config.model || 'Unknown';
}
get price() {
return this.price;
}
@g-patel
g-patel / coffee sucks
Last active January 29, 2016 21:13
coffe sucks
//coffee
[1,2,3].push [4] .map .reduce
//js
// Generated by CoffeeScript 1.10.0
(function() {
[1, 2, 3].push([4].map.reduce);
}).call(this);
@g-patel
g-patel / gist:e7bb20108fccdf6dfb658ee3bddeefe3
Last active April 20, 2016 21:23
Bable transpiles ES6 modules to CommonJS modules
C02Q10QCG8WM:~ gpatel$ ./node_modules/.bin/babel -d ~/tmp/es5-compiled --presets es2015 ~/tmp/lib.js ~/tmp/main.js
/Users/gpatel/tmp/lib.js -> /Users/gpatel/tmp/es5-compiled/Users/gpatel/tmp/lib.js
/Users/gpatel/tmp/main.js -> /Users/gpatel/tmp/es5-compiled/Users/gpatel/tmp/main.js
C02Q10QCG8WM:~ gpatel$ cat ~/tmp/lib.js ~/tmp/main.js ~/tmp/es5-compiled/Users/gpatel/tmp/*
export const sqrt = Math.sqrt;
export function square(x) {
return x * x;
}
export function diag(x, y) {
return sqrt(square(x) + square(y));
@g-patel
g-patel / event-loop.js
Last active September 17, 2016 07:04
If you can tell output of following program, you probably know javascript event loop. Ref: https://mzl.la/1T3wZ3U
(function() {
for(let i=0; i<1000 ;i++) {
setTimeout(function() {
console.log(`Hi`);
}, 0);
}
for(let i=0; i<1000; i++) {
console.log('Hello');
}
})();
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Untitled benchmark</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
@g-patel
g-patel / index.html
Created December 9, 2016 01:22 — forked from RubaXa/index.html
Array#forEach (http://jsbench.github.io/#934845e96f163934870e) #jsbench #jsperf
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Array#forEach</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
@g-patel
g-patel / Component.js
Created January 18, 2017 19:02
Vuejs Server side rendering with async data
Vue.Component({
name: 'foo',
template: `
<section v-html="markup"></section>
`,
props: [],
data() {
return {
markup: ''
};
var config = require('../config');
var webpack = require('webpack');
var merge = require('webpack-merge');
var utils = require('./utils');
var path = require('path');
var projectRoot = path.resolve(__dirname, '../');
var baseWebpackConfig = require('./webpack.common');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
const ENV = process.env.ENV = process.env.NODE_ENV = 'production';
const webpack = require('webpack');
const helpers = require('./helpers');
const config = require('../config');
const path = require('path');
const projectRoot = path.resolve(__dirname, '../');
const utils = require('./utils');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const ENV = process.env.NODE_ENV || 'development';