Skip to content

Instantly share code, notes, and snippets.

Avatar
🔫
pew

phil romanov fletcherist

🔫
pew
View GitHub Profile
View draftAliceConfirmMiddleware.ts
alice.welcome((ctx) => {
ctx.confirm({
reply: '18 есть?',
onYes: (ctx) => ctx.reply('добро пожаловать'),
onNo: (ctx) => ctx.reply('в другой раз'),
})
})
function aliceConfirmMiddleware() {
const store = new Map()
View blockchain.js
// 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 Oct 11, 2017
CPU Metrics for Chrome Extensions
View CpuMeter.js
((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!
View greengit-lambda.js
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 Sep 15, 2017
BST Implementation is FP Style
View binaryTree.js
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]
View 825B.py
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 Jul 11, 2017
That's how to do a scrolling modal window with fixed background
View modal-scrolling.html
<!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
View helpers.md

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 Nov 15, 2018
fletcherist's mac env for work & !work
View env.sh
# 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
View dus.sh
#!/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
You can’t perform that action at this time.