Skip to content

Instantly share code, notes, and snippets.

View fletcherist's full-sized avatar
🔫
pew

phil romanov fletcherist

🔫
pew
View GitHub Profile
alice.welcome((ctx) => {
ctx.confirm({
reply: '18 есть?',
onYes: (ctx) => ctx.reply('добро пожаловать'),
onNo: (ctx) => ctx.reply('в другой раз'),
})
})
function aliceConfirmMiddleware() {
const store = new Map()
// This is blockchain implementaion
// Be careful — it doesn't work as expected actually :)
const CryptoJS = require('crypto-js')
class Block {
constructor(index, timestamp, data, previousHash = '0') {
this.index = index
this.previousHash = previousHash
this.timestamp = timestamp
this.data = data
@fletcherist
fletcherist / CpuMeter.js
Created October 11, 2017 15:13
CPU Metrics for Chrome Extensions
((name, context = window, func) => { context[name] = func() })
('CpuMeter', this, () => {
const isEmptyObject = object => Object.keys(object).length === 0
const getProcessorUsage = (usage, oldUsage) =>
Math.floor((usage.kernel + usage.user - oldUsage.kernel - oldUsage.user) / (usage.total - oldUsage.total) * 100)
class CpuMeter {
constructor() {
if (!chrome || !chrome.system || !chrome.system.cpu) {
throw new Error(`No access to chrome.system.cpu!
@fletcherist
fletcherist / greengit-lambda.js
Created September 23, 2017 19:35
greengit-lambda
const GitHubApi = require('github')
const github = new GitHubApi({
version: '3.0.0',
debug: false,
protocol: 'https',
host: 'api.github.com',
pathPrefix: '',
timeout: 5000,
headers: {
'user-agent': 'GitHub Commits Abuser' // GitHub is happy with a unique user agent
@fletcherist
fletcherist / binaryTree.js
Created September 15, 2017 21:58
BST Implementation is FP Style
const merge = (...args) => Object.assign({}, ...args)
const arrayFromObject = obj => Object.keys(obj).map(key => obj[key])
const getLastTreeIndex = tree => parseInt(Object.keys(tree).pop(), 10)
const getNextTreeIndex = tree => getLastTreeIndex(tree) + 1
const getNodeParentIndex = (tree, {value}) => {
let currentNode = tree[0]
let currentIndex = 0
while (currentNode) {
if (value >= currentNode.value) {
currentNode = tree[currentNode.right]
from sys import exit
game = {}
game_inverted = {}
game_diagonal = []
for i in range(0, 10):
game[i] = []
game_inverted[i] = []
@fletcherist
fletcherist / modal-scrolling.html
Created July 11, 2017 17:18
That's how to do a scrolling modal window with fixed background
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<div class='container'>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo

Working with ssh

ssh-keygen

ssh-copy-id id@server

Deploy all files, except node_modules

`rsync -rav -e ssh --include '*/' --exclude='node_modules'
server:./directory/ \ .

@fletcherist
fletcherist / env.sh
Last active November 15, 2018 15:55
fletcherist's mac env for work & !work
# MIT — fletcherist
# brew tap caskroom/versions
git config --global user.name "fletcherist"
# Saving screenshots to the folder in ~/screenshots
mkdir ~/screenshots
defaults write com.apple.screencapture location ~/screenshots
killall SystemUIServer
#!/bin/bash
dus () {
size=0
# checking whether the dir argument provided
if [ "$1" != "" ]; then
sub_dir="/$1"
else
sub_dir=""
fi
# iterating over all files in all subdirectories