Skip to content

Instantly share code, notes, and snippets.

View MehulATL's full-sized avatar

Mehul Patel MehulATL

View GitHub Profile
@MehulATL
MehulATL / reactstreaming.js
Created July 23, 2020 21:31 — forked from dabit3/reactstreaming.js
React Streaming code from live broadcast
import React from 'react';
import logo from './logo.svg';
import './App.css';
import ReactPlayer from 'react-player'
import { HashRouter, Link, Switch, Route } from 'react-router-dom'
import AuthComponent from './AuthComponent'
import { Auth, API } from 'aws-amplify'
import { createComment as CreateComment } from './graphql/mutations'
import { listComments as ListComments } from './graphql/queries'
import { onCreateComment as OnCreateComment } from './graphql/subscriptions'
@MehulATL
MehulATL / .profile
Last active December 3, 2019 17:02
.profile lol
# get current branch in git repo
function parse_git_branch() {
BRANCH=`git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'`
if [ ! "${BRANCH}" == "" ]
then
STAT=`parse_git_dirty`
echo "[${BRANCH}${STAT}]"
else
echo ""
fi
@MehulATL
MehulATL / config.js
Last active December 3, 2019 17:00
hyper term settings
module.exports = {
config: {
// default font size in pixels for all tabs
fontSize: 18,
// font family with optional fallbacks
fontFamily: 'Operator Mono Ssm',
// fontFamily: 'Monaco, Menlo, "DejaVu Sans Mono", "Lucida Console", monospace',
// terminal cursor background color and opacity (hex, rgb, hsl, hsv, hwb or cmyk)

Parens And Performance

Years ago, some smart folks that worked on JS engines realized that not all JS that's loaded into a page/app initially is needed right away. They implemented JIT to optimize this situation.

JIT means Just-In-Time, which means essentially that the engine can defer processing (parsing, compiling) certain parts of a JS program until a later time, for example when the function in question is actually needed. This deferral means the engine is freer to spend the important cycles right now on the code that's going to run right now. This is a really good thing for JS performance.

Some time later, some JS engine devs realized that they needed to get some hints from the code as to which functions would run right away, and which ones wouldn't. In technical speak, these hints are called heuristics.

So they realized that one very common pattern for knowing that a function was going to run right away is if the first character before the function keyword was a (, because that usually m

@MehulATL
MehulATL / styles.less
Created August 27, 2016 23:25
me atom font styling
//add the following styles to use ur font
atom-text-editor {
font-family: "Operator Mono Ssm";
font-size: 16px;
font-weight: 100;
line-height: 1.6;
letter-spacing: -0.5px;
}
.entity.other.attribute-name {
font-style: italic;
@MehulATL
MehulATL / index.js
Last active March 24, 2016 18:51
troll(React)
if(deepEquals(lastRenderedViewData, viewData)) return;
lastRenderedViewData = viewData;
function compare(expected, actual) {
if (typeof(actual) !== typeof(expected)) {
return false;
}
if (typeof(expected) !== 'object' || expected === null) {
return expected === actual;
}
if (!!expected && !actual) {
return false;
}
@MehulATL
MehulATL / index.js
Created November 26, 2015 00:17
simple express server
// Server
var express = require('express');
var app = express();
// Store all environment variables
app.set('port', process.env.PORT || 3001);
app.set('env', process.env.NODE_ENV || 'production');
// App middleware
// serve index.html at this path
@MehulATL
MehulATL / app.js
Created June 29, 2015 23:18
declare view title in ui.router state declaration
.run(function($rootScope, $injector, $state, $stateParams) {
$rootScope.$state = $state;
$rootScope.$stateParams = $stateParams;
$rootScope.$title = function() {
if (angular.isFunction($state.current.title)) {
return $injector.invoke($state.current.title, $rootScope, {
$scope: $rootScope,
$currentState: $state.current
});
<?xml version="1.0" encoding="UTF-8"?>
<!-- Dracula Theme v0.7.6
#
# https://github.com/zenorocha/dracula-theme
#
# Copyright 2015, All rights reserved
#
# Code licensed under the MIT license
# http://zenorocha.mit-license.org