Skip to content

Instantly share code, notes, and snippets.

View carlos-jenkins's full-sized avatar

Carlos Jenkins carlos-jenkins

View GitHub Profile
@carlos-jenkins
carlos-jenkins / base64.py
Created July 2, 2019 06:39
Calculate the length in bytes of a base64 string.
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 / setup.py
Created July 1, 2017 00:46
Cythonization of a pure Python package in setup.py
# Run me with:
# python3 setup.py bdist_wheel --cythonize
# ...
if '--cythonize' in argv:
from Cython.Build import cythonize
packaging = {
'ext_modules': cythonize('lib/**/*.py'),
}
@carlos-jenkins
carlos-jenkins / multihooks.py
Last active August 10, 2023 22:12
Delegating script for multiple git hooks
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright (C) 2015-2017 Carlos Jenkins <carlos@jenkins.co.cr>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
@carlos-jenkins
carlos-jenkins / kuraterm.glade
Last active April 2, 2023 13:28
Example of a Gtk application using a VTE terminal widget written in Python 3
<?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 / app.py
Created February 10, 2014 20:03
Example to set to a Gtk application a custom theme.
# -*- coding:utf-8 -*-
#
# Copyright (C) 2013 Carlos Jenkins <carlos@jenkins.co.cr>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
@carlos-jenkins
carlos-jenkins / app.py
Created February 10, 2014 22:42
Gtk+ 3.0 application theming using GResource. Compile using `glib-compile-resources gtktheme.gresource.xml`
# -*- coding:utf-8 -*-
#
# Copyright (C) 2013 Carlos Jenkins <carlos@jenkins.co.cr>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
@carlos-jenkins
carlos-jenkins / add_cert.sh
Created May 19, 2016 20:15
Download and add SSL certificate to shared system NSS database. A.k.a how the fuck do you add a certificate to Chrome/Chromium.
#!/usr/bin/env bash
set -o errexit
set -o nounset
# set -o xtrace
DOMAIN=${1:-}
@carlos-jenkins
carlos-jenkins / app.py
Created February 6, 2014 20:31
How to programatically add new menu items to menu item in PyGObject.
"""
Hierarchy is:
- GtkMenuBar
- GtkMenuItem
- GtkMenu
- GtkMenuItem
- GtkImageMenuItem
- GtkCheckMenuItem
- GtkRadioMenuItem
- GtkSeparatorMenuItem
@carlos-jenkins
carlos-jenkins / to_iso8601_and_back.py
Last active May 8, 2022 21:19
Create and parse ISO8601 with Offset with standard library only in Python 3.5 and 3.6
# PARSING AN ISO8601 WITH OFFSET FORMATTED STRING USING A PYTHON VERSION PRIOR
# TO 3.7 WITH THE STANDARD LIBRARY ONLY
#
#
# For the formatting:
#
# This returns a datetime object with the timezone set to UTC.
# The internal time can now be interpreted as UTC.
#
# datetime.now(timezone.utc)
@carlos-jenkins
carlos-jenkins / vg.c
Created February 7, 2014 23:17
Valgrind test program to demostrate memory access violation, memory leak or double free problems in a C program.
#include <stdlib.h>
#include <stdio.h>
// Compile with:
// gcc -std=c99 -g -Wall -O0 -o vg vg.c
// Run with:
// valgrind --leak-check=full ./vg [1|2|3]
int read_and_write(int* buff, int size, int seed)
{