Skip to content

Instantly share code, notes, and snippets.

@nemtsov
nemtsov / pulse.css
Last active June 20, 2020 19:42
Anchor pulsing with CSS box-shadow
.pulse {
padding: 2px 5px;
display: inline-flex;
justify-content: center;
align-items: center;
border-radius: 8px;
cursor: pointer;
animation: pulse 3s infinite;
color: hsl(340, 86%, 43%);
}
let variablesStyles: { [key: string]: HTMLStyleElement } = {};
function updateCssStyle(id: string, styleString: string): void {
const newStyle = styleString;
if (!variablesStyles[id]) {
variablesStyles[id] = document.createElement('style');
document.head.appendChild(variablesStyles[id]);
}
const bcrypt = require('bcryptjs');
const crypto = require('crypto');
const http = require('http');
const querystring = require('querystring');
const { promisify } = require('util');
const randomBytes = promisify(crypto.randomBytes);
const ONE_YEAR_IN_SEC = 365 * 24 * 60 * 60;
const users = [];
@nemtsov
nemtsov / 1-basic-server_1-start.js
Last active January 31, 2019 04:46
Memory Leak Talk
const http = require('http');
const colors = ['red', 'green', 'blue'];
function getUserType(user) {
// - long or cpu-intensive task -
switch (user.color) {
case 'red':
return 'red user';
@nemtsov
nemtsov / fish_prompt.fish
Last active January 23, 2019 04:02
faster_git_fish_prompt.fish
function fish_prompt
set -l __last_command_exit_status $status
if not set -q -g __fish_yuriy_functions_defined
set -g __fish_yuriy_functions_defined
function _git_branch_name
set -l branch (git symbolic-ref --quiet HEAD ^/dev/null)
if set -q branch[1]
@nemtsov
nemtsov / index.html
Created September 18, 2018 06:54
Understanding Gun.js
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Understand Gun</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
#app {
@nemtsov
nemtsov / require_only_when_changed.js
Last active May 25, 2018 15:55
Require only when changed
function getJSON(filename) {
if (!IS_PROD) {
getJSON.lastMtimes = getJSON.lastMtimes || {};
const filePath = require.resolve(filename);
const { mtimeMs } = fs.statSync(filePath);
const lastMtime = getJSON.lastMtimes[filePath];
if (!lastMtime || lastMtime !== mtimeMs) {
getJSON.lastMtimes[filePath] = mtimeMs;
delete require.cache[filePath];
@nemtsov
nemtsov / create_new_user.sh
Last active April 20, 2018 04:32
Kubernetes Administration Helpers
#!/usr/bin/env bash
USERNAME="yuriy"
GROUP="wr"
CA_DIR="/etc/kubernetes/pki"
USER_CERTS_DIR="/home/$USERNAME/.certs"
mkdir -p $USER_CERTS_DIR
pushd $USER_CERTS_DIR
@nemtsov
nemtsov / behance_grey_out_seen.js
Last active April 9, 2018 15:25
Behance: Grey Out Seen Projects
// ==UserScript==
// @name Behance Grey Out Seen
// @version 1
// @grant none
// @match https://www.behance.net/*
// ==/UserScript==
const ACTIVITY_RE = /\/(activity)?$/;
const PROJECT_RE = /\/gallery\/([0-9]+)\/.+/;
let viewedProjectIds = JSON.parse(localStorage.getItem('viewedProjectIds')) || [];
@nemtsov
nemtsov / server.js
Created February 27, 2018 06:38
Start two node servers in one
/* eslint no-console: 0 */
const { fork, spawn } = require('child_process');
const web = fork(`${__dirname}/web.js`);
web.on('close', code => process.exit(code));
if (process.env.NODE_ENV === 'development') {
const api = spawn('nodemon', ['--watch', 'server', '--ext', 'js,gql,json', 'server/api.js']);
api.stdout.on('data', data => process.stdout.write(data));
api.stderr.on('data', data => process.stderr.write(data));