Skip to content

Instantly share code, notes, and snippets.

View Kequc's full-sized avatar

Kequc

View GitHub Profile
@donmccurdy
donmccurdy / wildcard-to-regexp.js
Last active February 21, 2024 06:49
Wildcard and glob matching in JavaScript.
/**
* Creates a RegExp from the given string, converting asterisks to .* expressions,
* and escaping all other characters.
*/
function wildcardToRegExp (s) {
return new RegExp('^' + s.split(/\*+/).map(regExpEscape).join('.*') + '$');
}
/**
* RegExp-escapes all characters in the given string.
@ygotthilf
ygotthilf / jwtRS256.sh
Last active May 8, 2024 10:31
How to generate JWT RS256 key
ssh-keygen -t rsa -b 4096 -m PEM -f jwtRS256.key
# Don't add passphrase
openssl rsa -in jwtRS256.key -pubout -outform PEM -out jwtRS256.key.pub
cat jwtRS256.key
cat jwtRS256.key.pub
@paulirish
paulirish / what-forces-layout.md
Last active May 6, 2024 07:54
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
@danielgtaylor
danielgtaylor / gist:0b60c2ed1f069f118562
Last active April 2, 2024 20:18
Moving to ES6 from CoffeeScript

Moving to ES6 from CoffeeScript

I fell in love with CoffeeScript a couple of years ago. Javascript has always seemed something of an interesting curiosity to me and I was happy to see the meteoric rise of Node.js, but coming from a background of Python I really preferred a cleaner syntax.

In any fast moving community it is inevitable that things will change, and so today we see a big shift toward ES6, the new version of Javascript. It incorporates a handful of the nicer features from CoffeeScript and is usable today through tools like Babel. Here are some of my thoughts and issues on moving away from CoffeeScript in favor of ES6.

While reading I suggest keeping open a tab to Babel's learning ES6 page. The examples there are great.

Punctuation

Holy punctuation, Batman! Say goodbye to your whitespace and hello to parenthesis, curly braces, and semicolons again. Even with the advanced ES6 syntax you'll find yourself writing a lot more punctuatio

@miguelmota
miguelmota / randomDate.js
Last active December 21, 2022 16:27
Random date in JavaScript
function randomDate(start, end) {
return new Date(start.getTime() + Math.random() * (end.getTime() - start.getTime()))
}
console.log(randomDate(new Date(2012, 0, 1), new Date()))
@roman01la
roman01la / web-worker-cors.js
Created September 9, 2014 17:26
Cross-origin solution for loading WebWorker
var xhr = new XMLHttpRequest();
xhr.open('GET', url);
xhr.onload = function() {
if (xhr.status === 200) {
var workerSrcBlob, workerBlobURL;
workerSrcBlob = new Blob([xhr.responseText], { type: 'text/javascript' });
workerBlobURL = window.URL.createObjectURL(workerSrcBlob);
var worker = new Worker(workerBlobURL);
@patriciogonzalezvivo
patriciogonzalezvivo / GLSL-Noise.md
Last active May 8, 2024 18:44
GLSL Noise Algorithms

Please consider using http://lygia.xyz instead of copy/pasting this functions. It expand suport for voronoi, voronoise, fbm, noise, worley, noise, derivatives and much more, through simple file dependencies. Take a look to https://github.com/patriciogonzalezvivo/lygia/tree/main/generative

Generic 1,2,3 Noise

float rand(float n){return fract(sin(n) * 43758.5453123);}

float noise(float p){
	float fl = floor(p);
  float fc = fract(p);
Router.query = (function(router) {
var current = function() {
return router.current();
};
var currentParams = function() {
return current().params;
};
var currentQueryParams = function() {
@Kequc
Kequc / gist:8740833
Last active January 15, 2018 09:15
Rename directory of files in random order to simple numerical form
require 'fileutils'
# Set folder path
folder_path = "/User/absolute/path/to/dir"
# Start at number
start = 0
# Group into directories of size
size = 125
# "%07d" for 7 digits ie 0000001.jpg
padding = "%07d"
# Then run this monster
@Fusselwurm
Fusselwurm / querySelector.js
Created January 30, 2013 14:39
document.querySelector, document.querySelectorAll for IE7
/*global document */
/**
* define document.querySelector & document.querySelectorAll for IE7
*
* A not very fast but small hack. The approach is taken from
* http://weblogs.asp.net/bleroy/archive/2009/08/31/queryselectorall-on-old-ie-versions-something-that-doesn-t-work.aspx
*
*/
(function () {
var