Skip to content

Instantly share code, notes, and snippets.

View caryfuk's full-sized avatar
😱

Pavel Moravec caryfuk

😱
View GitHub Profile
@caryfuk
caryfuk / build-object-conditionally.js
Created September 11, 2018 16:08
conditionally add key to an object
const account = {
email,
password,
...(nickname && {nickname}),
}
// https://medium.freecodecamp.org/how-to-conditionally-build-an-object-in-javascript-with-es6-e2c49022c448
@caryfuk
caryfuk / circular-list.js
Last active September 12, 2018 08:22
circular list
const list = new Array(100)
function set (i, item) {
list[i % list.length] = item
}
// and something on performance: https://www.nearform.com/blog/wormholes-in-javascript/
@caryfuk
caryfuk / normalize-and-replace.js
Last active September 5, 2018 08:37
getting rid of diacritics
/* https://thread.engineering/searching-and-sorting-text-with-diacritical-marks-in-javascript-45afef20e7f2 */
const animal = 'žluťoučký kůň'.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
/* sorting with locale */
arr.sort((a, b) => a.localeCompare(b));
@caryfuk
caryfuk / colorConstrast.js
Created July 26, 2018 20:28
Return either white or black to achieve greatest constrast.
function whiteOrBlack(color) {
const colorArr = color.length === 4 ? color.match(/[\da-fA-F]{1}/g) : color.match(/[\da-fA-F]{2}/g);
return colorArr
.map(s => s.length > 1 ? parseInt(s, 16) : parseInt(s, 16) * 16)
.reduce((a, c) => a + c) > 381 ? '#000' : '#FFF';
}
@caryfuk
caryfuk / android-emulator-homebrew.sh
Last active February 9, 2018 17:21 — forked from spilth/android-emulator-homebrew.sh
Android Emulator with Homebrew
touch ~/.android/repositories.cfg
brew cask install caskroom/versions/java8
brew cask install android-sdk
brew cask install intel-haxm
brew install qt
export ANDROID_SDK_ROOT="/usr/local/share/android-sdk"
sdkmanager "platform-tools" "platforms;android-27" "extras;intel;Hardware_Accelerated_Execution_Manager" "build-tools;27.0.0" "system-images;android-27;google_apis;x86" "emulator"
avdmanager create avd -n test -k "system-images;android-27;google_apis;x86" --tag google_apis
/usr/local/share/android-sdk/tools/emulator -avd test
document.documentElement.webkitRequestFullScreen();
@caryfuk
caryfuk / gitlog.txt
Created July 3, 2016 08:19
pretty git log
git log --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
-p (with commit changes)
--graph (displayed as graph)
via Filipe Kiss
@caryfuk
caryfuk / atan2-alternative.js
Created June 20, 2016 15:04
compute angle on unit circle (alternative to built in Math.atan2)
const angle = (x, y) => {
let result = Math.atan(y / x);
if (x < 0) {
result += Math.PI;
} else if (y < 0) {
result += 2 * Math.PI;
}
return result;
};
@caryfuk
caryfuk / vars-in-calc.less
Last active April 4, 2018 08:23
Using variables in within calc in less
~"calc(100% - @{variable})";
// or
calc(100% ~"-" @variable);
### Terminal Syntax Highlighting
# Setup: "brew install highlight"
# Pipe Highlight to less
export LESSOPEN="| $(which highlight) %s --out-format xterm256 --line-numbers --quiet --force --style solarized-light"
export LESS=" -R"
alias less='less -m -N -g -i -J --line-numbers --underline-special'
alias more='less'