Skip to content

Instantly share code, notes, and snippets.

View catdad's full-sized avatar
🍍
What's happening?

Kiril Vatev catdad

🍍
What's happening?
View GitHub Profile
const path = require('path');
const chokidar = require('chokidar');
const root = path.resolve('.');
const watcher = chokidar.watch('.', {
cwd: root,
ignored: [
/(^|[/\\])\../, // Dotfiles
@catdad
catdad / script.cmd
Created May 30, 2019 02:34
macos virtual modifications
REM https://medium.com/@twister.mr/installing-macos-to-virtualbox-1fcc5cf22801
VBoxManage.exe modifyvm "Mojave" --cpuidset 00000001 000106e5 00100800 0098e3fd bfebfbff
VBoxManage.exe setextradata "Mojave" "VBoxInternal/Devices/efi/0/Config/DmiSystemProduct" "iMac11,3"
VBoxManage.exe setextradata "Mojave" "VBoxInternal/Devices/efi/0/Config/DmiSystemVersion" "1.0"
VBoxManage.exe setextradata "Mojave" "VBoxInternal/Devices/efi/0/Config/DmiBoardProduct" "Iloveapple"
VBoxManage.exe setextradata "Mojave" "VBoxInternal/Devices/smc/0/Config/DeviceKey" "ourhardworkbythesewordsguardedpleasedontsteal(c)AppleComputerInc"
VBoxManage.exe setextradata "Mojave" "VBoxInternal/Devices/smc/0/Config/GetKeyFromRealSMC" 1
VBoxManage.exe setextradata "Mojave" VBoxInternal2/EfiGopMode 4
REM resize screen
function excelDateToJsDate(excelDate) {
// this code was originally written in https://gist.github.com/christopherscott/2782634
return new Date(
(excelDate - (25567 + 1)) * 86400 * 1000
);
}
function jsDateToExcelDate(date) {
// just working backwards from the code above
return (date.getTime() / (86400 * 1000)) + (25567 + 1);
@catdad
catdad / dumb-console.html
Created November 10, 2017 15:43
Sometimes, this is all you need for some quick mobile debugging.
<script src="//catdad.github.io/tiny.cdn/lib/toast/1.0.0/toast.min.js"></script>
<script>
(function () {
function logger(type) {
return function () {
toast[type]([].reduce.call(arguments, function (memo, arg) {
return memo + ' ' + arg.toString();
}, ''));
};
}
@catdad
catdad / README.md
Last active September 27, 2017 15:35
Promise.all, but wait for all promises to finish

Promise.all will execute all promises in parallel, and fail whenever any one of the promises fails. This could even include failing synchronously if one is a Promise.reject(). Instead of doing this, here we want to make sure that all promises finish before we handle the result. We wait for all promises to finish, check their status, and reject or resolve the final promise based on whether any errors were encountered or not.

function renderMustache(str, obj) {
return Object.keys(obj).reduce(function (memo, key) {
var value = obj[key];
var regex = new RegExp('\\$\\{' + key + '\\}', 'g');
return memo.replace(regex, value);
}, str);
};
// usage
@catdad
catdad / get-json-value.sh
Created August 11, 2017 15:47
Use node to parse some json from a bash script
BUILD_NUMBER=`node <<- EOM
var fs = require('fs');
var file = JSON.parse(fs.readFileSync('./file.json', 'utf8'));
process.stdout.write(file.displayName);
EOM`
function buff(size) {
var buf = new Buffer(size);
buf.fill(0);
return buf;
}
var mb = 1024*1024;
var temp = [];
@catdad
catdad / transform.js
Created September 11, 2016 14:54
change chunk sizes in a stream
var through = require('through2');
function changeChunkSizes() {
var buff = '';
var data;
var keepIdx;
return through(function (chunk, enc, cb) {
buff += chunk.toString();
data = keepIdx = undefined;
// Name Function
// ---- --------
// CON Keyboard and display
// PRN System list device, usually a parallel port
// AUX Auxiliary device, usually a serial port
// CLOCK$ System real-time clock
// NUL Bit-bucket device
// A:-Z: Drive letters
// COM1 First serial communications port
// LPT1 First parallel printer port