Skip to content

Instantly share code, notes, and snippets.

View nickpricks's full-sized avatar

Nitesh Kachroo nickpricks

  • Chandigarh, India
View GitHub Profile
const expr = 'Papayas';
// old way
switch (expr) {
case 'Oranges':
console.log('Oranges are $0.59 a pound.');
break;
case 'Apples':
console.log('Apples are $0.32 a pound.');
break;
@nickpricks
nickpricks / useScroll.js
Created December 16, 2020 10:28 — forked from joshuacerbito/useScroll.js
Custom React hook for listening to scroll events
/**
* useScroll React custom hook
* Usage:
* const { scrollX, scrollY, scrollDirection } = useScroll();
*/
import { useState, useEffect } from "react";
export function useScroll() {
const [lastScrollTop, setLastScrollTop] = useState(0);
@nickpricks
nickpricks / stopwatch.sh
Created January 11, 2020 07:14 — forked from busterc/stopwatch.sh
stopwatch with laps for bash #bash
#!/bin/bash
function stopwatch() {
local n=0
local t=0
local continuing="true"
local lap=1
local key="~"
local pausing="~"
@nickpricks
nickpricks / node-on-ec2-port-80.md
Created December 18, 2019 05:36 — forked from kentbrew/node-on-ec2-port-80.md
How I Got Node.js Talking on EC2's Port 80

The Problem

Standard practices say no non-root process gets to talk to the Internet on a port less than 1024. How, then, could I get Node talking on port 80 on EC2? (I wanted it to go as fast as possible and use the smallest possible share of my teeny tiny little micro-instance's resources, so proxying through nginx or Apache seemed suboptimal.)

The temptingly easy but ultimately wrong solution:

Alter the port the script talks to from 8000 to 80:

}).listen(80);
@nickpricks
nickpricks / .editorconfig
Created December 12, 2019 04:47
Best practices (and my favorite) for js,jsx,ts,tsx,json
[*.{js,jsx,ts,tsx,json}]
indent_size = 2
indent_style = space
trim_trailing_whitespace = true
end_of_line = lf
insert_final_newline = true
charset = utf-8
max_line_length = 120
@nickpricks
nickpricks / LICENSE.txt
Created November 29, 2019 12:13 — forked from jed/LICENSE.txt
generate random UUIDs
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Jed Schmidt <http://jed.is>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@nickpricks
nickpricks / altered-in-last-N-days.sql
Created December 20, 2018 09:57
MS-SQL Query to list UserTables altered within last N Days
DECLARE @N int = 100;
SELECT name, create_date, modify_date
FROM sys.objects
WHERE [type] = 'U' AND modify_date >= GETDATE() - @N
ORDER BY modify_date DESC;
@nickpricks
nickpricks / min-max-js-dates-arr.js
Created November 27, 2018 11:21
find min max in js array of dates
var dz = ["2018-11-29T00:00:00.000Z","2018-11-30T00:00:00.000Z","2018-11-29T00:00:00.000Z","2018-12-01T00:00:00.000Z","2018-12-01T00:00:00.000Z","2018-12-02T00:00:00.000Z","2018-12-03T00:00:00.000Z","2018-12-04T00:00:00.000Z","2018-12-05T00:00:00.000Z","2018-12-06T00:00:00.000Z","2018-12-07T00:00:00.000Z","2018-12-08T00:00:00.000Z"].map(i => new Date(i));
var mx = Math.max(...dz);
var ni = Math.min(...dz);
console.log('\n\nMax date => ', new Date(mx), '\n\nMin date => ', new Date(ni));
let io = {};
const eventService = require('../services/eventService');
const csvHelper = require('../helpers/csvHelper');
exports.plugin = {
name: 'hapi-real-notification',
register: (server, options) => {
io = require('socket.io')(server.listener);
const redis = require('socket.io-redis');
io.adapter(redis({ host: options.host, port: options.port }));
@nickpricks
nickpricks / LICENSE
Created August 17, 2018 05:51 — forked from ourmaninamsterdam/LICENSE
Arrayzing - The JavaScript array cheatsheet
The MIT License (MIT)
Copyright (c) 2015 Justin Perry
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions: