Skip to content

Instantly share code, notes, and snippets.

Carlos Jenkins carlos-jenkins

Block or report user

Report or block carlos-jenkins

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@carlos-jenkins
carlos-jenkins / split.py
Last active Nov 4, 2019
Split a collection in two parts as defined by the given criteria.
View split.py
def split(iterable, criteria=lambda e: e):
"""
Split a collection in two parts as defined by the given criteria.
Usage::
>>> split([1,2,3,4,5,6], lambda e: e > 2)
([3, 4, 5, 6], [1, 2])
By default, the element itself is used as the criteria::
@carlos-jenkins
carlos-jenkins / cache.py
Last active Oct 4, 2019
Cache the result of a function for certain time.
View cache.py
from time import monotonic
from functools import wraps
def cache(expiration_s):
"""
Cache the result of a function for certain time.
There is one restriction: all arguments of the wrapped function must be
immutable, that is, they must be used as key in a dictionary.
@carlos-jenkins
carlos-jenkins / jobqueue.groovy
Last active Oct 3, 2019
Jenkins script to get job queues
View jobqueue.groovy
import groovy.json.JsonOutput
result = []
Jenkins.instance.queue.items.each {
// Only consider BuildableItem
// Other known objects are:
// - BlockedItem, which lacks the runId
if (it instanceof Queue.BuildableItem) {
result.add([
@carlos-jenkins
carlos-jenkins / kuraterm.glade
Last active Sep 13, 2019
Example of a Gtk application using a VTE terminal widget written in Python 3
View kuraterm.glade
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<requires lib="vte-2.91" version="0.52"/>
<object class="GtkWindow" id="window">
<property name="can_focus">False</property>
<signal name="delete-event" handler="stop" swapped="no"/>
<child>
<placeholder/>
@carlos-jenkins
carlos-jenkins / nopenlimit.py
Created Sep 6, 2019
Get and set the NOPEN limit (maximum number of open files)
View nopenlimit.py
from resource import RLIMIT_NOFILE, getrlimit, setrlimit
def setfilelimits(limit):
soft, hard = getrlimit(RLIMIT_NOFILE)
if limit > hard:
raise RuntimeError(
'Unable to raise open files limit to {}. '
'Hard limit is set to {}'.format(
@carlos-jenkins
carlos-jenkins / difftool.sh
Created Jul 19, 2019
Setup Meld for git difftool
View difftool.sh
sudo apt install meld
git config --global alias.difftree 'difftool --dir-diff'
git config --global diff.tool meld
git config --global difftool.prompt false
# Now use it:
# git difftree master..HEAD
# git difftree e49286eb1acbae69058856c744676c63d1154ba6..57adcd018d6e11c0982187cddfce6ee2bb641c6d
@carlos-jenkins
carlos-jenkins / base64.py
Created Jul 2, 2019
Calculate the length in bytes of a base64 string.
View base64.py
def b64len(b64str):
"""
Calculate the length in bytes of a base64 string.
This function could decode the base64 string to a binary blob and count its
number of bytes with len(). But, that's inefficient and requires more
memory that really needed.
Base64 encodes three bytes to four characters. Sometimes, padding is added
in the form of one or two '=' characters.
@carlos-jenkins
carlos-jenkins / async_poll.py
Created Jul 2, 2019
Just a generic polling function
View async_poll.py
from time import time
from asyncio import sleep
from .poll import NotReadyYet
async def poll(
func,
timeout_s=30.0, polling_s=5.0,
catchexcs=(NotReadyYet, ), pollcb=None,
@carlos-jenkins
carlos-jenkins / namespace.py
Last active Jun 6, 2019
Access dictionary using dot notation
View namespace.py
"""
Simple dictionary to object class.
"""
from collections import Mapping
try:
from pprintpp import pformat
except ImportError:
from pprint import pformat
@carlos-jenkins
carlos-jenkins / si.js
Last active Sep 23, 2019
Auto-converter of arbitrary values to International System of Units (SI) human readable prefix.
View si.js
/*
* Auto-converter of arbitrary values to International System of Units (SI)
* human readable prefix.
*
* Typical usage:
*
* const txpackets = 2450
* const txbytes = txpackets * 256
* const txtime = 2.0
*
You can’t perform that action at this time.