Skip to content

Instantly share code, notes, and snippets.

View picaq's full-sized avatar
๐Ÿ“
๐ŸŒธ๐ŸŒท๐ŸŒน๐ŸŒผ๐ŸŒธ๐ŸŒท๐ŸŒน๐ŸŒธ

Mandy Chen picaq

๐Ÿ“
๐ŸŒธ๐ŸŒท๐ŸŒน๐ŸŒผ๐ŸŒธ๐ŸŒท๐ŸŒน๐ŸŒธ
View GitHub Profile
@picaq
picaq / mapIncrementDecrement.js
Created March 7, 2025 01:42
Javascript Maps
let map = new Map();
const incrementMapVal = (map, key) => {
const currentValue = map.has(key) ? map.get(key) : 0;
map.set(key, currentValue + 1);
}
const decrementMapVal = (map, key) => {
const currentValue = map.has(key) && map.get(key);
currentValue > 1 ? map.set(key, currentValue - 1) : map.delete(key);
let randomize = list => console.log(list[Math.floor(list.length * Math.random())]);
@picaq
picaq / info table formatting.md
Created November 2, 2024 03:31
Markdown formatting
List 1: Info 1
List 2: Info 2
List 3: Info 3
@picaq
picaq / try catch await async network.js
Created September 14, 2024 00:16
Try catch and await async in a network API request
const getCityValues = async () => {
try {
const response = await fetch(
`https://data.epa.gov/efservice/getEnvirofactsUVHourly/CITY/Seattle/STATE/WA/JSON`
);
const jsonData = await response.json();
console.log(jsonData);
} catch (error) {
console.error(error.message);
console.error(userCity, 'is not found!');
@picaq
picaq / count occurrences of chars or substring occurances in string.js
Last active August 29, 2024 22:02
String manipulation, counting and accounting
const count = (str, subst) => str.match( new RegExp(subst, "g") )?.length || 0;
@picaq
picaq / currency.js
Last active August 25, 2024 02:31
Formatted Math
// guide : https://www.freecodecamp.org/news/how-to-format-number-as-currency-in-javascript-one-line-of-code/
// format number to US dollar
let usd = new Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'USD',
});
let cad = new Intl.NumberFormat('en-CA', {
style: 'currency',

Fine typography for the web

  1. the easiest way to edit and update CSS is with the Stylus plugin to specify user styles
  2. a js bookmarklet or snippet is used to inject quote classes for styling

view the codepen here

@picaq
picaq / temperature conversion.js
Created July 23, 2024 21:23
Chemistry calculations
const c2f = c => ( c * 9/5 ) + 32;
const f2c = f => ( f - 32 ) * 5/9;
const c2k = c => c + 273.15;
const k2c = k => k - 273.15;
const f2k = f => f2c(f) + 273.15;
const k2f = k => c2f(k - 273.15);
@picaq
picaq / ascii.js
Last active September 11, 2024 06:25
binary and ascii math
a.charCodeAt(0); // get char code int from str char
String.fromCharCode(...nums); // convert list of nums to string
// convert string to arr of char code nums
const charCodes = (string) => {
let nums = [];
for (i in string) nums.push(string.charCodeAt(i));
return nums;
}
@picaq
picaq / factorial.js
Last active August 26, 2024 18:25
Math JS
const bang = n => {
if ( n < 2 ) return 1;
let fact = 1, i = 2;
while (i <= n) {fact*=i; i++};
return fact;
}