This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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_-]$. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Random.srand | |
class Integer | |
def d n | |
times.map{|_e| Random.rand(n) + 1}.inject 0, :+ | |
end | |
private :d | |
def d2 | |
d 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tornado.ioloop | |
import tornado.web | |
import tornado.websocket | |
import tornado.gen | |
clients = [] | |
class IndexHandler(tornado.web.RequestHandler): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
See this answer: http://stackoverflow.com/a/26852822/1105249 which is better than my script since it is already provided. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(){ | |
var FBModule = angular.module('AngularFB', []); | |
var _fb_has_initialized = false; | |
var SDK = function($scope) { | |
this.$scope = $scope; | |
this._initialized = false; | |
this._calls = []; | |
}; |