Skip to content

Instantly share code, notes, and snippets.

Avatar
🧙
Web Wizardry

Christian Engel Paratron

🧙
Web Wizardry
View GitHub Profile
@Paratron
Paratron / svelte.txt
Created Oct 23, 2020
Svelte + Typescript + SASS
View svelte.txt
npx create-snowpack-app [NAME] --template @snowpack/app-template-svelte-typescript
npm i -d sass
// ====================================================================
// svelte.config.js
// ====================================================================
const autoPreprocess = require('svelte-preprocess');
module.exports = {
View led.js
var ws281x = require('rpi-ws281x');
const config = {
leds: 144 * 2,
type: "grb",
brightness: 255
};
function init(){
ws281x.configure(config);
@Paratron
Paratron / objectsEqual.js
Created Apr 4, 2020
Function to test if two objects are equal
View objectsEqual.js
/**
* This function takes two objects and compares if they have the same
* keys and their keys have the same values assigned, so the objects are
* basically the same.
* @param {object} objA
* @param {object} objB
* @return {boolean}
*/
const objectsEqual = (objA, objB) => {
const objAKeys = Object.keys(objA);
@Paratron
Paratron / cross-processA.js
Created Feb 4, 2020
Node cross process communication
View cross-processA.js
// One Process needs to be the host
const ipc = require('node-ipc');
ipc.config.id = 'a-unique-process-name1';
ipc.config.retry = 1500;
ipc.config.silent = true;
ipc.serve(() => ipc.server.on('eventName', message => {
console.log(message);
}));
ipc.server.start();
@Paratron
Paratron / color-log.js
Created May 21, 2019
This tiny wrapper around chalk enables easy coloring of log messages.
View color-log.js
/**
* Chalk powered color log
* =======================
* This module is a wrapper around the chalk package to provide
* simpler log message formatting.
* To switch a color inside your log message, simply use ´X where
* X is one of the color names in the chalkMap below.
*
* Example:
*
@Paratron
Paratron / storageHooks.js
Created Feb 14, 2019
Enables you to use hooks for localStorage and sessionStorage that even redraw all components when their respective values change.
View storageHooks.js
import React from "react";
let lsBus = {};
let ssBus = {};
/**
* Redraw all components that have a hook to localStorage with the given key.
* @param {string} key
* @param {*} newValue
*/
@Paratron
Paratron / docker-shell.sh
Created Feb 5, 2019
Open a shell into a running docker container
View docker-shell.sh
docker exec -ti container_id bash
@Paratron
Paratron / docker-compose.yml
Last active Feb 5, 2019
Quick Apache only server for a project
View docker-compose.yml
# This will start a apache server and maps it to the local port 80
# It will assume your hosted content in the folder ./src
version: '2'
services:
apache2:
image: webdevops/apache:latest
volumes:
- ./src:/app
ports:
- 80:80
@Paratron
Paratron / scss.md
Last active Jan 18, 2019
Use SCSS to CSS converter for your project
View scss.md

Use SCSS to CSS converter for your project

  • npm install --save-dev node-sass
  • Add script to package.json: node-sass --watch INPUTFOLDER -o OUTPUTFOLDER
  • Run script, enjoy
@Paratron
Paratron / promisifyModule.js
Last active Dec 12, 2018
This node module will consume another module and promisify all of its functions.
View promisifyModule.js
const {promisify} = require('util');
const promisifyModuleFunctions = (inModule) => Object
.entries(inModule)
.reduce((outModule, [key, property]) => {
outModule[key] = (typeof property === 'function')
? promisify(property)
: property;
return outModule;