Skip to content

Instantly share code, notes, and snippets.

View slonoed's full-sized avatar
🥔

Dmitry Manannikov slonoed

🥔
View GitHub Profile
package main
import (
"context"
"log"
"os"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
@slonoed
slonoed / rules
Last active May 5, 2019 09:53
ls_adb_2019_05_03
# Blocklist for use with Little Snitch
#
# For more information about this list, see: https://pgl.yoyo.org/adservers/
# ----
# last updated: Fri, 03 May 2019 16:04:09 GMT
# entries: 2964
# format: littlesnitch (littlesnitch -- for use with Little Snitch)
# credits: Peter Lowe - pgl@yoyo.org - https://pgl.yoyo.org/ - https://twitter.com/pgl
# this URL: http://pgl.yoyo.org/adservers/serverlist.php?hostformat=littlesnitch;showintro=0
# Patreon: https://patreon.com/blocklist
@slonoed
slonoed / eslint-local-rules.js
Created March 6, 2019 11:13
eslint rule to prevent await in expressions
/*
Should be used with "eslint-plugin-local-rules" plugin
*/
'use strict'
module.exports = {
'no-await-in-expressions': {
meta: {
type: 'problem',
@slonoed
slonoed / fuzzy_history.sh
Created May 26, 2018 08:07
Fuzzy find and execute command from history
# Fuzzy history
hist() {
local cmd
cmd=$(history | sed -E 's/[0-9]+\ \ //g' | sort -u | grep '^[^\ ]' | fzf --no-multi) &&
echo "\$ $cmd" &&
command $cmd
}
@slonoed
slonoed / ClientRender.js
Created May 16, 2018 16:36
React component to handle client-server render inconsistency
/*
* ClientRender helps to avoid server-client render inconsistency.
*
* I.E. client render depends on data from LocalStorage
*
* Usage:
*
* r(ClientRender, {server: 'Rendered on server'}, 'Rendered on client')
*/
import {Component} from 'react'
@slonoed
slonoed / btc.sh
Created February 23, 2018 18:35
Create public key from private
#!/bin/bash
# Various bash bitcoin tools
#
# requires dc, the unix desktop calculator (which should be included in the
# 'bc' package)
#
# This script requires bash version 4 or above.
#
# This script uses GNU tools. It is therefore not guaranted to work on a POSIX
# system.
@slonoed
slonoed / cache.js
Last active February 15, 2018 09:08
Simple memory cache
/*
* Simple implementation of memory cache
*
* Is use async API in case we replace it with redis.
*
* Keys should be symbols.
*/
const DEFAULT_TTL = 5 * 60 * 1000
const CLEAN_INTERVAL = DEFAULT_TTL * 1.5
@slonoed
slonoed / withPropsChanged.js
Created October 18, 2017 13:13
HOC call callback when props changed
const withPropsChanged = (arePropsChagned, callback) => BaseComponent => {
const factory = React.createFactory(BaseComponent)
return class Watcher extends React.Component {
componentWillReceiveProps(nextProps) {
if (arePropsChagned(this.props, nextProps)) {
callback(nextProps)
}
}
render() {
return factory(this.props)
@slonoed
slonoed / domain.sh
Created October 1, 2017 09:55
Tool to create domain with cert (nginx + letsencrypt)
#!/bin/sh
# Tool to create domain with cert
# ./domain.sh test.example.com 1234
# where 1234 - upstream port
# Input params
DOMAIN=$1
UPSTREAM_PORT=$2
@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++
}
}