Skip to content

Instantly share code, notes, and snippets.

@sshmyg
sshmyg / uuid.md
Created September 5, 2020 15:32
Простой способ генерации символьных ID и UUID

Source: https://tech.geekjob.ru/prostoy-sposob-generacii-id-uuid/

На JavaScript Если вдруг нужно быстро сгенерить символьные ID, которые представляют собой сочетание цифр и символов, при этом вам не нужна высокая надежность и коллизии вам не страшны, то можно сделать это очень быстро следующим образом:

const id = f${(~~(Math.random()*1e8)).toString(16)}; // Result: f5d47a64 Можно так же сделать генерацию хешей от времени:

const id = f${(+new Date).toString(16)};

String.fromCodePoint(...["1f469", "200d", "2764", "fe0f", "200d", "1f48b", "200d", "1f469"].map(u => "0x" + u))
@sshmyg
sshmyg / README
Created June 29, 2019 11:18 — forked from joelambert/README
Drop in replacements for setTimeout()/setInterval() that makes use of requestAnimationFrame() where possible for better performance
Drop in replace functions for setTimeout() & setInterval() that
make use of requestAnimationFrame() for performance where available
http://www.joelambert.co.uk
Copyright 2011, Joe Lambert.
Free to use under the MIT license.
http://www.opensource.org/licenses/mit-license.php
@sshmyg
sshmyg / deps.md
Last active May 27, 2019 18:30
Puppeteer ubuntu deps

Troubleshooting

Issue

sudo apt-get install gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget
@sshmyg
sshmyg / current-dir-in-iterm-tab-title.sh
Created September 18, 2018 06:22 — forked from phette23/current-dir-in-iterm-tab-title.sh
Set the iTerm tab title to the current directory, not full path.
# put this in your .bash_profile
if [ $ITERM_SESSION_ID ]; then
export PROMPT_COMMAND='echo -ne "\033];${PWD##*/}\007"; ':"$PROMPT_COMMAND";
fi
# Piece-by-Piece Explanation:
# the if condition makes sure we only screw with $PROMPT_COMMAND if we're in an iTerm environment
# iTerm happens to give each session a unique $ITERM_SESSION_ID we can use, $ITERM_PROFILE is an option too
# the $PROMPT_COMMAND environment variable is executed every time a command is run
# see: ss64.com/bash/syntax-prompt.html
@sshmyg
sshmyg / README.md
Created May 5, 2018 19:44 — forked from nicerobot/README.md
Mac OS X uninstall script for packaged install of node.js

To run this, you can try:

curl -ksO https://gist.githubusercontent.com/nicerobot/2697848/raw/uninstall-node.sh
chmod +x ./uninstall-node.sh
./uninstall-node.sh
rm uninstall-node.sh
@sshmyg
sshmyg / debouncing-throttling-explained-examples.md
Created January 31, 2017 20:27
Difference between Debounce and Throttle

Difference between Debounce and Throttle

Debounce

Debounce a function when you want it to execute only once after a defined interval of time. If the event occurs multiple times within the interval, the interval is reset each time.
Example A user is typing into an input field and you want to execute a function, such as a call to the server, only when the user stops typing for a certain interval, such as 500ms.

Throttle

@sshmyg
sshmyg / keysimulator.js
Last active March 22, 2016 08:13
Keyboard simulator
var E = {
createEvent: function(e, keyValue, keyCode) {
e = e || 'keypress';
keyValue = keyValue ? keyValue.charCodeAt(0) : keyCode;
if (!(e || keyValue)) {
throw Error('e and keyValue required');
}
@sshmyg
sshmyg / extend.js
Created December 16, 2015 14:49
SImple extend
var extend = function(target, source) {
target = target || {};
for (var prop in source) {
if (!source.hasOwnProperty(prop)) continue;
if (typeof source[prop] === 'object') {
target[prop] = extend(target[prop], source[prop]);
} else {
target[prop] = source[prop];
@sshmyg
sshmyg / format-number.regexp.js
Created September 18, 2015 06:04
Format number like 1 000 000, with space
var str = '234456234';
str.replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g, '$1 ');