Skip to content

Instantly share code, notes, and snippets.

View lvnam96's full-sized avatar
🐧
why are we still here? just to suffer?

nam lvnam96

🐧
why are we still here? just to suffer?
View GitHub Profile
@lvnam96
lvnam96 / clientOnly.js
Last active March 6, 2024 15:26
Resolve issue of passing `ref` on `dynamic()` (lazy) loaded component in NextJS
// Issue: https://github.com/vercel/next.js/issues/4957
/**
* Usage is the same as `dynamic()` from NextJS with 1 exception: `ssr` IS ALWAYS FALSE
* @param {() => any} importCallback Ex: () => import('./LazyComponent.jsx')
* @param {{ loading?: () => import('react').ReactNode }} options This can be similar to options of `dynamic()` from NextJS
*/
export const clientOnly = (importCallback, { loading } = {}) => {
const LazyComponent = lazy(importCallback);
@lvnam96
lvnam96 / ZustandStoreConsumer.svelte
Last active May 14, 2023 01:36
svelte-zustand (adapter)
<script lang="ts">
import { store, useAbcData, useSetData } from './store';
// you can import store & access its prop directly:
$: console.log('new changes will be logged here', $store.data);
// or grab its data via helper function:
const data = useAbcData(); // note that `data` is not subscribed to changes (like it should be if returned from a "react hook"). If you need to, use `$store.data` instead
const setData = useSetData(); // same goes here
</script>
@lvnam96
lvnam96 / keybase.md
Created February 29, 2020 19:14
Verify GibHub account on Keybase.io

Keybase proof

I hereby claim:

  • I am lvnam96 on github.
  • I am garyle (https://keybase.io/garyle) on keybase.
  • I have a public key ASANDhV83YJoVgoICRUwYZB-a5PPJMd4Q5Q0aTN6AAxD7wo

To claim this, I am signing this object:

function workAfterDataRetrieved (data) {
return new Promise((resolve) => {
// doSomeDutyTaskHere();
console.log('task done: ' + data.name);
resolve();
});
}
function getJSON (url) {
console.log('sent: ' + url);
@lvnam96
lvnam96 / README.md
Created November 19, 2019 08:45 — forked from magnetikonline/README.md
Responsive embedding of Google Maps (or anything <iframe> embedded really).

Responsive Google Maps embedding

Simple technique for embedding Google Maps <iframe>'s responsively using a padding-bottom percentage trick, which when applied to a block element will be calculated as a percentage of the element width - essentially providing an aspect ratio.

This technique should work on anything that is <iframe> embedded from your social network/service of choice.

@lvnam96
lvnam96 / gist:c3050960b4b199401cfff69790791c99
Last active March 6, 2024 08:15
Aliasing Git commands
git config --global alias.st status
git config --global alias.br branch
git config --global alias.co checkout
git config --global alias.ls 'log --oneline --decorate'
git config --global alias.sts stash
git config --global alias.cm commit
git config --global alias.cma 'commit --amend'
git config --global alias.rs reset
git config --global alias.rb rebase
git config --global alias.rbi 'rebase -i'
@lvnam96
lvnam96 / getRandomDarkHSLColor.js
Created September 4, 2017 06:27
Generate random dark HSL color (CSS) in JavaScript
const getRandomColor = () => {
const h = Math.floor(Math.random() * 360),
s = Math.floor(Math.random() * 100) + '%',
l = Math.floor(Math.random() * 60) + '%';// max value of l is 100, but I set to 60 cause I want to generate dark colors
// (use for background with white/light font color)
return `hsl(${h},${s},${l})`;
};
@lvnam96
lvnam96 / randomString.js
Last active October 17, 2018 00:45
Generate random string/characters in JavaScript (from Stack Overflow)
//https://stackoverflow.com/questions/1349404/generate-random-string-characters-in-javascript
(length => {
let text = '';
const POSSIBLE_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',
POSSIBLE_SCOPE = POSSIBLE_CHARS.length;
for (let i = 0; i < length; i += 1) {
text += POSSIBLE_CHARS.charAt(Math.floor(Math.random() * POSSIBLE_SCOPE));
}