Skip to content

Instantly share code, notes, and snippets.

View blackjid's full-sized avatar
🎹

Juan Ignacio Donoso blackjid

🎹
View GitHub Profile
@blackjid
blackjid / gist:2628871
Created May 7, 2012 16:41
A clean way to get data from a form element using the submit event
//Requires underscore, jquery
$(document).on('submit', 'selector.to.the.form.element', function(e){
// The the data from the form
var formData = _.reduce($(e.currentTarget).serializeArray(), function(memo, val){
memo[val.name] = val.value;
return memo;
},{});
@blackjid
blackjid / dateDjango.js
Created April 19, 2012 16:53
Create a Javascript date object with the time synced with the server time. The code must be processed in the server.
// Django template
(function(){
var _date = new Date();
date = {
gmtOffset: {% now "Z" %},
offset: {% now "U" %} - Math.round(_date.getTime() / 1000),
now: function(unix){
if(unix)
return Math.round(_date.getTime() / 1000) + this.offset + _date.getTimezoneOffset()*60*1000 + this.gmtOffset*1000;
return new Date(((Math.round(_date.getTime() / 1000) + this.offset)*1000) + _date.getTimezoneOffset()*60*1000 + this.gmtOffset*1000);