Skip to content

Instantly share code, notes, and snippets.

View Paratron's full-sized avatar
🧙
Web Wizardry

Christian Engel Paratron

🧙
Web Wizardry
View GitHub Profile
/**
* Draws a poligon - can draw anything from a triangle to a star.
* Source and demo: http://jsfiddle.net/tohan/8vwjn4cx/
*/
function drawShape(ctx, x, y, points, radius1, radius2, alpha0) {
//points: number of points (or number of sides for polygons)
//radius1: "outer" radius of the star
//radius2: "inner" radius of the star (if equal to radius1, a polygon is drawn)
//angle0: initial angle (clockwise), by default, stars and polygons are 'pointing' up
var i, angle, radius;
@Paratron
Paratron / dynamic_changehandlers.jsx
Last active September 18, 2017 10:26
React dynamic change handlers pattern
import React from 'react';
import PropTypes from 'prop-types';
const propTypes = {
firstName: PropTypes.string,
lastName: PropTypes.string,
birthDay: PropTypes.number,
gender: PropTypes.number,
}
@Paratron
Paratron / shared_value_component.js
Last active September 22, 2017 16:27
React shared values component
/**
* Sometimes you need to create a component of which all instances should rely on the same data pool.
* Lets for example consider a country selector dropdown. No matter how much of them you use inside your
* application - the all should share the same list of countries. But passing that list down to each and
* every component instance via props is very tiresome and bloats your app.
*
* Behold: the shared value component pattern!
*/
import React from 'react';
import PropTypes from 'prop-types';
# With SASS
create-react-app APPNAME --scripts-version custom-react-scripts
# With typescript
create-react-app APPNAME --scripts-version=react-scripts-ts
const myObject = ['a', 'b', 'c'].reduce((obj, key) => (obj[key] = key, obj), {});
@Paratron
Paratron / promisifyModule.js
Last active December 12, 2018 15:11
This node module will consume another module and promisify all of its functions.
const {promisify} = require('util');
const promisifyModuleFunctions = (inModule) => Object
.entries(inModule)
.reduce((outModule, [key, property]) => {
outModule[key] = (typeof property === 'function')
? promisify(property)
: property;
return outModule;
@Paratron
Paratron / async-nodeJS.js
Created December 12, 2018 13:20
Simple async functionality for native style nodeJS functions
// The normal async programming flow in nodeJS can get hairy, quickly:
function readAndParse(filename, callback){
fs.readFile(filename, 'utf8', (err, data) => {
if(err){
callback(err, null);
return;
}
myParser.doParsing(data, (err, result) => {
@Paratron
Paratron / scss.md
Last active January 18, 2019 14:13
Use SCSS to CSS converter for your project

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 / docker-compose.yml
Last active February 5, 2019 12:46
Quick Apache only server for a project
# 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 / color-log.js
Created May 21, 2019 13:13
This tiny wrapper around chalk enables easy coloring of log messages.
/**
* 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:
*