Skip to content

Instantly share code, notes, and snippets.

View jlpoveda's full-sized avatar

Jose Luis Poveda jlpoveda

View GitHub Profile
@jlpoveda
jlpoveda / snmp_to_influxdb.py
Created September 6, 2019 08:21
Script to insert data in InfluxDB
from pysnmp import hlapi
from influxdb import InfluxDBClient
def get(target, oids, credentials, port=161, engine=hlapi.SnmpEngine(), context=hlapi.ContextData()):
handler = hlapi.getCmd(
engine,
credentials,
hlapi.UdpTransportTarget((target, port)),
context,
@jlpoveda
jlpoveda / uuid_from_bin.sql
Last active March 12, 2019 10:37
Sql function to convert an uuid from binary
DELIMITER |
CREATE FUNCTION uuid_from_bin(b BINARY(16))
RETURNS CHAR(36) DETERMINISTIC
BEGIN
DECLARE hex CHAR(32);
SET hex = HEX(b);
RETURN CONCAT(LEFT(hex, 8), '-', MID(hex, 9,4), '-', MID(hex, 13,4), '-', MID(hex, 17,4), '-', RIGHT(hex, 12));
END
|
.----------------------------------------------------.
| |
| _ .-"-. .-"-. .--. _ _ _ ____ |
| ,'` | | ._ `.| ._ \| / ,' '\| | _ .' ) | _|_|__
_|_ / /| | | | \ '| | \ | ; / ., || || || ; | |_(]___`\
/___[)' | | | | '-`/ | '-`/| | / /_| || || | \ `\| '(]____ '
| ____[) '-' | | |-' | .-' | |/ || `' | ; | |"(]___ |
; ___[)| .-. | | | | | | '-./`| || | / /| |__(]_ /
\ _[) |_| \_' '_| ._| '---' '--'`.__.'(_,' |_____||-`
`-| |
<?php
// $this['CarritoDetalle'] es una entidad de Doctrine 1 con Lazy Load.
//
// El problema es que en php 5.6 esto funciona bien porque evalúa la expresión antes de devolver el
// resultado pero en php 7 no lo evalúa.
//
public function getCampanyaId()
{
if (!empty($this['CarritoDetalle'][0]['atributo_campanya_2_id'])) {
@jlpoveda
jlpoveda / php
Created August 24, 2015 22:22
PDO rendimiento
<?php
class User {
private $matricula;
private $marca_id;
public function __construct($matricula, $marca_id)
{
$this->matricula = $matricula;
@jlpoveda
jlpoveda / php
Created August 24, 2015 21:02
PDO::FETCH_CLASS sample
<?php
class User {
private $matricula;
private $marca_id;
public function __construct($matricula, $marca_id)
{
$this->matricula = $matricula;
@jlpoveda
jlpoveda / elasticsearch01
Created September 25, 2014 21:38
Algunas pruebas con Elasticsearch
PUT /ofertix/campanya_producto/3
{
"nombre": "Zapatos 3",
"campanya_id": "3725",
"habilitado": "1",
"categoria": {
"1": "Actual",
"2": "Hombre",
"3": "Calzado",
"4": "Deportivo"
#!/usr/bin/env python
import sys, re
def gen_pin (mac_str, sn):
mac_int = [int(x, 16) for x in mac_str]
sn_int = [0]*5+[int(x) for x in sn[5:]]
hpin = [0] * 7
k1 = (sn_int[6] + sn_int[7] + mac_int[10] + mac_int[11]) & 0xF
k2 = (sn_int[8] + sn_int[9] + mac_int[8] + mac_int[9]) & 0xF
@jlpoveda
jlpoveda / compress_directory_images.sh
Created November 9, 2012 08:12
Compress all images of a directory
for i in $(ls *.jpg); do convert -quality 80 $i zz_out/$i; done
@jlpoveda
jlpoveda / pseudo_probability_function.php
Created November 7, 2012 11:06
Emular una función de probabilidad
// Array con probabilidades
$arrayProbabilities = (
20,
20,
10,
1,
20,
10
)
// Generamos un número entre 0 y la probabilidad más alta