Skip to content

Instantly share code, notes, and snippets.

View ricardocanelas's full-sized avatar
🦈

Ricardo Canelas ricardocanelas

🦈
View GitHub Profile
// Place your settings in this file to overwrite the default settings
{
"workbench.colorTheme": "Visual Studio Light",
"editor.minimap.enabled": false,
"explorer.confirmDragAndDrop": false,
"files.autoSave": "off",
"window.zoomLevel": 0,
"files.encoding": "utf8",
"editor.tabSize": 2,
"files.trimTrailingWhitespace": true,
@ricardocanelas
ricardocanelas / promiseMap.js
Last active December 22, 2019 11:30
JavaScript - Promise Map
// https://codesandbox.io/s/promisemap-o7f7n
const getData = id =>
new Promise((res, rej) => {
setTimeout(() => {
const data = { id, uid: (Math.random() * 100).toFixed(2) };
console.log("data", data);
res(data);
}, 100);
});
function draggable({ dragElem, zoneElemBefore }) {
const $dragElem = document.querySelector(dragElem)
const $zoneElem = $dragElem.closest(zoneElemBefore)
const margin = 10
$dragElem.onmousedown = function (event) {
if (event.target.tagName === "TEXTAREA") return;
event.preventDefault();
let shiftY = event.clientY - $dragElem.getBoundingClientRect().top;
@ricardocanelas
ricardocanelas / regex.md
Last active April 23, 2021 13:38
Regex - Basic information

Reference

Meta Sequences:

  • . (a dot) It denotes “any character except a newline”

Quantifiers:

  • + to the match one character after another.
  • ? is a quantifier by itself (zero or one), but if added after another quantifier (or even itself) it gets another meaning – it switches the matching mode from greedy --> to --> lazy.
const isTouchDevice = () => {
const prefixes = ['', '-webkit-', '-moz-', '-o-', '-ms-', ''];
const mq = query => window.matchMedia(query).matches;
if (
'ontouchstart' in window ||
(window.DocumentTouch && document instanceof 'DocumentTouch')
) {
return true;
}
@ricardocanelas
ricardocanelas / server-with-static.js
Last active May 14, 2020 18:58
Simple server using http
const http = require('http');
const url = require('url');
const path = require('path')
const fs = require('fs');
const mimeTypes = {
"html": "text/html",
"mp3":"audio/mpeg",
"mp4":"video/mp4",
"jpeg": "image/jpeg",
@ricardocanelas
ricardocanelas / class-fn.md
Created June 8, 2020 22:19
javascript-class-method

Class

class Star {
  constructor(name) {
    this.name = name;
  }
  getMessage(message) {
 return this.name + message;
@ricardocanelas
ricardocanelas / template-engine-simple.js
Last active October 28, 2020 17:54
Template Engine
export const template = function (tpl, data) {
if (typeof tpl !== 'string') return ''
if (typeof data !== 'object') return tpl
const interpolate = new RegExp('{{(.+?)}}', 'gi')
let result = tpl
result = result.replace(interpolate, (...args) => {
const values = args[1] ? args[1].trim().split('||') : ''
@ricardocanelas
ricardocanelas / utilities.scss
Last active June 24, 2020 22:28
Utility-Class (like Bootstrap 5) buut.. in a simple way
$grid-breakpoints: (
xs: 0,
sm: 576px,
md: 768px,
lg: 992px,
xl: 1200px,
xxl: 1400px
);
$utilities: (
@ricardocanelas
ricardocanelas / custom-checkbox-twbs.scss
Created July 1, 2020 12:03
get-boostrap-custom-checkbox
$custom-checkbox-color: $color-brand-wcag-3-1;
$custom-checkbox-size: 24px;
.custom-checkbox {
.custom-control-input {
opacity: 0;
width: $custom-checkbox-size;
height: $custom-checkbox-size;
}