Skip to content

Instantly share code, notes, and snippets.

@b3ni
b3ni / numero_letras.py
Created February 20, 2018 17:21 — forked from efrenfuentes/numero_letras.py
Numero a letras (Python)
#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = 'efrenfuentes'
MONEDA_SINGULAR = 'bolivar'
MONEDA_PLURAL = 'bolivares'
CENTIMOS_SINGULAR = 'centimo'
@b3ni
b3ni / .bash_aliases
Last active August 29, 2015 14:15
.bash_aliases
alias log-apache='tail -f /var/log/apache2/error.log'
alias python-clean='find . -name "*.py[c|o]" -exec rm -rvf {} \;'
@b3ni
b3ni / mixin_search.py
Last active August 29, 2015 14:14
SearchMixin
from operator import or_
from django.db.models import Q
from django.core.exceptions import ImproperlyConfigured
class SimpleSearchMixin(object):
def search_query(self):
return self.request.GET.get('query_search')
def get_context_data(self, **kwargs):
@b3ni
b3ni / README.markdown
Created April 16, 2012 15:31 — forked from gudbergur/README.markdown
Bootstrap's Typeahead plugin extended (allowing for AJAX functionality) among other things

This is a fork of Bootstrap Typeahead that adds minimal but powerful extensions.

For example, process typeahead list asynchronously and return objects

  # This example does an AJAX lookup and is in CoffeeScript
  $('.typeahead').typeahead(
    # source can be a function
    source: (typeahead, query) ->
 # this function receives the typeahead object and the query string
@b3ni
b3ni / Tools.php
Created March 9, 2012 10:18
Tools for create hooks in Prestashop
<?php
// Add in /override/Tools.php
/**
* Añade un hook al sistema
*/
function addHook($name, $title, $desc, $position=1) {
return Db::getInstance()->Execute('INSERT INTO `'._DB_PREFIX_.'hook` (`name`, `title`, `description`, `position`) VALUES (\''.$name.'\', \''.$title.'\', \''.$desc.'\', '.$position.')');
}
@b3ni
b3ni / validar_telfonos_es.php
Created March 7, 2012 14:57
Valida números de teléfono ES
<?php
/**
* Comprueba si es número de teléfono válido:
*
* ######### | ### ###### | ### ## ## ##
*
* @param $telefono string, número de teléfono a comprobar
*
* @return true o false
*/
@b3ni
b3ni / check_codigo_postal.php
Created March 7, 2012 14:44
Valida códigos postales
<?php
/**
* Comprueba si es un número de postal válido: #####
*
* @param $codigo string, código postal a comprobar
*
* @return true o false
*/
static public function isCodigoPostal($codigo) {
return preg_match('/^[0-9]{5,5}$/', $codigo);
@b3ni
b3ni / addRewriteRule.php
Created December 14, 2011 06:28
Add directive RewriteRule to .htaccess file easily in the hook "afterCreateHtaccess"
public static function addRewriteRule($rules, $comment="", $endcomment="") {
if (($htaccess = file_get_contents(_PS_ROOT_DIR_.'/.htaccess')) === FALSE)
return FALSE;
if (($pos = strrpos($htaccess, "<IfModule mod_rewrite.c>")) === FALSE)
return FALSE;
if (($pos = strpos($htaccess, "</IfModule>", $pos)) === FALSE)
return FALSE;
@b3ni
b3ni / add_days.php
Created December 9, 2011 09:38
Add days to date in php
/**
* Add days to a date.
*
* @param string $d, date
* @param int $ndays, number of days
* @param string $format, format date (@see: http://php.net/manual/en/function.date.php)
*/
function add_days($ndays, $d, $format="Y-m-d") {
$p = $ndays > 1 ? "s" : "";
$nf = strtotime(date($format, strtotime($d)) . " +".$ndays." day". $p);