Skip to content

Instantly share code, notes, and snippets.

View DimaCrafter's full-sized avatar
🌱
Low-Level Factory Adventures

Dmitriy Shiryaev DimaCrafter

🌱
Low-Level Factory Adventures
View GitHub Profile
@DimaCrafter
DimaCrafter / global-styles.js
Last active February 19, 2022 14:05
Svelte/Sapper `:global` prefixer for Less
export default {
install (less, mgr) {
mgr.addPostProcessor({
process (input, meta) {
return input.replace(/:global (.*?)\s*([{,])/g, ':global($1)$2');
}
});
}
}
@DimaCrafter
DimaCrafter / keyboard.js
Created October 4, 2020 08:47
Node.JS FFI (WinAPI) utility for keyboard
const ffi = require('node-ffi');
const FFIStruct = require('ref-struct');
const arch = require('os').arch();
const INPUT_KEYBOARD = 0x1;
const KEYEVENTF_KEYUP = 0x2;
const KEYEVENTF_SCANCODE = 0x8;
const InputStruct = FFIStruct({
type: 'int',
'???': 'int',
@DimaCrafter
DimaCrafter / Enum.js
Created December 8, 2019 08:05
[JS] Vanilla enum generator
module.exports = function Enum (keys) {
let result = {};
keys.forEach((key, i) => {
result[key] = i;
result[i] = key;
});
return result;
}
@DimaCrafter
DimaCrafter / index.js
Created October 28, 2019 07:15
[JS] Universal animation function
// https://gist.github.com/gre/1650294
const easeOutCubic = t => (--t) * t * t + 1;
function animate (obj, prop, from, to, duration, ease) {
if (!obj) return;
const delta = to - from;
const start = Date.now();
const end = start + duration;
const interval = setInterval(() => {
const timeDelta = Date.now() - start;
@DimaCrafter
DimaCrafter / README.md
Last active October 26, 2019 09:34
[JS] Benchmarking functions

Usage:

test([
    () => expr1,
    () => expr2,
    // ...
    () => exprN
], <how many times execute>);
function assign (obj1, obj2) {
if (!obj1) return obj2;
if (!obj2) return obj1;
let result = {};
for (let key in obj1) {
if (key in obj2) {
if (typeof obj2[key] == 'object') result[key] = assign(obj1[key], obj2[key]);
else result[key] = obj2[key];
} else result[key] = obj1[key];