Skip to content

Instantly share code, notes, and snippets.

Avatar
🥔

Dmitry Manannikov slonoed

🥔
View GitHub Profile
View iterm2 vim tmux navigation
https://github.com/neovim/neovim/issues/2048
Add Ctrl+h as Keyboard Shortcut
Choose Send Escape Sequence as Action
Type [104;5u for Esc+
@slonoed
slonoed / sendgrid-send-email.js
Created Oct 6, 2016
send email via sendgrid
View sendgrid-send-email.js
const KEY = "SENDGRID KEY HERE";
const fs = require('fs');
const html = fs.readFileSync('./index-1.html', 'utf8');
var helper = require('sendgrid').mail;
var from_email = new helper.Email('e@slonoed.net');
var to_email = new helper.Email('guru.veronika@gmail.com');
var subject = 'Hello World from the SendGrid Node.js Library!';
var content = new helper.Content('text/html',html);
var mail = new helper.Mail(from_email, subject, to_email, content);
@slonoed
slonoed / applescript
Created Oct 26, 2016
open file in vim in iterm2
View applescript
on run {input, parameters}
set myPath to POSIX path of input
set cmd to "vim " & quote & myPath & quote
tell application "iTerm"
activate
set newWindow to (create window with default profile)
tell current session of newWindow
write text cmd
end tell
@slonoed
slonoed / LineStream.js
Created Dec 16, 2016
Stream. Transform string chunks to data chunks.
View LineStream.js
class LineStream extends Transform {
constructor(...args) {
super(...args);
this.buffer = '';
}
_transform(chunk, encoding, callback) {
const lines = chunk.toString().split('\n');
lines[0] = this.buffer + lines[0];
View encode.vim
function! s:encodeURIComponent(str)
let s = ''
for i in range(strlen(a:str))
let c = a:str[i]
if c =~# "[A-Za-z0-9-_.!~*'()]"
let s .= c
else
let s .= printf('%%%02X', char2nr(a:str[i]))
endif
endfor
@slonoed
slonoed / create-domain.sh
Created Apr 29, 2017
Nginx letsencrypt template
View create-domain.sh
#!/bin/sh
# Input params
DOMAIN=$1
UPSTREAM_PORT=$2
# Check if config already exist (no overwrite)
if [ -f /etc/nginx/servers/$DOMAIN ]; then
echo "Config /etc/nginx/servers/$DOMAIN already exist. Remove it for continue"
exit 1;
@slonoed
slonoed / log.js
Created May 22, 2017
Simple log system
View log.js
/* @flow */
/* eslint-disable no-console */
/*
* Логгер, создается в разных контекстах
* Имеет внутренний стейт, так как должнен быть создан и начать
* работать до запуска основных модулей
*
* Доступные уровни: ALL, WARN, ERROR, SILENT
*
View reduce-id.js
// item = {id: 'uniq id', field: 1, fielda: 'a'}
listOfItems.reduce((a, i) => ({...a, [i.id]:i}), {})
@slonoed
slonoed / unused.sh
Last active May 31, 2019
Find unused deps
View unused.sh
FILES=$(cat package.json | jq -r '.dependencies * .devDependencies | keys | join("\n")')
ARR=', ' read -r -a array <<< $FILES
echo Not found deps
echo
for dep in "${array[@]}"
do
grep -qr "$dep" src
@slonoed
slonoed / round.js
Created Sep 21, 2017
Round after first N digits
View round.js
/*
101 - 100
12 - 12
12.3 - 12
1.45 - 1.4
*/
N = 2
parseFloat(a.toPrecision(N))