Skip to content

Instantly share code, notes, and snippets.

View hoyangtsai's full-sized avatar
⌨️
Prompting

Hoyang Tsai hoyangtsai

⌨️
Prompting
View GitHub Profile
@hoyangtsai
hoyangtsai / useAfterPaintEffect.js
Created January 2, 2024 08:15
#react #useEffect after paint
function useAfterPaintEffect(effect, dependencies) {
useEffect(() => {
requestAnimationFrame(() => {
setTimeout(() => {
effect();
}, 0);
});
}, dependencies);
}
@hoyangtsai
hoyangtsai / min.js
Created June 21, 2023 01:05
#BigInt #math min function
function min(...values) {
if (values.length < 1) {
return Infinity;
}
let minValue = values.shift();
for (const value of values) {
if (value < minValue) {
minValue = value;
@hoyangtsai
hoyangtsai / replace.js
Created May 29, 2023 11:19
replace a word in a sentence #snippet
'Brave New World'.split('New').join('Old')
// "Brave Old World"
@hoyangtsai
hoyangtsai / currency.js
Created December 12, 2022 02:13
currency format with Intl.NumberFormat
const amount = new Intl.NumberFormat('id-ID', {
style: 'currency',
currency: 'IDR'
}).format("15000");
console.log(amount);
@hoyangtsai
hoyangtsai / qrcode.html
Created October 27, 2022 07:32
generate qrcode from url
<html>
<body>
<div id="qrcode"></div>
<script src="https://cdn.jsdelivr.net/gh/davidshimjs/qrcodejs/qrcode.min.js"></script>
<script>
const qrcode = new QRCode(document.getElementById('qrcode'), {
text: 'http://jindo.dev.naver.com/collie',
width: 128,
@hoyangtsai
hoyangtsai / toinline.js
Last active August 21, 2022 10:17
Simple convert an object of styles into #inlineStyle #CSS string
const style = {
width: 400,
height: 300,
position: 'fixed',
top: 900,
left: 60,
'z-index': 1234
}
const inline = Object.entries(style).reduce((prev, curr) => {
@hoyangtsai
hoyangtsai / example.js
Created April 17, 2022 07:12
#js instanceof check
function Product(name, price) {
this.name = name;
this.price = price;
}
function Food(name, price) {
Product.call(this, name, price);
this.category = 'food';
}
@hoyangtsai
hoyangtsai / pagination.vue
Last active March 26, 2022 13:52
limit pagination
<script>
import { ref, watch } from 'vue'
export default {
props: {
totalPages: Number,
currentPage: Number,
},
setup(props) {
let numShown = 5;
@hoyangtsai
hoyangtsai / qs.js
Created January 20, 2022 17:54
object to url query string #snippet
// convert objec to a query string
const qs = Object.keys(params)
.map(key => `${key}=${params[key]}`)
.join('&');
// OR
var queryString = Object.keys(params).map((key) => {
return encodeURIComponent(key) + '=' + encodeURIComponent(params[key])
}).join('&');
@hoyangtsai
hoyangtsai / style.css
Created January 9, 2022 17:44
#MediaQuery #CSSHack
/* target IE 6 and 7 */
@media screen\9 {
/* custom style */
}
/* target IE 6, 7 and 8 */
@media \0screen\,screen\9 {
/* custom style */
}