Skip to content

Instantly share code, notes, and snippets.

View lucalanca's full-sized avatar

João Figueiredo lucalanca

View GitHub Profile
@lucalanca
lucalanca / SvgDonut.tsx
Created August 1, 2019 14:12
SVG Donut
import * as React from "react";
interface DonutProps {
segments: {
color: string;
percentage: number;
}[];
thickness?: number;
}
@lucalanca
lucalanca / singletons.php
Created December 11, 2018 15:35
Load all cockpit descriptions at once
# /config/api/public/singletons.php
# GET /api/public/singletons
# GET /api/public/singletons?lang=de
<?php
$options = [];
$response = [];
@lucalanca
lucalanca / catch-proxy.js
Created March 7, 2017 14:37
Custom promise catch handling.
// transforms a rejection into a custom-format.
const catchTransformer = (fn, catchMap) => fn().catch(err => Promise.reject(catchMap(err)));
// Example of code that we don't control. The rejection follows its own format (e.g. fetch api).
const doSomethingAsyncThatFails = () =>
new Promise((resolve, reject) => {
setTimeout(() => reject(new Error('failed')), 1000);
});
@lucalanca
lucalanca / transformArrayToDictionary.js
Last active February 13, 2017 16:01
transformArrayToDictionary
export const transformArrayToDictionary = (items, idKey) => items.reduce((acc, item) => {
const { [idKey]: title, ...rest } = item;
return {
...acc,
[title]: rest
}
}, {})
@lucalanca
lucalanca / remove-key-from-obj.js
Last active September 22, 2017 13:35
removes a key from an object without mutating it
const removeKeyFromObject = (obj, key) => {
const { [key]: _, ...rest } = obj;
return rest;
}
'use strict';
const FIELD_TYPE_BLACKLIST = ['file', 'reset', 'submit', 'button'];
const isFieldSerializable = (field) => field.name && FIELD_TYPE_BLACKLIST.indexOf(field.type) === -1
const formFieldsReducer = (state, field) => {
if (!isFieldSerializable(field)) {
return state;
}
# remove falsey elements from array
const compact = (arr) => arr.filter(Boolean)
@lucalanca
lucalanca / SassMeister-input.scss
Created February 23, 2016 08:13
Generated by SassMeister.com.
// ----
// libsass (v3.2.5)
// ----
@function imagePath($imageName) {
@return 'siroop.ch/#{$imageName}';
}
.foo {
background-image: url(imagePath('header.png'));
@lucalanca
lucalanca / SassMeister-input.scss
Created August 20, 2015 13:23
Generated by SassMeister.com.
// ----
// Sass (v3.3.14)
// Compass (v1.0.3)
// ----
@mixin outer {
@content;
}
@mixin inner {
@lucalanca
lucalanca / SassMeister-input.scss
Created August 20, 2015 13:22
Generated by SassMeister.com.
// ----
// Sass (v3.3.14)
// Compass (v1.0.3)
// ----
@mixin outer {
@content;
}
@mixin inner {