Skip to content

Instantly share code, notes, and snippets.

View chinchang's full-sized avatar
🏠
Building cssbattle.dev

Kushagra Gour chinchang

🏠
Building cssbattle.dev
View GitHub Profile
@chinchang
chinchang / usePromiseState.js
Created May 21, 2024 07:07
A custom wrapper hook for useState that return a promise on calling setValue
/**
* A custom wrapper hook for useState that return a promise
* on calling setValue.
* Useful with APIs like document.startViewTransition
*
* Demo: https://codesandbox.io/p/sandbox/react-view-transition-list-3ycjj9
*
*/
import { useEffect, useRef, useState } from "react";
@chinchang
chinchang / relative-time-format.js
Created June 11, 2020 17:47
relative time format
new Intl.RelativeTimeFormat('en', {
style: 'narrow'
}).format(-10, 'day')
// "10 days ago"
new Intl.RelativeTimeFormat('en', {
style: 'narrow'
}).format(10, 'day')
// "in 10 days"
@chinchang
chinchang / plural-units.js
Created May 25, 2020 04:13
Handling singular/plural for number units
new Intl.NumberFormat(undefined, {
style: "unit",
unit: 'kilometer',
unitDisplay: 'long'
}).format(10)
//"10 kilometres"
new Intl.NumberFormat(undefined, {
style: "unit",
unit: 'kilometer',
@chinchang
chinchang / currency-number-formatting.js
Created May 24, 2020 07:59
Formatting a number as currency
new Intl.NumberFormat(undefined, {
style: 'currency',
currency: 'INR'
}).format(23213)
//"₹23,213.00"
new Intl.NumberFormat('de-DE', {
style: 'currency',
currency: 'EUR'
}).format(23213)
@chinchang
chinchang / compact-number-formatting.js
Created May 23, 2020 15:18
Formatting numbers into approximate compact form
new Intl.NumberFormat(undefined, {
notation: 'compact'
}).format(12200);
// "12K"
new Intl.NumberFormat(undefined, {
notation: 'compact'
}).format(12534200);
// "13M"
async function loop() {
for (let i = 0; i < 10; i++) {
document.body.innerHTML += i + " ";
await waitForEvent();
}
}
function waitForEvent() {
return new Promise(resolve => {
window.onclick = () => {
@chinchang
chinchang / remote-first-tech-companies
Created October 1, 2019 10:33
List of good remote first companies in tech
- DuckDuckgo - https://duckduckgo.com/hiring/
- Gitlab - https://about.gitlab.com/jobs/
- Invision - https://www.invisionapp.com/about/#jobs
- Automattic - https://automattic.com/work-with-us/
- Doist - https://doist.com/jobs/
- Zapier - https://zapier.com/jobs/
- Gatsby - https://www.gatsbyjs.com/careers/
- Netlify - https://www.netlify.com/careers/
- Airbase - https://angel.co/company/airbase-1/jobs
- Hasura - https://hasura.io/careers
@chinchang
chinchang / c-exercises.md
Last active October 13, 2019 06:32
C exercises

Program 1

  • Take a sentence as input from user
  • Calculate and show: sentence's length, number of vowels.

Program 2

  • Take a number n between 5-20 as input from user
  • Create an array of length n
  • Put random number (1-100) in each element of the array
  • Display the array's element by comma separated. Eg. 1,56,2,88,2
  • Show the sum of the all the elements of the array
@chinchang
chinchang / endpoint.js
Created February 26, 2019 18:36
Now lambda issue
const PixelDiff = require('pixel-diff')
module.exports = async (req, res) => {
res.statusCode = 200
res.setHeader('Content-Type', `text/plain`)
res.setHeader('Cache-Control', 'no-cache')
res.end('done!')
}
@chinchang
chinchang / game.html
Last active March 23, 2020 13:43
A simple game for my talk at GDG devfest '18
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<style id="webmakerstyle">
body {
padding: 0;
margin: 0;