Skip to content

Instantly share code, notes, and snippets.

View ergoithz's full-sized avatar
🚚
Moved to gitlab.com/ergoithz

Felipe A. Hernandez ergoithz

🚚
Moved to gitlab.com/ergoithz
View GitHub Profile
@ergoithz
ergoithz / port.py
Created October 8, 2014 08:50
Python port chooser
import socket
used_ports = [None]
def choose_port(address='127.0.0.1'):
port = None
while port in used_ports:
testsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
testsocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
testsocket.bind((address, 0))
port = testsocket.getsockname()[1]
@ergoithz
ergoithz / xpath_soup.py
Last active January 11, 2025 16:34
Generate unique XPATH for BeautifulSoup element
#!/usr/bin/python
# -*- coding: utf-8 -*-
import bs4
def xpath_soup(element):
# type: (typing.Union[bs4.element.Tag, bs4.element.NavigableString]) -> str
"""
Generate xpath from BeautifulSoup4 element.
@ergoithz
ergoithz / json.py
Last active September 16, 2022 18:10
python json datetime encoder
import json
import datetime
import dateutil.parser
class JSONEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, datetime.datetime):
return {
'type': 'datetime',
'data': obj.isoformat()
@ergoithz
ergoithz / .pystartup
Last active May 10, 2016 14:02
Python autocomplete and history
# Add auto-completion and a stored history file of commands to your Python
# interactive interpreter. Requires Python 2.0+, readline. Autocomplete is
# bound to the TAB key by default (you can change it - see readline docs).
#
# Store the file in ~/.pystartup, and set an environment variable to point
# to it: "export PYTHONSTARTUP=$HOME/.pystartup" in bash.
import atexit
import os
import readline
@ergoithz
ergoithz / dev_startup.sh
Created December 16, 2015 07:40
Generic script to start vagrant on current directory on a terminal (great for running at startup)
#!/usr/bin/env bash
DIR=$( dirname "${BASH_SOURCE[0]}" )
cd $DIR
vagrant up
gnome-terminal -e "bash -c 'vagrant ssh';bash"
@ergoithz
ergoithz / tzsnippet.js
Last active April 7, 2016 14:38
Javascript current TZ string (for ISO_8601)
/**
* This snipped generates the offset part of ISO_8601 datetime strings.
* Useful for composed datetime strings as required for APIs complying RFC3339.
*/
var
tz = (new Date()).getTimezoneOffset(),
pad = function (v){
var sv = Math.abs(parseInt(v, 10)).toString();
return '00'.substr(sv.length) + sv;
},
@ergoithz
ergoithz / getparam.js
Last active August 11, 2016 10:02
parse GET parameters from JS
function getParam(key, qs) {
const
results = [],
reg = new RegExp(`(^|\&)(${key})(=([^&]*))?($|\&)`);
let
match = reg.exec(qs = qs||document.location.search.substr(1));
while(match){
results.push(match[3]?decodeURIComponent(match[4].replace('+', ' ')):true);
match = reg.exec(qs = qs.substr(match.index + match[0].length - 1));
}
@ergoithz
ergoithz / fuzzytime.js
Created September 22, 2016 12:51
Fuzzy time from seconds.
intervals = [
{t: 0.001, s: 'a millisecond', p: '%d milliseconds'},
{t: 1, s: 'a second', p: '%d seconds'},
{t: 60, s: 'a minute', p: '%d minutes', m: 1},
{t: 3600, s: 'an hour', p: '%d hours', m: 1},
{t: 86400, s: 'a day', p: '%d days', m: 1},
{t: 604800, s: 'a week', p: '%d weeks', m: 1},
{t: 2629800, s: 'a month', p: '%d months', m: 2},
{t: 31587840, s: 'a year', p: '%d years', m: 2},
];
@ergoithz
ergoithz / magisk.g5.howto.md
Last active August 30, 2021 20:35
LG G5 MAGISK-ROOT HOWTO

LG G5 (H850) TWRP & MAGISK (ROOT)

This tutorial shows the entire process of oficially unlocking, TWRP recovery flashing, and Magisk rooting your european LG G5.

Important

  • Unlocking bootloader wipes all your phone data, backup first.
  • Do not flash no-verity-opt-encrypt.zip, it causes random issues and it's not needed unless you want a writable system partition, and you probably don't (it prevent stock roms from being updated).
  • DO NOT WIPE data partition: As long user-data partition is encrypted with a key stored there, it will be no longer available.
  • If you have working root support, remove it (binary and application) before installing Magisk.
  • Root APPs with Magisk-related issues:
  • All non-magisk root managers.
@ergoithz
ergoithz / regexp.md
Last active February 16, 2020 09:04

ISODATE

^(\d{4}-((0[1-9]|1[0-2])-([0-1][1-9]|[12][0-8])|(0[13-9]|1[012])-(29|30)|(0[13578]|1[02])-31)|(\d\d(0[48]|[2468][048]|[13579][26])|(0[48]|[2468][048]|[13579][26])00)-02-29)$

Regular expression visualization

Debuggex Demo