Skip to content

Instantly share code, notes, and snippets.

@felipap
felipap / main.json
Created July 12, 2014 21:52
Dump candidatos à presidência, seus vices, ao governo do Rio, e seus vices.
{
"presidente": {
"280000000067": {
"propostas": [
{
"endereco": "http://divulgacand2014.tse.jus.br/divulga-cand-2014/proposta/eleicao/2014/idEleicao/143/UE/BR/candidato/280000000067/idarquivo/152?x=1404936456000280000000067",
"documento": "1 - proposta_governo1404422153496.pdf"
}
],
"genero": "MASCULINO",
@felipap
felipap / share.js
Created December 4, 2013 00:42
Minimalistic share plugin for http://vempraruavem.org
$.fn.share = function (options) {
// Prevent binding multiple times.
if (this.find('.sn-share-btns').length)
return;
var defOptions = {
trigger: 'hover',
duration: 'fast',
@felipap
felipap / events.js
Last active December 29, 2015 17:09
Minimalistic backbone-like Javascript events for light usage.
function implementEvents() {
this._callbacks = {};
this.on = function (eventName, func, t) {
if (typeof func !== 'function')
throw "Invalid argument to .on() "+func
if (this._callbacks[eventName])
this._callbacks[eventName].push(t?func.bind(t):func);
else
this._callbacks[eventName] = [t?func.bind(t):func];
@felipap
felipap / defaultView.js
Created November 10, 2013 18:55
The basic object I use to inherit most of my views in vempraruavem.org from.
var DefaultView = Backbone.View.extend({
btn: $("<div>"),
constructor: function () {
var self = this;
this.btn.click(function () { self.toggle(); });
Backbone.View.apply(this, arguments);
this.$el.on('click', '[data-action=exit]', function () { self.hide(); })
},
show: function () {
this.$el.fadeIn();
@felipap
felipap / max.js
Last active January 17, 2017 19:05
Script for TamperMonkey for maximizing youtube videos.
// ==UserScript==
// @name youtube plz
// @namespace http://use.i.E.your.homepage/
// @version 0.1
// @description enter something useful
// @match http://www.youtube.com/watch?*
// @match https://www.youtube.com/watch?*
// @copyright 2012+, You
// ==/UserScript==
@felipap
felipap / animateOnFrameRate.coffee
Created October 6, 2013 20:46
Coffee script version. ;)
window.AnimateOnFrameRate = do ->
# thanks, Paul Irish
window.requestAnimationFrame or
window.webkitRequestAnimationFrame or
window.mozRequestAnimationFrame or
window.oRequestAnimationFrame or
window.msRequestAnimationFrame or
(callback) ->
window.setTimeout callback, 1000/60
@felipap
felipap / painter.coffee
Created October 4, 2013 11:34
A set of functions for basic canvas 2d functionality. I find it easier to manipulate objects abstractly like this, even when using a dedicated render() method for each of them.
painter =
applyCanvasOptions : (context, options) ->
if options.fill is true
context.fillStyle = options.color or 'black'
else
context.strokeStyle = options.color or 'blue'
context.lineWidth = options.width or 1
###### Canvas manipulation functions
@felipap
felipap / backpatch.js
Last active December 21, 2015 20:09
Extending patch:true behaviour in a Backbone application, to update only the given attributes.
// Extend PATCH:true option of Backbone.
// When model.save([attrs], {patch:true}) is called:
// - the method is changed to PUT;
// - the data sent is a hash with the passed attributes and their values;
var originalSync = Backbone.sync;
Backbone.sync = function(method, model, options) {
if (method === 'patch' && options.attrs instanceof Array) {
// pop attributes and add their values
while (e = options.attrs.pop())
options.attrs[e] = model.get(e);
@felipap
felipap / 4pong.html
Last active December 20, 2015 18:08
Trabalho do Castaneda.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf8">
<title>Pong Game</title>
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0-rc1/css/bootstrap.min.css" rel="stylesheet">
<link href="http://netdna.bootstrapcdn.com/font-awesome/3.2.0/css/font-awesome.css" rel="stylesheet">
<style type="text/css">
@felipap
felipap / henon.html
Last active December 19, 2015 17:48
Hénon attractor
<!DOCTYPE html>
<html>
<head>
<style>
canvas { border: 1px solid #DDD; }
</style>
</head>
<canvas width=1500 height=1000></canvas>
<script>
var ctx = document.querySelector('canvas').getContext('2d'),