Skip to content

Instantly share code, notes, and snippets.

@MJ111
MJ111 / .vimrc.after
Last active January 21, 2017 14:18
vimconfig
" after the plugins loaded
set foldlevel=10
set foldmethod=syntax
set clipboard=unnamed
set autoindent
filetype plugin indent on
@MJ111
MJ111 / .zshrc
Last active January 21, 2017 15:35
.zshrc
# Path to your oh-my-zsh installation.
export ZSH=/Users/minjeongkim/.oh-my-zsh
source $ZSH/oh-my-zsh.sh
source ~/.zplug/init.zsh
zplug "plugins/git", from:oh-my-zsh
zplug "zsh-users/zsh-autosuggestions"
zplug "b4b4r07/enhancd", use:init.sh
zplug "b4b4r07/httpstat", \
as:command, \
use:'(*).sh', \
@MJ111
MJ111 / arrows.zsh-theme
Last active March 12, 2017 18:58
arrows.zsh-theme
PROMPT='%{$fg_bold[yellow]%}%c%{$reset_color%} $(git_prompt_info)%{$reset_color%}$(git_prompt_status)%{$reset_color%}
$fg_bold[red]›$fg_bold[cyan]›$fg_bold[blue]›%{$reset_color%} '
RPROMPT=''
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[green]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_DIRTY=""
ZSH_THEME_GIT_PROMPT_CLEAN=""
ZSH_THEME_GIT_PROMPT_ADDED="%{$fg_bold[green]%} + "
@MJ111
MJ111 / .gitattributes
Last active March 24, 2017 10:03
Tell git to always select my local version or remote version for conflicted merges
**/*.txt merge=theirs
@MJ111
MJ111 / weird.js
Last active August 2, 2017 04:08
Weird JavaScript Snippet
// 1.
'0' == 0 // true
0 == [] // true
'0' == [] // false
// 2.
['10', '10', '10'].map(parseInt) // [10, NaN, 2]
// 3.
let obj = {bar:0}
@MJ111
MJ111 / countdown.js
Created July 20, 2017 06:25
Calculate milliseconds between midnight and present time according to universal time
const now = new Date();
const utcnow = Date.UTC(
now.getUTCFullYear(),
now.getUTCMonth(),
now.getUTCDate(),
now.getUTCHours(),
now.getUTCMinutes(),
now.getUTCMilliseconds()
);
let utctmr = Date.UTC(
@MJ111
MJ111 / removeBrokenSurrogate.js
Created August 1, 2017 03:55
[Remove divided surrogate pair unicode] #JavaScript #Unicode
/*
* This would be necessary If you have limited length textarea and sliced the input string.
* because individual surrogate codes are useless and raise error in Python and broken character is ugly
* (https://unicode-table.com/en/blocks/high-surrogates/)
*/
function SliceAndCleanInputStr (inputStr) { // inputStr = 'aaaaaa😄'
var sliced = inputStrstr.slice(0, 7) // "aaaaaa�"
return sliced.replace(/[\ud800-\udbff]/g, '') // "aaaaaa"
}
@MJ111
MJ111 / removeBOM.sh
Last active August 9, 2017 06:10 — forked from akost/convert.sh
Bash script for recursive utf-8 byte order mark removal
#!/bin/bash
# Recursive utf-8 byte order mark removal
# https://en.wikipedia.org/wiki/Byte_order_mark#Byte_order_marks_by_encoding
# Place this file in the root of your site, add execute permission and run
# Converts *.php, *.html, *.css, *.js files.
# To add file type by extension, e.g. *.cgi, add '-o -name "*.cgi"' to the find command
find ./ -name "*.php" -o -name "*.html" -o -name "*.css" -o -name "*.js" -o -name "*.sass" -type f |
while read file
@MJ111
MJ111 / webpackDevServerIssue.md
Last active August 9, 2017 12:28
can't resolve 'tls' 'fs', ... when running webpack-dev-server issue

Don't pass file name as argument

$ node_modules/webpack-dev-server/bin/webpack-dev-server.js webpack.config.js

This will raises errors like this.

    ERROR in ./~/tunnel-agent/index.js
    Module not found: Error: Can't resolve 'net' in '/Users/projects/frontend/node_modules/tunnel-agent'
     @ ./~/tunnel-agent/index.js 3:10-24
     @ ./~/request/lib/tunnel.js

@ ./~/request/request.js

@MJ111
MJ111 / handleScroll.js
Created August 17, 2017 08:02
Check if the element is in the middle of window at scroll event
// https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect
function handleScroll() {
const position = document.getElementById('content').getBoundingClientRect()
// check if the element is in the middle of viewport(window)
if (position.top < window.innerHeight/2 && position.bottom > 0 && position.bottom > window.innerHeight/2) {
// do what you want to do
}
}