Skip to content

Instantly share code, notes, and snippets.

@luismasuelli
luismasuelli / AngularJS-Facebook.js
Last active August 29, 2015 14:06
Facebook Service (factory) to defer a call until the FB SDK instance is ready (or execute the deferred calls, or perform an immediate call, when the FB object is ready)
(function(){
var FBModule = angular.module('AngularFB', []);
var _fb_has_initialized = false;
var SDK = function($scope) {
this.$scope = $scope;
this._initialized = false;
this._calls = [];
};
@luismasuelli
luismasuelli / multipart.js
Last active August 29, 2015 14:08
Angular File Upload - Crea la directiva file-model con soporte para envio de multipart y dependencia de jqueryfilestyle. La directiva ng-model NO banca file uploads
(function(){
angular
.module('FileUploads', [])
.factory('FileUploads.FormDataBuilder', ['$window', function(window) {
return function(data) {
var fd = new window.FormData();
angular.forEach(data, function(value, key) {
console.log(value);
fd.append(key, value);
@luismasuelli
luismasuelli / inner-xy.txt
Last active August 29, 2015 14:09
Angular directive to capture the inner XY coordinates of the clicked element
See this answer: http://stackoverflow.com/a/26852822/1105249 which is better than my script since it is already provided.
@luismasuelli
luismasuelli / tornado.py
Created December 30, 2014 23:09
Ejemplo de Tornado con schedulear asincronicamente (lanzar "paralelamente") una tarea en forma de corrutina.
import tornado.ioloop
import tornado.web
import tornado.websocket
import tornado.gen
clients = []
class IndexHandler(tornado.web.RequestHandler):
@luismasuelli
luismasuelli / drf30-dj17-untranslated.po
Last active December 16, 2021 02:08
Mensajes no traducidos al español de Django-REST-Framework 3.0.5 respecto de Django==1.7.x
#NOTE: for a full translation, have your project hold a symlink to the rest_framework directory in your source tree
# AND include the options to follow symlinks in the makemessages command. Messages for django-rest-framework will
# be fully generated.
#: rest_framework/authtoken/serializers.py:20
msgid "User account is disabled."
msgstr "La cuenta de usuario está desactivada."
#: rest_framework/authtoken/serializers.py:23
msgid "Unable to log in with provided credentials."
@luismasuelli
luismasuelli / post-receive.sh
Created March 9, 2015 06:32
Implementacion de post-receive para poner en los git de webfaction de aplicaciones django regulares
#!/bin/sh
#myuser: account user @ webfaction
#mydeploy: web application name (when created in webfaction's cpanel interface)
#mydjangoprj: however is named the django project inside the application
# (NOTES: if project name is changed, the apache wsgi files must be changed accordingly)
GIT_WORK_TREE=/home/myuser/webapps/mydeploy/mydjangoprj git checkout -f master
GIT_WORK_TREE=/home/myuser/webapps/mydeploy/mydjangoprj git reset --hard
cd /home/myuser/webapps/mydeploy/mydjangoprj
#pip install --upgrade -r /home/myuser/webapps/mydeploy/mydjangoprj/requirements.txt
python2.7 manage.py collectstatic --noinput
@luismasuelli
luismasuelli / dice.rb
Created May 25, 2017 17:52
Dice rolling
Random.srand
class Integer
def d n
times.map{|_e| Random.rand(n) + 1}.inject 0, :+
end
private :d
def d2
d 2
function repeat(what, howMuch) {
var total = "";
for(var k=0; k<howMuch; k++) total += what;
return total;
}
function moo(v) {
return v.replace(/\S+/g, function(captured) {
return "M" + repeat("O", Math.min(captured.length - 1, 2));
});
}
@luismasuelli
luismasuelli / thumbnails.py
Created January 18, 2021 02:49
Get og:image and thumbnail it
from io import BytesIO
from PIL import Image
import requests
def get_image_from_body(soup):
"""
Given a soup, tries to get its og:image_tag.
:param soup: A parsed DOM, as a BeautifulSoup object.
:return: A PIL Image if everything went ok (a jpg/png image can be
@luismasuelli
luismasuelli / advanced_name_validator.py
Created January 18, 2021 17:03
Advanced name validator
# This code can easily be adapted to Python 3.
from __future__ import unicode_literals
from django.core.validators import RegexValidator as _RegexValidator
import unicodedata
from django.utils import six
# Another validator that could be useful: A regex validator using ^[\w_-]$.