Skip to content

Instantly share code, notes, and snippets.

View execmd's full-sized avatar
🏠
Working from home

Denis execmd

🏠
Working from home
  • ROOTAPI LLC
  • Riga, Latvia
View GitHub Profile
@execmd
execmd / .cmd
Created March 26, 2019 10:04
WSL git and other tools can be runned in WSL under CMD
REM For git binary we can use windows bash.exe because git is installed in wsl in binary path
REM For other tools which are included as functions or in interactive shell like nvm (nvm, node, npm) we need to run debian (or other distributive)
REM Binary version
@echo off
If %PROCESSOR_ARCHITECTURE% == x86 (
"C:\Windows\sysnative\bash.exe" -c "git %*"
) Else (
"bash.exe" -c "git %*"
)
@execmd
execmd / parse_dotenv.bash
Created December 16, 2017 13:25 — forked from judy2k/parse_dotenv.bash
Parse a .env (dotenv) file directly using BASH
# Pass the env-vars to MYCOMMAND
eval $(egrep -v '^#' .env | xargs) MYCOMMAND
# … or ...
# Export the vars in .env into your shell:
export $(egrep -v '^#' .env | xargs)
@execmd
execmd / .js
Created December 15, 2017 05:29
simple proxy server
#!/usr/bin/env node
'use strict';
const { createServer, connect } = require('net');
const log = (group) => (...args) => console.log.apply(console, ['[' + group + ']', ...args]);
const err = (group) => (...args) => console.error.apply(console, ['[' + group + ']', ...args]);
const l = log('server');
@execmd
execmd / parseSize.js
Created August 5, 2015 13:47
Parsing size in bytes to readable format
function parseSize(size, power) {
power = power || 1024;
var pref = ['b', 'K', 'M', 'G', 'T'], sizes = [], i = 0;
while (size > 1) {
sizes.unshift((size % power) + pref[i]);
size = Math.floor(size / power);
i++;
}
return sizes.join(' ');
@execmd
execmd / gist:906c1bb34a7e452e3cda
Created June 17, 2015 09:20
Generate string from char code ranges
var string = '';
var chars = [[48, 57], [65, 90], [97, 122]];
chars.forEach(function (charRange) {
for (var i = charRange[0]; i<=charRange[1]; i++) {
string += String.fromCharCode(i);
}
});
@execmd
execmd / gist:050dcd1238229883f88f
Created October 3, 2014 13:16
Random string generator
function generateRandom(n) {
return Math.floor(Math.random() * Math.pow(16777215, n || 2)).toString(36);
}
@execmd
execmd / get_language.js
Last active August 29, 2015 14:02
Selecting language from available languages based on Accept-Language header. If provided selectedLanguage, then check if this exists in availableLanguages. As fallback uses defaultLanguage or zero element of availableLanguages.
// File: get_language.js
/**
* Parses header 'Accept-Language' and returns array with extracted languages
* sorted by quality factor.
*
* @param header
* @returns {Array}
*/