Skip to content

Instantly share code, notes, and snippets.

View cuong-nguyen's full-sized avatar
👨‍💻
Focusing

Cuong cuong-nguyen

👨‍💻
Focusing
View GitHub Profile
@cuong-nguyen
cuong-nguyen / nesting.css
Created February 26, 2021 04:12 — forked from csswizardry/nesting.css
DOM Depth Visualiser
/**
* Tier 1 – Dotted
*/
* { outline: 2px dotted purple; }
* * { outline: 2px dotted blue; }
* * * { outline: 2px dotted green; }
* * * * { outline: 2px dotted yellow; }
* * * * * { outline: 2px dotted orange; }
* * * * * * { outline: 2px dotted red; }
@cuong-nguyen
cuong-nguyen / vim-surround
Created February 17, 2021 10:16
Practice vim surrounding commands
// https://github.com/tpope/vim-surround/blob/master/doc/surround.txt
// delete double quotes
"Hello world!"
// change [] brackets to ()
[123+456]/2
// change quotes to `p` tag
"Look ma, I'm HTML!"
/**
* @param {HTMLElement} element
* @param {Keyframe[] | PropertyIndexedKeyframes} to
* @param {KeyframeAnimationOptions} options
*/
export function animateTo(element, keyframes, options) {
const anim = element.animate(
keyframes,
{ ...options, fill: 'both' },
);
1. given 2 sorted number arrays, merge them in sorted order
input: [2,4,8] and [1,3,5,7]
output: [1, 2, 3, 4, 5, 7, 8]
2. given this data structure
// input
const bookings = [
{ id: 1, userId: 456, status: 'confirmed' },
@cuong-nguyen
cuong-nguyen / pure_html_css_modal.css
Created May 1, 2019 05:40 — forked from calebporzio/pure_html_css_modal.css
The CSS for the pure HTML/CSS modal I tweeted about.
details summary {
cursor: pointer;
outline: none !important;
display: inline-block;
padding: 8px 12px;
padding-top: 10px;
border-radius: 4px;
overflow: hidden;
background: #F09825;
color: white;
@cuong-nguyen
cuong-nguyen / uniq.js
Last active July 5, 2017 12:27
Array w/ unique numbers
let uniq = (arr) => {
let map = {};
for (let i=0; i<arr.length; i++) {
if (typeof map[arr[i]] === 'undefined') {
map[arr[i]] = arr[i];
} else {
arr.splice(i, 1);
}
}
@cuong-nguyen
cuong-nguyen / missing.js
Last active July 5, 2017 11:36
Missing number in the unsorted sequence 1...n
let missing = (arr) => {
let i = 1, max = arr.length, sum1 = 0, sum2 = 0;
while (i <= max) {
sum1 += i;
sum2 += arr[i-1] || 0;
if (arr[i-1] > max) max = arr[i-1];
i++;
}
return (sum1 - sum2) || undefined;
}