Skip to content

Instantly share code, notes, and snippets.

View hinex's full-sized avatar
🚀
Remote worker

Roman Hinex hinex

🚀
Remote worker
View GitHub Profile
Array.prototype.reduceCustom = function(callback, initialValue) {
const array = this
if (!array.length) {
if (initialValue) {
return initialValue
}
throw new Error('TypeError: Reduce of empty array with no initial value')
}
@hinex
hinex / knex.js
Created December 12, 2018 16:03
Knex.js Insert or Update
const DB = require('../db')
const insertOrUpdate = (tableName, rows) => {
return DB.transaction((trx) => {
const queries = rows.map((tuple) => {
const insert = trx(tableName).insert(tuple).toString()
const update = trx(tableName).update(tuple).toString().replace(/^update(.*?)set\s/gi, '')
@hinex
hinex / h.zsh-theme
Last active May 22, 2019 12:09
ZSH theme like as bash
if [ $UID -eq 0 ]; then CARETCOLOR="red"; else CARETCOLOR="blue"; fi
local return_code="%(?..%{$fg[red]%}%? ↵%{$reset_color%})"
PROMPT='%{$terminfo[bold]$fg[green]%}%n@%m %{${fg_bold[blue]}%}:: %{$reset_color%}%{${fg[cyan]}%}%3~ $(git_prompt_info)%{${fg_bold[$CARETCOLOR]}%}»%{${reset_color}%} '
RPS1="${return_code}"
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[yellow]%}‹"
ZSH_THEME_GIT_PROMPT_SUFFIX="› %{$reset_color%}"