Skip to content

Instantly share code, notes, and snippets.

View neharkarvishal's full-sized avatar

Vishal Neharkar neharkarvishal

View GitHub Profile

Timeseries Data in MySQL

  • IOT Readings
  • Performance Metrics
  • Heartbeat System

We operate on the tinesearies data, chunk it down into buckets and run mins, avgs and maxes over all of that data

-- If you know how to convert recursive code to iterative code with its own stack,
-- then you understand recursion and can answer simple interview questions about it.
-- mysql 8 and above
CREATE TABLE nodes (
node INT NOT NULL,
parent INT,
-- add any other columns used in the query here
PRIMARY KEY (node),
FOREIGN KEY (parent) REFERENCES nodes(node)
import axios from "axios";
import {v4 as uuid} from 'uuid'
const API_URL = `${process.env.REACT_APP_URL}/`;
const Axios = axios.create({
baseURL: API_URL,
});
//API Call Interceptor to add token to the header.
Axios.interceptors.request.use(
const b64toBlob = (b64Data, contentType = "", sliceSize = 512) => {
const byteCharacters = atob(b64Data);
const byteArrays = [];
for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) {
const slice = byteCharacters.slice(offset, offset + sliceSize);
const byteNumbers = new Array(slice.length);
for (let i = 0; i < slice.length; i++) {
byteNumbers[i] = slice.charCodeAt(i);
@neharkarvishal
neharkarvishal / generateCacheKey.js
Created January 7, 2023 09:08
Generate Cache Key
'use strict';
const { generateHeadersKey } = require('./generateHeadersKey');
const { generateQueryParamsKey } = require('./generateQueryParamsKey');
function generateCacheKey(
ctx,
keys = {
useQueryParams: false, // @todo: array or boolean => can be optimized
useHeaders: [],
@neharkarvishal
neharkarvishal / withTimeout.js
Created January 7, 2023 09:05
Reject promise after timeout
/**
* Reject promise after timeout
*
* @todo this is slow, we should find a way to do this in a faster way
* @param {Promise<any>} callback
* @param {number} ms
* @return {Promise<never>}
*/
function withTimeout(callback, ms) {
let timeout;
/*------------------------------------------
Responsive Grid Media Queries - 1280, 1024, 768, 480
1280-1024 - desktop (default grid)
1024-768 - tablet landscape
768-480 - tablet
480-less - phone landscape & smaller
--------------------------------------------*/
@media all and (min-width: 1024px) and (max-width: 1280px) { }
@media all and (min-width: 768px) and (max-width: 1024px) { }
import { Extension } from '@tiptap/core';
import { ComponentType } from 'react';
import { ContextMenuPlugin, ContextMenuProps } from './ContextMenuPlugin';
interface ContextMenuOptions {
component: ComponentType<ContextMenuProps>;
}
export const ContextMenu = Extension.create<ContextMenuOptions>({
name: 'contextMenu',
/**
* Generate html string suitable for rendering in PDF
*/
export const generateReportPdfHTML = async (options: GenerateReportPdfOptions): Promise<string> => {
const pages = CustomReportTemplate({ ...options, ssr: true });
const pagesContent = _.map(pages, ({ name, content }) => (
<Flex key={`box-${name}`} flexDir="column" h="100vh" style={{ pageBreakBefore: 'always' }}>
{content}
</Flex>
@neharkarvishal
neharkarvishal / media.js
Created August 27, 2022 11:37
Media Queries in CSS, JavaScript and with RxJS
/**
* The vanilla javascript way of implementing such a functionality would be to use
* he window's matchMedia function. The function takes a string query and
* returns a MediaQueryList that can be used to get the current result of the
* query and listen to changes of the media query.
*/
const mediaQueryList = window.matchMedia(`(min-width: 767px)`);
console.log(mediaQueryList.matches); // true or false