Skip to content

Instantly share code, notes, and snippets.

View Flyrell's full-sized avatar
🧠
Busy brain...

Dawid Zbiński Flyrell

🧠
Busy brain...
View GitHub Profile
@Flyrell
Flyrell / rotateElement.js
Last active February 18, 2024 17:02
Simple function for creating element that rotate based on the mouse position. In other words, the element is looking-at/following the mouse.
/**
* DEMO: https://jsfiddle.net/gd6b71Ln/38/
*
* CAUTION: You will need to edit `el.style.transform = 'rotate('+ deg +'deg)'`,
* in case the element has already existing transform styles (just append them)
*
* COMPATIBILITY: https://caniuse.com/#feat=getboundingclientrect
* https://caniuse.com/#feat=transforms2d
*
* Makes the element rotate based on the mouse position
@Flyrell
Flyrell / ifCondition.ts
Last active November 29, 2019 18:35
RxJS: Simple If condition for Observables in TypeScript
// Simple if condition that stops Observable from continuing passed condition function returns false.
// There's also an option to run else callback if needed.
/*
* USAGE
*
* of(events).pipe(
* ifCondition(event => event.name.endsWith('anything'), () => console.log('Not the anything event'))
* )
*/
@Flyrell
Flyrell / createAvatar.ts
Created February 10, 2020 18:00
Code used to upload the file and create an avatar of a fixed size from the center of the uploaded image. Keeps the original ratio of an image and makes sure dimensions of the images are at least the same as our fixed size.
const AVATAR_SIZE = 140;
function onFileChange(input: HTMLInputElement): Promise<string> {
const fileReader = new FileReader();
fileReader.readAsDataURL(input.files.item(0));
return new Promise((resolve) => {
fileReader.onload = (event) => {
const image = new Image();
image.src = event.target.result as string;
image.onload = () => {
@Flyrell
Flyrell / generator_getAllPossibleCombinations.js
Last active June 20, 2020 14:50
Simple function for generating all possible configuration without repeating the items with possibility to specify the output length
function* getAllPossibleCombinations(arr, outputLength = arr.length) {
if (outputLength > arr.length) {
throw 'Not enough items in array';
}
for (let i = 0; i < arr.length; i++) {
if (outputLength === 1) yield arr[i];
for (let j = 0; j < arr.length; j++) {
if (i === j) continue;
#!/usr/local/bin/node
const fs = require('fs');
const path = require('path');
const arguments = process.argv.slice(2);
const folder = arguments[0];
const filePrefix = arguments[1];
const map = {