Skip to content

Instantly share code, notes, and snippets.

View marcelaraujo's full-sized avatar

Marcel Araujo marcelaraujo

View GitHub Profile
@marcelaraujo
marcelaraujo / gist:10610335
Created April 14, 2014 01:49
jQuery window resize
/* Get size of viewport */
layout.winWidth = $(window).width();
layout.winHeight = $(window).height();
/* Get available width by subtracting the size of the rest of the components */
var dwidth = layout.winWidth - 63;
var dheight = layout.winHeight - 111;
/* Check if scrollbars are needed (cheight and cwidth are canvas element's height and width)*/
var vScrollNeeded = dheight < app.cheight;
var person = {};
Object.defineProperty(person, 'firstName', {
get: function() { return firstName; },
set: function(newName) { firstName = newName; },
enumerable: true
});
Object.defineProperty(person, 'lastName', {
get: function() { return lastName; },
var fs = require('fs');
var net = require('net');
var http = require('http');
var https = require('https');
var httpAddress = '/path/to/http.sock';
var httpsAddress = '/path/to/https.sock';
fs.unlinkSync(httpAddress);
fs.unlinkSync(httpsAddress);
/*! Copyright (c) 2011 Piotr Rochala (http://rocha.la)
* Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
* and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
*
* See working example at http://rocha.la/fun-with-pixels-html5-video-canvas
*
*/
var canvasVideo = function()
{
var $ = jQuery,
var $this = element; //cache
(function loop() {
if (!$this.paused && !$this.ended) {
context.drawImage($this, 0, 0);
setTimeout(loop, 16.67); // drawing at 30fps
}
})();
var requestAnimFrame = (function () {
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function (/* function */ callback, /* DOMElement */ element) {
window.setTimeout( callback, 16.667 );
};
})();
function updateSVG() {
var el = document.querySelector('.icon-user');
var style = window.getComputedStyle(el);
var uri = style.backgroundImage;
var svg64 = uri.replace(/^.+base64,/, "").replace(/\"?\)$/, "")
var xml = window.atob(svg64);
var hex = '#' + Math.floor(Math.random()*16777215).toString(16);
var color = xml.replace(/fill="#[A-Za-z0-9]+"/, 'fill="' + hex + '"');
var color64 = window.btoa(color);
var colorUri = "url('data:image/svg+xml;base64," + color64 + "')";
@marcelaraujo
marcelaraujo / test.html
Last active August 29, 2015 14:01
xmlrequest api bug at Chrome
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script type="text/javascript">
var httpRequest;
if (window.XMLHttpRequest) { // Mozilla, Safari, ...
#!/usr/bin/env python
# Clone or update all a user's gists
# curl -ks https://gist.githubusercontent.com/fedir/5466075/raw/gist-backup.py | USER=fedir python
# USER=fedir python gist-backup.py
import json
import urllib
from subprocess import call
from urllib import urlopen
import os

Moving from jQuery

Events

// jQuery
$(document).ready(function() {
  // code
})