Skip to content

Instantly share code, notes, and snippets.

@rodu
rodu / palette-generator.scss
Last active August 17, 2018 14:43
Given a base color, Generates a color palette with SASS based on the idea of Material Design.
.palette-container {
display: flex;
margin: 20px;
}
.color-name {
font-size: 12pt;
font-weight: bold;
margin: 20px;
// Credits: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
function escapeRegExp(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
}
@rodu
rodu / hexToRgba
Created January 29, 2018 21:50
A function to transform an hex color to its rgba equivalent
// Depends on LoDash chunk function
import { chunk } from 'lodash';
const hexToRgba = (hex = '000000', alpha = 1) => {
const hexChunkSize = hex.length / 3;
const rgb = _.chunk(Array.from(hex.replace('#', '')), hexChunkSize)
.map((chunk) => chunk.join(''))
.map((hex) => parseInt(hex, 16))
.join(',');
@rodu
rodu / delay-decorator
Created January 26, 2018 11:37
A sample decorator to create a delay on class methods or other functions
import { delay } from 'lodash';
const UI_DELAY = 250; // milliseconds
export function uidelay(wait = UI_DELAY) {
return function(target, method, descriptor, ...args) {
const original = descriptor.value;
return Object.assign(descriptor, {
value() {
delay(() => original.call(this), wait, ...args);
@rodu
rodu / rename.sh
Last active April 18, 2017 14:27
Renames all .js to .ts in src folder
#!/bin/bash
for file in $(find src -name "*.js");do git mv $file ${file/.js/.ts}; done
@rodu
rodu / Sublime Text JavaScript Snippets
Last active September 19, 2016 11:30
Sublime Text JavaScript Snippets
These are the snippets I use in Sublime Text.
{
"proto": {
"prefix": "proto",
"body": "${1:class_name}.prototype.${2:method_name} = function ${2:method_name}(${3:first_argument}){\n\t${0:// body...}\n};\n",
"description": "Prototype"
},
"befinj": {
"prefix": "befinj",
"body": "beforeEach(inject((${1:name}) => {\n ${2:}\n}));",
"description": "beforeEach inject"
(+new Date() + Math.floor(Math.random() * 999999)).toString(16)