Skip to content

Instantly share code, notes, and snippets.

@g-patel
g-patel / gist:2e1301de8caaa3d088ff71bd29cbe6a7
Created May 20, 2019 04:39
Sample.tsx ans SampleTests.tsx (How "rendering" deals with React Elements, and only react elements)
//Sample.tsx
import * as React from 'react';
export function Tiny(props: any) {
return (
<div id="tiny" ></div>
);
}
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<div id="root">nothing rendered yet</div>
<script src='https://unpkg.com/[email protected]/umd/react.development.js'></script>
<script src='https://unpkg.com/[email protected]/umd/react-dom.development.js'></script>
<script src="https://unpkg.com/@babel/[email protected]/babel.js"></script>
@g-patel
g-patel / index.js
Last active February 14, 2017 20:43
import Vue from 'vue';
Vue.config.devtools = true;
const componentsContext = require.context('./components', true, /\.vue$/);
const ComponentsById = {};
const ComponentsByName = {};
const ComponentsMap = {};
const cMap = {};
const ComponentNames = [];
require('./index.styl');
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';
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';
@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: ''
};
@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>
<!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 / 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');
}
})();
@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));