Skip to content

Instantly share code, notes, and snippets.

View qgustavor's full-sized avatar
🎯
Focusing

Gustavo Rodrigues qgustavor

🎯
Focusing
View GitHub Profile
@qgustavor
qgustavor / infinite-scroll.js
Created February 25, 2014 15:51
Scroll infinito
window.onscroll = function onScroll() {
var htmlEl = document.documentElement,
alturaJanela = htmlEl.clientHeight,
alturaTotal = Math.max(document.body.scrollHeight, htmlEl.scrollHeight, document.body.offsetHeight, htmlEl.offsetHeight, htmlEl.clientHeight);
// Aplique a lógica que quiser, usei: se o scroll
if(alturaTotal - 2 * alturaJanela < window.scrollY) {
carregarDados();
}
window.onscroll = null;
@qgustavor
qgustavor / gist:11261348
Created April 24, 2014 16:46
Browser recursion test
/** Get the maximum call stack and the error it generates */
(function () {
var results = {};
(function f (a) {
try {
f(a+1);
} catch (e) {
results[a] = e;
}
}(0));
@qgustavor
qgustavor / example.js
Last active August 29, 2015 14:03
Advanced compilation version of hasChainOfKeys
// Example usage:
var example1 = {foo: {bar: 1}},
example2 = {foo: {bar: 1, qux: 1}},
example3 = {foo: {BAZ: 1}},
template1 = {foo: {bar: 1}}
template2 = {foo: {bar: {qux: 1}}}},
// returns true: all keys from the template exist in the object
hasChainOfKeys(example1, template1);
@qgustavor
qgustavor / isValidEmail.js
Last active August 29, 2015 14:07
isValidEmail
/**
* Validates e-mail addresses
* Supports internacionalized e-mails
*/
function isValidEmail(input) {
// Split the e-mail into local part and domain part:
var parts = input.split('@');
// It needs to have those two parts:
if (parts.length !== 2) return false;
var reservedWords = "arguments caller length name prototype __proto__".split(" ")
module.exports = createNamedParameters
function createNamedParameters(argv, fn) {
var length = fn.length
var composed = Array(length)
if (argv.length !== length) throw new Error("Argument lengths don't match")
function composing() {
// note: require ES6
$('#frame').html('<canvas id="pinkSlime" resize></canvas><div id="werd" class="glitch" data-text=""></div>')
{let script=$('script[canvas="pinkSlime"]')[0];
script.innerHTML=script.innerHTML
// disable checking
.replace('Boolean(window.chrome)', 'true')
// replace IE specific javascript with the standards one
// http://stackoverflow.com/a/21512167
.replace(/event\.event\.(\w)/g, (a,b) => `event.event.client${b.toUpperCase()}`);
}
@qgustavor
qgustavor / fasterStronger.html
Last active August 29, 2015 14:15
Faster "Stronger"
<!doctype html>
<!-- Use cdn.rawgit.com or htmlpreview.github.io to test -->
<html lang="en">
<head>
<meta charset="utf-8">
<meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
<meta property="og:title" content="Harder, Better, Faster, Stronger"/>
<meta property="og:url" content="http://davealger.c.mom/stronger/"/>
<meta property="og:image" content="http://davealger.com/stronger/punk_small.jpg"/>
<meta property="og:site_name" content="davealger.com"/>
@qgustavor
qgustavor / jquery-jsx.js
Created March 12, 2015 12:18
Using JSX with jQuery:
// Requires: jQuery, Zepto or a library with similar api
let React = {createElement: (e, args, ...children) => $(`<${e}>`, args).append(
children.map(e => typeof e==='string' ? $('<span>',{text:e}) : e)
)};
// Usage:
$('.container').append(
<div>
<h1>Credens Justitiam</h1>
<p>Solti ola i <br />
@qgustavor
qgustavor / index.js
Last active August 29, 2015 14:18 — forked from tylor/index.js
/**
* This script takes a directory of images, looks for GPS
* coordinates in each file, and then writes the filename and
* decimal degrees to CSV. If you're pulling images off of your
* iPhone, using Image Capture is a quick way to move them onto
* your computer and get started.
*
* Make sure you have imagemagick installed:
* $ brew install imagemagick
* Download these files and install dependencies:
@qgustavor
qgustavor / chatzilla.js
Created June 3, 2015 20:57
Chatzilla automatic XDCC
// Usage:
// Start a XDCC download then use
// /eval [folowed with the code below]
(function down(i) {
let f = client.dcc.files,
s = f[f.length - 1].state,
_ = s.socketDisconnected;
s.socketDisconnected = () => {
_.call(s);
if (i === 1229) return; // LAST PACK NUMBER