Skip to content

Instantly share code, notes, and snippets.

View ricardocanelas's full-sized avatar
🦈

Ricardo Canelas ricardocanelas

🦈
View GitHub Profile
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 / 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.
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 / 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);
});
// 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 / _wordpress-helpers.md
Last active December 22, 2018 14:57
WordPress Helpers
  • getPrevNext();
  • register_post_type
@ricardocanelas
ricardocanelas / react-mock.md
Last active October 4, 2018 17:30
React - Mock

package.json

"devDependencies": {
    "enzyme": "^3.3.0",
    "enzyme-adapter-react-16": "^1.1.1",
    "jest-fetch-mock": "^1.4.2",
    "sinon": "^4.4.2",
    "source-map-explorer": "^1.5.0"
@ricardocanelas
ricardocanelas / Kernel.php
Created September 3, 2018 14:07
Laravel / Locale (middleware)
<?php // app/Http/kernel.php
namespace App\Http;
use Illuminate\Foundation\Http\Kernel as HttpKernel;
class Kernel extends HttpKernel
{
//...
protected $middlewareGroups = [
@ricardocanelas
ricardocanelas / webpack-3.md
Last active October 30, 2017 20:27
[NOTE] Webpack 3.0

WEBPACK

SOLUTIONS

import .min files

LOADERS