Skip to content

Instantly share code, notes, and snippets.

View mrvaldes's full-sized avatar
🌴

Matias Valdes mrvaldes

🌴
View GitHub Profile
@mrvaldes
mrvaldes / .block
Last active May 11, 2020 22:42
test
license: mit
@mrvaldes
mrvaldes / update_firefox.sh
Last active August 17, 2020 19:40
update firefox
#!/bin/bash
DOWNLOAD_DIR="${HOME}/Downloads"
FIREFOX_DIR="/usr/lib/firefox_dev"
DESKTOPFILE="${HOME}/.local/share/applications/firefox_dev.desktop"
URL="https://download.mozilla.org/?product=firefox-devedition-latest-ssl&os=linux64&lang=en-US"
REDIR_URL=$(curl --head --silent "${URL}" --write-out "%{redirect_url}")
FILENAME=$(basename "${REDIR_URL}")
FILENAME_PATH="${DOWNLOAD_DIR}/${FILENAME}"
echo $FILENAME_PATH
curl --location "${URL}" --output "${FILENAME_PATH}"
@mrvaldes
mrvaldes / mysql_8_skip_locked.py
Created November 14, 2018 07:38
MySQL 8.0 SQLAlchemy suffix with SKIP LOCKED
# Use compiler extension to change SELECT FOR UPDATE with SKIP LOCKED, supported since MySQL 8.
# As of SQLAlchemy v1.2 SKIP LOCKED is only compiled for Oracle and PostgreSQL backends.
# ref:
# https://dev.mysql.com/doc/refman/8.0/en/innodb-locking-reads.html
# https://docs.sqlalchemy.org/en/latest/core/selectable.html#sqlalchemy.sql.expression.Select.with_for_update
from sqlalchemy.ext.compiler import compiles
from sqlalchemy.sql.expression import Select
from sqlalchemy.sql.selectable import ForUpdateArg
@mrvaldes
mrvaldes / strace_uses.sh
Created July 26, 2018 18:13
strace uses
# forgot to redirect output to log:
strace -f -p <pid> -e write 2>&1 | tee /tmp/log.txt
@mrvaldes
mrvaldes / inplace-line-update.py
Last active November 2, 2017 01:07
Example of inplace line editing (update line by line) on a big file
def iterate_rainbow(file):
import mmap
import contextlib
import csv
from io import StringIO
encoding = 'utf-8'
csv_opts = {'delimiter': ';', 'quoting': csv.QUOTE_MINIMAL, 'quotechar': '"'}
with open(file, 'r+b') as fd:
with contextlib.closing(mmap.mmap(fd.fileno(), 0, access=mmap.ACCESS_WRITE)) as mm:
@mrvaldes
mrvaldes / sqlalchemy_mapping_related_model_columns.py
Last active June 21, 2017 21:22
sqlalchemy mapping related model columns
@mrvaldes
mrvaldes / geoalchemy-st_contains.py
Created May 19, 2017 17:35
Example of GeoAlchemy2 to filter query by spatial type (ST) functions
from geoalchemy2 import Geography, Geometry
from sqlalchemy import cast
...
class Node(db.Model):
....
def get_area(self, type_key):
try:
return Area.query.filter(Area.type_key == type_key).filter(
cast(Area.polygon, Geometry).ST_Contains(
cast(self.point, Geometry))).first() or None
make -qp | awk -F':' '/^[a-zA-Z0-9][^$#\/\t=]*:([^=]|$)/ {split($1,A,/ /);for(i in A)print A[i]}'
for n in $(tail -n +3 primes1.txt); do [ ! -z "${n##*[!0-9]*}" ] && echo $n; done
@mrvaldes
mrvaldes / php-exception-closures.php
Last active August 29, 2015 13:56
PHP test of exceptions behavior in closures
<?php
echo "php version: ".phpversion()."\n";
echo "\ncall named function:\n---\n";
function named() {
try{
echo "try\n";return true;
} finally {
echo "finally\n";return false;
}