Skip to content

Instantly share code, notes, and snippets.

View PsyGik's full-sized avatar
🏠
Working from home

Dhanraj Padmashali PsyGik

🏠
Working from home
View GitHub Profile
@PsyGik
PsyGik / middleware.js
Created July 2, 2021 05:08
Express Request Headers
// Let Next.js handle rest of the routes
function modifyResponseBody(req, res, next) {
var oldSend = res.send;
res.send = function (data) {
// arguments[0] (or `data`) contains the response body
arguments[0] = 'modified : ' + arguments[0];
oldSend.apply(res, arguments);
};
res.on('finish', function () {
@PsyGik
PsyGik / collision.js
Created May 14, 2021 16:06
Snippet to detect collision and intersection between two DOM elements
const collision = {
collide: function (el1, el2) {
const rect1 = el1.getBoundingClientRect();
const rect2 = el2.getBoundingClientRect();
return !(
rect1.top > rect2.bottom ||
rect1.right < rect2.left ||
rect1.bottom < rect2.top ||
@PsyGik
PsyGik / micro-frontend.component.js
Created April 4, 2021 09:52
Code snippets for the blog post: Microfrontends are awesome!
import React from 'react';
import ScriptCache from './script-cache';
class MicroFrontend extends React.Component {
scriptCache;
abortController;
constructor(props) {
super(props);
@PsyGik
PsyGik / smooth-scrolling.js
Created August 17, 2019 18:30 — forked from drwpow/smooth-scrolling.js
Performant, 60FPS smooth scrolling in Vanilla JavaScript using requestAnimationFrame
/**
* @param {number} yPos Pixels from the top of the screen to scroll to
* @param {number} duration Time of animation in milliseconds
*/
const scrollTo = (yPos, duration = 600) => {
const startY = window.scrollY;
const difference = yPos - startY;
const startTime = performance.now();
const step = () => {
@PsyGik
PsyGik / index.ts
Last active January 30, 2019 11:53
The Build Series: E1 - Contact Form powered by Firebase Functions
import * as functions from 'firebase-functions';
const { google } = require('googleapis');
const express = require('express');
const cors = require('cors');
const app = express();
// Automatically allow cross-origin requests
app.use(cors({ origin: true }));
@PsyGik
PsyGik / projects.json
Last active February 7, 2019 08:56
contents for personal website
[
{
"title": "MyBusTracker.live",
"url": "https://app.mybustracker.live",
"excerpt": "Manage all your Students, Vehicles and Staff information. See real-time updates for the bus, its estimated time of arrival and delays if any.\n Be informed of any incidents by real-time push notificationns. Generate reports and rate drivers by A.I driven scoring algorithm.\n ",
"info": [
"Built the entire system from ground up in 3 months",
"Used NestJS as backend frameword",
"Developed the front-end using Angular",
"Configured Gitlab CI/CD for Backend and Frontend",
@PsyGik
PsyGik / clipboard.html
Created December 12, 2018 07:04 — forked from LewdEwe-ErikWallace/clipboard.html
This is an example of how to poll the clipboard for changes in an Electron application. See notes in HTML.
<!DOCTYPE html>
<html lang="en">
<head>
<title>My App - Clipboard</title>
<meta charset="utf-8">
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self' chrome-extension://*;">
</head>
<body>
@PsyGik
PsyGik / onesingal.service.ts
Created November 24, 2018 06:49
OneSignal Angular TypeScript
import {Injectable} from '@angular/core';
import {Cache} from '../utils/storage.provider'; // Decorator to access local storage
let OneSignal;
const url = '';
@Injectable()
export class OneSignalService {
@Cache({pool: 'OneSignal'}) oneSignalInit; // to check if OneSignal is already initialized.
@PsyGik
PsyGik / FingerprintUIHelper.java
Created October 30, 2018 09:15
Android Fingerprint Authentication Helper Class
import android.annotation.TargetApi;
import android.app.KeyguardManager;
import android.hardware.fingerprint.FingerprintManager;
import android.os.Build;
import android.os.CancellationSignal;
import android.security.keystore.KeyGenParameterSpec;
import android.security.keystore.KeyProperties;
import java.io.IOException;
@PsyGik
PsyGik / nodejs-tcp-example.js
Created June 30, 2018 16:08 — forked from tedmiston/nodejs-tcp-example.js
Node.js TCP client and server example
/*
In the node.js intro tutorial (http://nodejs.org/), they show a basic tcp
server, but for some reason omit a client connecting to it. I added an
example at the bottom.
Save the following server in example.js:
*/
var net = require('net');