Skip to content

Instantly share code, notes, and snippets.

View ondoheer's full-sized avatar

Pedro Baumann ondoheer

  • Athelas Perú
  • Lima - Perú
View GitHub Profile
@ondoheer
ondoheer / Index function
Created November 20, 2014 20:19
Flask-Stormpath-Wedding login function
@frontend.route('/')
@frontend.route('/index')
@login_required
@pony.db_session
def index():
# We check if the user exists in the database we load it,
# otherwise we create a new one.
user_id = user.get_id()
server {
# Running port
listen 80;
server_name pedroyluciasecasan.com www.pedroyluciasecasan.com; #nombre del dominio(s) que debe asociar a esa ruta
#logs (logs independientes para la web, las carpetas de la ruta DEBEN existir)
access_log /var/www/logs/pedroyluciasecasan.com/access.log;
error_log /var/www/logs/pedroyluciasecasan.com/error.log;
<?php
// Check for empty fields
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['phone']) ||
empty($_POST['message']) ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "No arguments Provided!";
return false;
@ondoheer
ondoheer / gist:70c739a32245024cfadf
Created April 8, 2015 17:44
Sqlalchemy tutorial code
from sqlalchemy import create_engine
#in memory only sqlite db
engine = create_engine('sqlite:///demo.db', echo=True)
# Lazy Connecting
# The Engine, when first returned by create_engine(), has not actually tried to connect to the database yet; that happens only the first time it is asked to perform a task against the database.
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
@ondoheer
ondoheer / send_mail.py
Created April 27, 2015 03:25
Trouble sending mail asynchronously
@main.route("/mail/<int:_id>/<int:number>")
@login_required
def mailSession(_id, number):
from flask_mail import Message
from decorators import async
from app import mail, create_app
@ondoheer
ondoheer / game.py
Last active October 12, 2015 13:27
Tic Tac toe Implementation against player and AI, AI not yet implemented
import sys
import random
import copy
class Game():
def __init__(self):
self.board = [" "] * 9
self.playing_board = copy.deepcopy(self.board)
self.player1 = {
@ondoheer
ondoheer / grav
Created November 23, 2015 17:49
nginx.conf
server {
#listen 80;
index index.html index.php;
## Begin - Server Info
root /var/www/;
server_name grav;
## End - Server Info
## Begin - Index
//Función para convertir el custom_field('xx') en un excerpt de 50 palabras máximo
function get_athelas_custom_field_excerpt($title, $chars) {
global $post;
$text = get_field($title);
if ( '' != $text ) {
$text = strip_shortcodes( $text );
$text = apply_filters('the_content', $text);
$text = str_replace(']]>', ']]>', $text);
$excerpt_length = $chars; // in words
$excerpt_more = apply_filters('excerpt_more', ' ' . '...');
edis_1 | [1] 20 Dec 22:51:18.478 * Background saving started by pid 14
redis_1 | [14] 20 Dec 22:51:18.562 * DB saved on disk
redis_1 | [14] 20 Dec 22:51:18.564 * RDB: 6 MB of memory used by copy-on-write
redis_1 | [1] 20 Dec 22:51:18.579 * Background saving terminated with success
postgres_1 | ERROR: role "catwatch" already exists
postgres_1 | STATEMENT: CREATE USER catwatch WITH PASSWORD 'bestpassword'
postgres_1 | ERROR: role "catwatch" already exists
postgres_1 | STATEMENT: CREATE USER catwatch WITH PASSWORD 'bestpassword'
redis_1 | [1] 20 Dec 23:41:20.277 * 100 changes in 300 seconds. Saving...
@ondoheer
ondoheer / crop_resize.py
Created December 27, 2015 01:35
Pillow image crop and resize
def resize_and_crop(img_path, modified_path, size, crop_type='top'):
"""
Resize and crop an image to fit the specified size.
args:
img_path: path for the image to resize.
modified_path: path to store the modified image.
size: `(width, height)` tuple.
crop_type: can be 'top', 'middle' or 'bottom', depending on this
value, the image will cropped getting the 'top/left', 'middle' or