Skip to content

Instantly share code, notes, and snippets.

View raghavgarg1257's full-sized avatar
🤘

Raghav Garg raghavgarg1257

🤘
View GitHub Profile
@raghavgarg1257
raghavgarg1257 / memorystats.js
Created October 4, 2019 07:02
Box8 Web SSR | memory profiling
const child_process = require('child_process');
const axios = require('axios');
const redis = require('redis');
const client = redis.createClient({ host: '127.0.0.1', port: 6379 });
const stats = {
category: [],
menu: [],
cart: [],
(() => {
const GRID_SIZE = 31;
const instructions = [
{
moveX: -Math.floor(GRID_SIZE / 2),
moveY: -Math.floor(GRID_SIZE / 2),
},
];
for (let x=0; x<GRID_SIZE - 1; x++) {
@raghavgarg1257
raghavgarg1257 / calc.js
Created May 30, 2019 08:16
closure and proto problem
function calc(value) {
const args = [value];
const recursiveCalc = function(value) {
if (args.length < 2) {
args.push(value);
}
return recursiveCalc;
}
recursiveCalc.__proto__.add = () => args[0] + args[1]
recursiveCalc.__proto__.substract = () => args[0] - args[1]

RUBY

internal_grids.outlet_ares_line_boundary_pluscodes.to_json

JS

coord_json = "[]"
grids = JSON.parse(coord_json);
grids.forEach(grid =&gt; {
import { ..., ErrorHandler } from '@angular/core';
import * as SentryNode from '@sentry/node'; // server SDK, should not load on browser
import { ErrorLogger } from './error-logger';
...
providers: [
...
{ provide: ErrorHandler, useFactory: ErrorLogger.initWith(SentryNode) }
]
import { ..., ErrorHandler } from '@angular/core';
import * as SentryBrowser from '@sentry/browser'; // browser SDK
import { ErrorLogger } from './error-logger';
...
providers: [
...
{ provide: ErrorHandler, useFactory: ErrorLogger.initWith(SentryBrowser) }
]
@raghavgarg1257
raghavgarg1257 / error-logger.ts
Last active September 24, 2020 09:54
Angular Universal, add Error Logger like Sentry. Medium Article
import { ErrorHandler } from '@angular/core';
import { environment } from '../environments/environment';
export class ErrorLogger implements ErrorHandler {
static initWith(sentry: any) {
return () => new ErrorLogger(sentry);
}
constructor(private sentry: any) {
{
"app":{
"name":"Spectrum [TEST]",
"audio_enabled":true,
"show_powered_by":true,
"active_admins":[
{
"id":"2310387",
"first_name":"Raghav",
"last_name":"Garg",
@raghavgarg1257
raghavgarg1257 / App.js
Last active July 1, 2018 11:05
Consider the use of `children` for wrapping everything in one component. Its very common to use this `children` prop.
import React, { Component } from 'react';
import { Route, Switch } from 'react-router-dom'
// import pages
import Container from './Container';
import Greetings from './Greetings';
import Customers from './Customers';
class App extends Component {
@raghavgarg1257
raghavgarg1257 / index-html.js
Created March 27, 2018 12:08
React only SSR (for apps using redux we need to do some more things)
// template for wrapping html
import WebpackHash from '../../public/webpack-hash';
export default function(html) {
return `
<!DOCTYPE html>
<html lang="en">
<head>