Skip to content

Instantly share code, notes, and snippets.

View MiguelCastillo's full-sized avatar

Miguel Castillo MiguelCastillo

View GitHub Profile
@MiguelCastillo
MiguelCastillo / bind.js
Last active May 28, 2023 12:20
Bind polyfill
/**
* Function bind polyfill
* https://github.com/ariya/phantomjs/issues/10522
*/
if (!Function.prototype.bind) {
Function.prototype.bind = function (context /* ...args */) {
var fn = this;
var args = Array.prototype.slice.call(arguments, 1);
@MiguelCastillo
MiguelCastillo / multipart.js
Last active September 18, 2021 18:42
Multipart parse
function multipart(parts, done) {
this.boundary = multipart.generateBoundary();
this.parts = [];
this.filecount;
var readycount = Object.keys(parts).length;
function updateReady() {
readycount--;
if (!readycount) {
@MiguelCastillo
MiguelCastillo / fileurl.js
Last active August 29, 2015 14:03
Regex to parse FILE urls
// http://regex101.com/r/zT4pG0/6
function parseUrl (urlString) {
return /(?:^(file:)(\/\/\/?))?(([A-Za-z-]+:)?[/\\d\w\.\s-]+)/gmi.exec(urlString);
}
@MiguelCastillo
MiguelCastillo / httpurl.js
Last active August 29, 2015 14:03
Regex to parse HTTP urls
// https://regex101.com/r/aH9kH3/21
function parseUrl (urlString) {
return /^((https?:)(\/\/\/?)(?:([\w]+)(?::([\w]*))?@)?([\d\w\.-]+)(?::(\d+))?)?([\/\\\w\.()-]*)?(?:([?][^#]*)?(#.*)?)*/gmi.exec(urlString);
}
@MiguelCastillo
MiguelCastillo / gist:d9ddf33fe7f1e715e981
Last active August 29, 2015 14:03
Windows drive letters to lower case
function fixPath(path) {
return path.replace(/^([A-Za-z]+:)?\//, function (match) {
return match.toLocaleLowerCase();
});
}
@MiguelCastillo
MiguelCastillo / gist:1a9dd73c7d7f74b0e35e
Last active August 29, 2015 14:03
Strip Minified code
function stripMinified(text) {
// var regex = /function[ ]?\w*\([\w,]*\)\{(?:\S[\s]?){150,}\}/gm;
// var regex = /(?:\S[\s]?){150,}[\n]$/gm;
var regex = /(?:.){250,}/gm;
return text.replace(regex, function() {return "";});
}
for (var i in el[0]) {
if (i[0] === 'o' && i[1] === 'n') {
defineEvent(el, i.substr(2));
}
}
function defineEvent(el, evtType) {
var evtDef = {
name: evtType,
@MiguelCastillo
MiguelCastillo / gist:b945ceb0ca99c23b71ec
Last active August 29, 2015 14:02
Regex to test if function is minified and if its big enough that it's hard enough to read that you can just skip...
// Heuristic to guess if code is minified.
// http://regex101.com/r/oE3nP0
if ( /function[ ]?\w*\([\w,]*\)\{(?:\S[ ]?){1000,}\}/g.test(text) ) {
return;
}
@MiguelCastillo
MiguelCastillo / index.html
Last active August 29, 2015 13:59
requirejs index.html
<html>
<head>
<script src="require.js" data-main="main"></script>
</head>
<body>
Welcome to the modern era!
</body>
</html>
@MiguelCastillo
MiguelCastillo / main.js
Last active August 29, 2015 13:59
Sample require 2
define( [
"app", "common", "utils", "contacts", "hiring"
], function(app, common, utils, contacts, hiring) {
});