Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Leo Dutra leodutra

🏠
Working from home
View GitHub Profile
View Liberal Regex Pattern for Web URLs
The regex patterns in this gist are intended only to match web URLs -- http,
https, and naked domains like "example.com". For a pattern that attempts to
match all URLs, regardless of protocol, see: https://gist.github.com/gruber/249502
# Single-line version:
(?i)\b((?:https?:(?:/{1,3}|[a-z0-9%])|[a-z0-9.\-]+[.](?:com|net|org|edu|gov|mil|aero|asia|biz|cat|coop|info|int|jobs|mobi|museum|name|post|pro|tel|travel|xxx|ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cs|cu|cv|cx|cy|cz|dd|de|dj|dk|dm|do|dz|ec|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|s
View Liberal Regex Pattern for All URLs
The regex patterns in this gist are intended to match any URLs,
including "mailto:foo@example.com", "x-whatever://foo", etc. For a
pattern that attempts only to match web URLs (http, https), see:
https://gist.github.com/gruber/8891611
# Single-line version of pattern:
(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))
@leodutra
leodutra / iframe-reference.html
Last active Aug 29, 2015
IFrame Default Attributes Reference + Scroll Definition (IE 8- Fix)
View iframe-reference.html
<!--
seamless="seamless" - Specifies that the <iframe> should look like it is a part of the containing document
allowTransparency="true" - old "seamless" alternative (is not a W3C spec/ option)
frameborder="0" - no border on old browsers (deprecated on HTML5)
scrolling="auto" - Specifies whether or not to display scrollbars in an <iframe> (deprecated on HTML5)
horizontalscrolling - force hide horizontal scrolling on (IE fix)
verticalscrolling - force hide vertical scrolling on (IE fix)
AUTO RESIZE IFRAME
https://github.com/davidjbradshaw/iframe-resizer
View is-document-hidden.js
function getHiddenProp(){
var prefixes = ['webkit','moz','ms','o'];
// if 'hidden' is natively supported just return it
if ('hidden' in document) return 'hidden';
// otherwise loop over all the known prefixes until we find one
for (var i = 0; i < prefixes.length; i++){
if ((prefixes[i] + 'Hidden') in document)
return prefixes[i] + 'Hidden';
@leodutra
leodutra / fullEncodeURI.js
Last active Aug 29, 2015
Fully Encode URI/URL
View fullEncodeURI.js
function fullEncodeURI(str) {
if (str !== undefined && str !== null) {
str = '' + str;
var res = '';
for(var i = 0, l = str.length; i < l ;) {
res += '%';
res += str.charCodeAt(i++).toString('16');
}
return res;
}
@leodutra
leodutra / node-with-proxy-config.bat
Last active Aug 29, 2015
Configurar Node.js em rede privada com Squid Proxy
View node-with-proxy-config.bat
@echo off
set proxy=10.2.97.200:8080
set loglevel=http
set domain=brq.com
:: Intro
echo Configuracao NODE JS & echo.
echo Entre com o login de rede. & echo.
@leodutra
leodutra / load-template.js
Last active Aug 29, 2015
Loads an external HTML template inside a script tag.
View load-template.js
(function($) {
// <script type="text/x-html-template" data-src="url" async></script>
$("script[type='text/x-html-template']").each(function() {
var $el = $(this);
var src = $el.data('src');
if (!src) return;
$.ajax({
url: src,
@leodutra
leodutra / decodeURIComponent.js
Created Oct 6, 2014
Cross compatible decodeURIComponent()
View decodeURIComponent.js
// about it: http://stackoverflow.com/a/12796866/1260526
// Some Mozilla browsers do wrong conversion
decodeURIComponent(str.replace(/\+/gim,' '));
@leodutra
leodutra / test-title-attr-line-break.html
Created Nov 17, 2014
Test - Breaking Line Inside Title Attribute
View test-title-attr-line-break.html
<!DOCTYPE html>
<html>
<head>
<title>TEST - Line Break in title attribute</title>
<style>
.line-through {
text-decoration: line-through;
}
@leodutra
leodutra / extends.js
Last active Aug 29, 2015
JavaScript simple inheritance.
View extends.js
function EXTENDS(super_, extension) {
var obj = function() {};
var proto = obj.prototype = new super_();
proto.super = function() {
super_.apply(this, arguments);
};
for (var prop in extension) {