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 / 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]])
@morulus
morulus / git-tag-delete-local-and-remote.sh
Created May 25, 2019 18:39 — forked from mobilemind/git-tag-delete-local-and-remote.sh
how to delete a git tag locally and remote
# delete local tag '12345'
git tag -d 12345
# delete remote tag '12345' (eg, GitHub version too)
git push origin :refs/tags/12345
# alternative approach
git push --delete origin tagName
git tag -d tagName
@morulus
morulus / DragPiece2D.cs
Last active May 7, 2019 00:30 — forked from nucleartide/DragPiece2D.cs
A C# script for Unity that allows you to drag 2D rigidbodies around. Works with Unity 4.3's Box2D wrappers (support 2019 2.0)
// Tested with Unity Personal 2019.2.0a14
using UnityEngine;
using System.Collections;
public class DragPiece2D : MonoBehaviour
{
public float dampingRatio = 5.0f;
public float frequency = 2.5f;
public float drag = 10.0f;
public float angularDrag = 5.0f;
@morulus
morulus / .eslintrc
Last active September 21, 2018 00:40
File.eslintrc.es6.react
{
parser: babel-eslint,
env: {
browser: true,
jest : true,
node : true,
es6: true
},
parserOptions: {
ecmaFeatures: {