Skip to content

Instantly share code, notes, and snippets.

View alejandrobernardis's full-sized avatar
🐻

Alejandro M. BERNARDIS alejandrobernardis

🐻
View GitHub Profile
@alejandrobernardis
alejandrobernardis / users.py
Last active May 22, 2022 19:53
Tornado Role
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2012 The Octopus Apps Inc.
# Licensed under the Apache License, Version 2.0 (the "License")
#
# Author: Alejandro M. Bernardis
# Email: alejandro.m.bernardis at gmail.com
# Created: Feb 6, 2012, 2:44:12 PM
#
@alejandrobernardis
alejandrobernardis / csv.py
Created February 10, 2012 16:50
CSV, MongoEngine
_Q = Q(...)&Q(...) # Query
_total = MyModel.objects(_Q).count()
if _total < 1:
error = MessageError(1, u"No se encontraron resultados con el filtro definido.")
else:
_skip = 0
_limit = 100
_range = int(_total/_limit)+1
_file_dir = os.path.abspath("")+"/my/path/csv"
@alejandrobernardis
alejandrobernardis / handlers.py
Created February 10, 2012 16:55
Tornado, Download File
class AdminFileHandler(BaseHandler):
@authenticated
def get(self, file_name):
_file_dir = os.path.abspath("")+"/my/path/downloads"
_file_path = "%s/%s" % (_file_dir, file_name)
if not file_name or not os.path.exists(_file_path):
raise HTTPError(404)
self.set_header('Content-Type', 'application/force-download')
self.set_header('Content-Disposition', 'attachment; filename=%s' % file_name)
@alejandrobernardis
alejandrobernardis / gist:1819960
Created February 13, 2012 20:30
Bash, ShellScript, Admin, Python, Supervisor
# (yr) variables
domain='mydomain.com'
vhost_dir=/my/path/vhosts
httpdocs_dir=$vhost_dir/$domain/httpdocs_python
supervisor_dir=$httpdocs_dir/apps-config
project_dir=$httpdocs_dir/apps/administrator
# (yr) helpers
alias py='/usr/local/bin/python2.7'
alias python='/usr/local/bin/python2.7'
apt-get update && apt-get -u upgrade
apt-get install build-essential tree joe
apt-get install python-setuptools
apt-get install mercurial subversion git
apt-get install ant curl sqlite3 mysql-server mysql-client mysql-common mongodb-server mongodb-clients python-mysqldb python-pycurl python-pymongo
easy_install supervisor
# interfaces
auto eth0
iface eth0 inet static
@alejandrobernardis
alejandrobernardis / gist:1829120
Created February 14, 2012 18:54
project create
cproject(){
if [ -z "$1" ]; then
echo "Define el nombre del cliente."
elif [ -z "$2" ]; then
echo "Define el nombre del projecto."
else
base_path=`pwd`
base_path=$base_path'/project/'$(date +%Y%m%d%H%M%S)
echo 'Base Path: '$base_path
client=$1
wget --no-check-certificate -O tornado-master.tar.gz https://github.com/facebook/tornado/tarball/master
wget --no-check-certificate -O pymongo-master.tar.gz https://github.com/mongodb/mongo-python-driver/tarball/master
wget --no-check-certificate -O mongoengine-master.tar.gz https://github.com/hmarr/mongoengine/tarball/master
wget --no-check-certificate -O wtforms-master.tar.gz https://bitbucket.org/simplecodes/wtforms/get/default.tar.gz
@alejandrobernardis
alejandrobernardis / gist:1830077
Created February 14, 2012 20:27
Basic timesince
#: -- timesince ----------------------------------------------------------------
def get_plural(value, singular, plural, message=""):
try:
return plural if int(value) > 1 else singular
except:
return message
def get_str_plural(value, singular, plural, message="", tmpl=u"%s %s"):
return tmpl % (value, get_plural(value, singular, plural))
@alejandrobernardis
alejandrobernardis / gist:1853912
Created February 17, 2012 14:56
Simple YouTube Video List
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2012 Young and Rubicam Digital Mexico.
# Licensed under the Apache License, Version 2.0 (the "License")
#
# Author: Alejandro M. Bernardis
# Email: alejandro.bernardis at gmail.com
# Created: Feb 17, 2012 08:54:18 AM
#
@alejandrobernardis
alejandrobernardis / build.properties
Created February 20, 2012 20:26
Flash, Flex SDK, AS3, ANT
######################################
## Project Information
######################################
author = Alejandro M. Bernardis
author.email = alejandrob@kirikacode.com
project.owner = Kirika Code
project.owner.url = http://www.kirikacode.com
project.fullname = AS3 Kirika Code Application
project.version = 1.0.0