Skip to content

Instantly share code, notes, and snippets.

View hungdoansy's full-sized avatar
📺

Hung Doan hungdoansy

📺
View GitHub Profile
@hungdoansy
hungdoansy / .hyper.js
Last active August 12, 2020 06:44
Hyper configuration
// Future versions of Hyper may add additional config options,
// which will not automatically be merged into this file.
// See https://hyper.is#cfg for all currently supported options.
module.exports = {
config: {
// choose either `'stable'` for receiving highly polished,
// or `'canary'` for less polished but more frequent updates
updateChannel: "stable",
@hungdoansy
hungdoansy / remove-ads.js
Last active September 15, 2020 01:45
User script used in TamperMonkey to remove ads in Facebooks' news feed | Currently, working with the new theme in English
// ==UserScript==
// @name Hide sponsored items
// @namespace whatisthis
// @version 0.1
// @description try to sanitize Facebook
// @author Sy Hung Doan
// @match https://www.facebook.com/*
// @match https://facebook.com/*
// @grant none
// ==/UserScript==
@hungdoansy
hungdoansy / useMultipleRefs.js
Created December 20, 2020 13:54
Use multiple refs for a list in React
/*
* This is helpful when you have multiple items and want to have some control over each of them.
*/
export const useMultipleRefs = (n) => {
const refs = useRef(
Array(n)
.fill(1)
.reduce((acc, _, index) => {
acc[index] = React.createRef();
@hungdoansy
hungdoansy / useQueryParam.js
Last active December 23, 2020 07:19
Simple & minimal useQueryParam hook
import { useCallback } from 'react';
import { useHistory, useLocation } from 'react-router-dom';
import queryString from 'query-string';
const useQueryParam = (key) => {
const history = useHistory();
const location = useLocation();
const { search } = location;
const params = queryString.parse(search);
@hungdoansy
hungdoansy / simpleCarousel.js
Last active January 21, 2021 11:56
Simple Carousel with React and styled-component
// Codesandbox: https://codesandbox.io/s/elegant-frog-hbs3f?file=/src/Carousel.js:0-5654
import React, { useRef, useState } from "react";
import classNames from "classnames";
import styled from "styled-components";
const ArrowDownContainer = styled.div`
display: flex;
justify-content: center;
align-items: center;
@hungdoansy
hungdoansy / compare.js
Created April 28, 2021 07:04
Compare Math.floor and ~~
const getNumbers = () => {
const numbers = [];
for(let i = 0; i < 50000; i++) {
const n = +(Math.random() * 10000).toFixed(5);
numbers.push(n);
}
return numbers;
}
@hungdoansy
hungdoansy / convert.js
Created May 12, 2021 05:07
Convert remote image into base64 with axios
const getBase64 = async url => {
const response = await axios.get(url, {
responseType: 'arraybuffer',
});
const imageType = response.headers['content-type'];
const base64 = Buffer.from(response.data, 'binary').toString('base64');
const dataURI = `data:${imageType};base64,${base64}`;
return dataURI;
@hungdoansy
hungdoansy / GPG and git on macOS.md
Created August 16, 2021 08:49 — forked from danieleggert/GPG and git on macOS.md
How to set up git to use the GPG Suite

GPG and git on macOS

Setup

No need for homebrew or anything like that. Works with https://www.git-tower.com and the command line.

  1. Install https://gpgtools.org -- I'd suggest to do a customized install and deselect GPGMail.
  2. Create or import a key -- see below for https://keybase.io
  3. Run gpg --list-secret-keys and look for sec, use the key ID for the next step
  4. Configure git to use GPG -- replace the key with the one from gpg --list-secret-keys

General

Request URL: https://www.binance.com/bapi/composite/v1/public/cms/article/catalog/list/query?catalogId=48&pageNo=1&pageSize=15
Request Method: GET
Status Code: 200 
Remote Address: 13.225.99.49:443
Referrer Policy: origin-when-cross-origin
@hungdoansy
hungdoansy / index.js
Last active January 17, 2022 03:38
Display built time in front end projects (I use React to illustrate)
console.log(`Built time: %c${new Date(Number(process.env.REACT_APP_BUILT_TIME) * 1000)}`, "color: #bada55");