Skip to content

Instantly share code, notes, and snippets.

View slonoed's full-sized avatar
🥔

Dmitry Manannikov slonoed

🥔
View GitHub Profile
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 October 6, 2016 08:39
send email via sendgrid
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 October 26, 2016 18:49
open file in vim in iterm2
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 December 16, 2016 13:28
Stream. Transform string chunks to data chunks.
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];
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 April 29, 2017 13:49
Nginx letsencrypt template
#!/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 11:10
Simple log system
/* @flow */
/* eslint-disable no-console */
/*
* Логгер, создается в разных контекстах
* Имеет внутренний стейт, так как должнен быть создан и начать
* работать до запуска основных модулей
*
* Доступные уровни: ALL, WARN, ERROR, SILENT
*
@slonoed
slonoed / reduce-id.js
Created August 1, 2017 07:51
Reduce entities
// 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 13:28
Find unused deps
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 September 21, 2017 07:01
Round after first N digits
/*
101 - 100
12 - 12
12.3 - 12
1.45 - 1.4
*/
N = 2
parseFloat(a.toPrecision(N))