Skip to content

Instantly share code, notes, and snippets.

View advanced_name_validator.py
# 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_-]$.
@luismasuelli
luismasuelli / thumbnails.py
Created Jan 18, 2021
Get og:image and thumbnail it
View thumbnails.py
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
View moo.js
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));
});
}
View dice.rb
Random.srand
class Integer
def d n
times.map{|_e| Random.rand(n) + 1}.inject 0, :+
end
private :d
def d2
d 2
@luismasuelli
luismasuelli / post-receive.sh
Created Mar 9, 2015
Implementacion de post-receive para poner en los git de webfaction de aplicaciones django regulares
View post-receive.sh
#!/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 / drf30-dj17-untranslated.po
Last active Aug 29, 2015
Mensajes no traducidos al español de Django-REST-Framework 3.0.5 respecto de Django==1.7.x
View drf30-dj17-untranslated.po
#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 / tornado.py
Created Dec 30, 2014
Ejemplo de Tornado con schedulear asincronicamente (lanzar "paralelamente") una tarea en forma de corrutina.
View tornado.py
import tornado.ioloop
import tornado.web
import tornado.websocket
import tornado.gen
clients = []
class IndexHandler(tornado.web.RequestHandler):
@luismasuelli
luismasuelli / inner-xy.txt
Last active Aug 29, 2015
Angular directive to capture the inner XY coordinates of the clicked element
View inner-xy.txt
See this answer: http://stackoverflow.com/a/26852822/1105249 which is better than my script since it is already provided.
@luismasuelli
luismasuelli / multipart.js
Last active Aug 29, 2015
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
View multipart.js
(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 / AngularJS-Facebook.js
Last active Aug 29, 2015
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)
View AngularJS-Facebook.js
(function(){
var FBModule = angular.module('AngularFB', []);
var _fb_has_initialized = false;
var SDK = function($scope) {
this.$scope = $scope;
this._initialized = false;
this._calls = [];
};