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 / almost_sorted.py
Created November 7, 2019 17:49
Talently HR 1st problems
def almostSorted(arr):
s = sorted(arr)
diffcount = 0
diff1 = None
diff2 = None
for i in range(len(arr)):
@ondoheer
ondoheer / share.php
Created February 20, 2018 17:14
Social share links
<section class="article-footer-section article-recommend" id=" article-recommend">
<h4 class="recommend-title article-footer-section-title">Recomienda este artículo</h4><ul class="recommend-list">
<!-- TWITTER as data attributes-->
<li class="recommend-list-item" title="Comparte en Twitter">
<a href="http://twitter.com/share" data-count="none" data-url="<?php the_permalink();?>" data-text="<?php the_title(); ?>" target="_blank">
<div alt="f202" class="genericon genericon-twitter"></div>
</a>
</li>
<!-- TWITTER as uri-->
<li class="recommend-list-item" title="Comparte en Twitter">
@ondoheer
ondoheer / game.py
Created August 22, 2017 14:24
Valentin first refactoring
stumble_around = "You stumble around and fall in a knife. Good job!"
def start_room():
print "You enter a dark room with two doors. Do you go through door #1 or #2?"
door = raw_input("> ")
if door == "1":
bear_room()
elif door == "2":
pit_fall()
else:
print stumble_around
@ondoheer
ondoheer / Pagination.html
Created July 17, 2016 15:16
Pagination with parameters
{% macro render_pagination(pagination, endpoint, per_page, order_by, direction) %}
<ul class="pagination">
{% if pagination.has_prev %}
<li>
<a href="{{ url_for(endpoint, page=pagination.prev_num, per_page=per_page, order_by=order_by, direction=direction) }}" aria-label="Previous">
<span aria-hidden="true">&laquo;</span>
</a>
</li>
@ondoheer
ondoheer / views.py
Created April 20, 2016 16:55
Basic Flask Crud
class AdminFAQView(AdminView):
def __init__(self):
self.form = FAQQuestionForm()
self.questions = db.session.query(Question.id, Question.question).all()
def get(self, question_id=None):
form = self.form
questions = self.questions
# -----------------------------------------------------------------------
# Defining MIME types to ensure the web server actually knows about them.
# -----------------------------------------------------------------------
<IfModule mod_mime.c>
AddType application/javascript js
AddType application/vnd.ms-fontobject eot
AddType application/font-woff2 woff2
AddType application/x-font-ttf ttf ttc
AddType font/opentype otf
@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
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...
//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', ' ' . '...');
@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