Skip to content

Instantly share code, notes, and snippets.

View morulus's full-sized avatar
💭
Hey, I have publish new package press-any-key on npmjs

Vladimir Kalmykov morulus

💭
Hey, I have publish new package press-any-key on npmjs
View GitHub Profile
@morulus
morulus / getvectorangle
Created May 15, 2015 08:17
Функция определения угла вектора по 2-м координатам
/* Returns CSS rotateZ compatible angle for verctor */
var getVectorAngle = function(x0,x,y0,y) {
if (y0===y) {
if (x>x0) angle = 0;
else if (x<x0) angle = 180;
else if (x===x0) angle = 0;
} else if (x0===x) {
if (y>y0) angle = 90;
else if (y0>y) angle = -90;
else angle = 0;
@morulus
morulus / readme.md
Last active February 28, 2022 13:58
Module.cra.react-app-rewired.disable-ensure-files

Use this chunk with react-app-rewired

It disables CRA warning about using files outside src directory

@morulus
morulus / svgPathToCubicBezierPoints.js
Last active August 7, 2020 12:36
SVG path to cubic Bezier converter (alpha)
function svgPathToCubicBezierPoints(path, percentRequired) {
var path=path.replace(/([\n])/g, ' ').replace(/[\t]+/g, ''),si=0,cubic=[],
task=0,
M_EREG = /M[\s\d\.\-\,]+[^\sSCLM]+/i,
c_EREG = /c[\s\d\.]+,[\d\.]+\-[\d\.]+,[\d\.]+[^\sSCLM]+/i,
s_EREG = /s[\s\d\.\-\,][^\sSCLM]+/i,
Parts = [],p=null,shift=0,cubic=[],vals,tonullx=0,tonully=0,i=0,locksblocks=[],addsx=0,addsy=0,
minx=9999999,miny=9999999,maxx=0,maxy=0;
// Search for M
@morulus
morulus / killsubshellonpress.sh
Created May 7, 2020 20:13
Kill subshell process on press any key (bash)
pid=$(sleep 1000 & echo "$PPID") &
npx -q press-any-key "Press any key to stop subshell" && kill "$pid";
@morulus
morulus / findPropertyName.js
Last active November 28, 2019 12:17
Find all property names xpath in the nested javascript structure
export default function findProperty(obj, name, xpath = ["[root]"], storedObjects = []) {
let foundedKeys = [];
if (storedObjects.includes(obj)) {
return foundedKeys;
}
storedObjects.push(obj);
if (Array.isArray(obj)) {
for (let i = 0; i < obj.length; i++) {
foundedKeys = foundedKeys.concat(
@morulus
morulus / server.js
Created November 17, 2019 04:57
Very lite http server node.js
var http = require("http"),
url = require("url"),
fs = require('fs'),
path = require('path'),
here = process.cwd(),
extTypes = {
"3gp" : "video/3gpp"
, "a" : "application/octet-stream"
, "ai" : "application/postscript"
, "aif" : "audio/x-aiff"
@morulus
morulus / server.js
Created November 17, 2019 04:57
Very light http server node.js
var http = require("http"),
url = require("url"),
fs = require('fs'),
path = require('path'),
here = process.cwd(),
extTypes = {
"3gp" : "video/3gpp"
, "a" : "application/octet-stream"
, "ai" : "application/postscript"
, "aif" : "audio/x-aiff"
@morulus
morulus / sortAccordingToDeps.js
Last active September 12, 2019 16:00
Sort npm packages according to their dependencies
/* Under MIT License, Vladimir Kalmykov 2019 */
// I'm not sure this is the best solution, but it works and finds cyclical dependencies
// Any suggestions? Leave comments.
/**
* @param packages Array of package.json
* @return Array of names
*/
function sortAccordingToDepends(packages) {
# List all node processes
ps -ef | grep " node" | awk '{print $8, $2}'
# Kill all node processes
ps -ef | grep " node" | awk '{print $2}' | xargs -n 1 bash -c 'kill -9 "$1" 2>/dev/null || echo "Pid $1 is invalid"' --
@morulus
morulus / getCombinations.js
Created July 7, 2019 00:12
Generate possible combinations of letters (Javascript)
module.exports = function getCombinations(letters, count, shift = 0) {
let variants = [];
for (let i = shift; i < letters.length; i++) {
if (count > 1) {
const childCombinations = getCombinations(letters, count - 1, i + 1);
for (let c = 0; c < childCombinations.length; c++) {
variants.push([letters[i]].concat(childCombinations[c]));
}
} else {
variants.push([letters[i]])