Skip to content

Instantly share code, notes, and snippets.

John Ku kujohn

View GitHub Profile
mikowl / oneliners.js
Last active Jun 5, 2020
👑 Awesome one-liners you might find useful while coding.
View oneliners.js
// By @coderitual
// Remove any duplicates from an array of primitives.
const unique = [ Set(arr)]
// Sleep in async functions. Use: await sleep(2000).
const sleep = (ms) => (new Promise(resolve => setTimeout(resolve, ms)));
// or
const sleep = util.promisify(setTimeout);
SamJakob / smoothscroll.js
Created Oct 22, 2018
A vue-js supported smooth-scroll module based on a Stack Overflow answer by Manuel Otto.
View smoothscroll.js
const SmoothScroll = (target, speed, smooth) => {
if (target === document)
target = (document.documentElement || document.body.parentNode || document.body) // cross browser support for document scrolling
let moving = false;
let pos = target.scrollTop;
target.addEventListener('mousewheel', scrolled, false)
/* target.addEventListener('DOMMouseScroll', scrolled, false) */
function scrolled(e) {
marnovo /
Created Jan 22, 2018
Enable AptX and AAC codecs on macOS
# (c) 2018 Marcelo Novaes
# License - MIT
# Enable AptX and AAC codecs on bluetooth connections on macOS
sudo defaults write bluetoothaudiod "Enable AptX codec" -bool true
sudo defaults write bluetoothaudiod "Enable AAC code" -bool true
# Reads set values, should return something like:
# {
marcusramberg / -
Last active Feb 4, 2020
kitty.conf including nord color theme
View -
# vim:fileencoding=utf-8:ft=conf
# Fully featured
font_family FuraCode Nerd Font Mono
italic_font auto
bold_font auto
bold_italic_font auto
# Font size (in pts)
font_size 11.0
yang-wei /
Last active Apr 9, 2020
Clojure Thread-first vs Thread-last Macros

Repost from:

In this post, I am going to show you {when|how} to use Clojure marcos, ->> aka thread-last and -> aka thread-first. In some case, -> and ->> may perform the same operation if you do not pay enough attention. So I will also show you what's the difference between them. Note that doc -> and docs ->> din't make sense for me at first, so if same thing happened to you I hope that this post will make it clear.

If I am coding a function in Clojure, I would not think to write in macro firstly(maybe I am still new to it?). Macros like -> and ->> only come in my mind when it comes to refactoring. They are not neccessary in our program but they will make it elegant.

To explain how both of these macros work, let's us solve a quiz together.

[Write a function which calculates factorials.](

paulirish /
Last active Aug 3, 2020
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
staltz /
Last active Aug 4, 2020
The introduction to Reactive Programming you've been missing
mislav /
Last active Jul 31, 2020
tmux-vim integration to transparently switch between tmux panes and vim split windows

I use tmux splits (panes). Inside one of these panes there's a Vim process, and it has its own splits (windows).

In Vim I have key bindings C-h/j/k/l set to switch windows in the given direction. (Vim default mappings for windows switching are the same, but prefixed with C-W.) I'd like to use the same keystrokes for switching tmux panes.

An extra goal that I've solved with a dirty hack is to toggle between last active panes with C-\.

Here's how it should work:

View tmux-cheatsheet.markdown

tmux shortcuts & cheatsheet

start new:


start new with session name:

tmux new -s myname

tmux cheat sheet

(C-x means ctrl+x, M-x means alt+x)

Prefix key

The default prefix is C-b. If you (or your muscle memory) prefer C-a, you need to add this to ~/.tmux.conf:

# remap prefix to Control + a
You can’t perform that action at this time.