Skip to content

Instantly share code, notes, and snippets.

View AnsonH's full-sized avatar
👾
Doing great

Anson Heung AnsonH

👾
Doing great
View GitHub Profile
@AnsonH
AnsonH / js-tip2.js
Last active September 8, 2021 11:17
Javascript Tip #2 - 3 ways to iterate through object keys
/* Tweet: https://twitter.com/AnsonH_/status/1435562848399228936?s=20 */
const student = { name: "Tom", age: 20, gender: "male" };
// Method 1: for-in loop
for (const key in student) {
console.log(key + ": " + student[key]);
}
// Method 2: Object.keys()
@AnsonH
AnsonH / js-tip1.js
Last active September 7, 2021 10:38
Javascript Tip #1 - Directly invoke arrow functions
/* Tweet: https://twitter.com/AnsonH_/status/1435189821740175363?s=20 */
/* Example 1 */
(() => {
console.log("Hello!");
})();
// Equivalent to...
(function() {
console.log("Hello!");
@AnsonH
AnsonH / init.vim
Last active September 6, 2021 13:01
Vim Tip #3 - Move lines up and down with <A-k> and <A-j>
nnoremap <silent> <A-j> :m .+1<CR>==
nnoremap <silent> <A-k> :m .-2<CR>==
inoremap <silent> <A-j> <Esc>:m .+1<CR>==gi
inoremap <silent> <A-k> <Esc>:m .-2<CR>==gi
vnoremap <silent> <A-j> :m '>+1<CR>gv=gv
vnoremap <silent> <A-k> :m '<-2<CR>gv=gv