Skip to content

Instantly share code, notes, and snippets.

View slonoed's full-sized avatar
🥔

Dmitry Manannikov slonoed

🥔
View GitHub Profile
@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 / vk_post_remove_script.js
Last active November 24, 2016 07:12
Remove vk.com messages
setInterval(function(){[].forEach.call(document.querySelectorAll('.post_delete_button'), function(e){e.click();e.remove()}); window.scrollTo(0,document.body.scrollHeight);}, 2000)
@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 / 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 / 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))
@slonoed
slonoed / testEpic.js
Last active September 21, 2017 13:06 — forked from mordaha/testEpic.js
async function retry(foo, count = 1, delay) {
let error;
while (count--) {
try {
return foo()
} catch (e) {
error = e
await timeout(delay)
}
@slonoed
slonoed / colorMaker.js
Created September 26, 2017 11:47
Make nice colors
// Return "infinite" sequence of HSL colors
function* colorMaker({distance = 1, saturation, luminosity, shift = 0}) {
let colorIndex = 0
while (true) {
const hue = (colorIndex * distance + shift) % 359
yield `hsl(${hue}, ${saturation}%, ${luminosity}%)`
colorIndex++
}
}