Skip to content

Instantly share code, notes, and snippets.

Working from home

Jesús Gómez jgomo3

Working from home
View GitHub Profile
jgomo3 / framebuffer.c
Created Apr 5, 2020 — forked from FredEckert/framebuffer.c
Paint Pixels to Screen via Linux FrameBuffer
View framebuffer.c
To test that the Linux framebuffer is set up correctly, and that the device permissions
are correct, use the program below which opens the frame buffer and draws a gradient-
filled red square:
retrieved from:
Testing the Linux Framebuffer for Qtopia Core (qt4-x11-4.2.2)
jgomo3 /
Last active Feb 21, 2020
Return the first n elements of a collection by natural order of by a key function
import heapq
def top(n, col, key=None):
return heapq.nsmallest(n, col, key)
# Alternative, descent only for small n.
from itertools import count
def top_small_n(n, col, key=None):
from collections import Counter
def even_word(word):
return sum(1 for w, n in Counter(word).items() if n%2 != 0)
jgomo3 /
Created Jan 14, 2020
Merge periods or ranges in a collection of them
>>> periodos = [(3, 5), (7, 8), (11, 12), (-10, -1), (6, 10), (-2, 2)]
>>> periods_intersection((3, 5), (7, 8))
>>> periods_intersection((7, 8), (6, 10))
(7, 8)
>>> periods_intersection((-10, -1), (-2, 2))
(-2, -1)
>>> periods_union((-10, -1), (-2, 2))
(-10, 2)
>>> periods_union((6, 10), (7, 8))
jgomo3 /
Created Jan 7, 2020
Kind of range, but for anything that supports adding, or can be combined by a given optional function
Defines the function serie, which...
From an starting point generates all the values following
by the given period.
It works with numbers, anything that support adding or
anything that support the optional binary opperation
>>> ns = serie(10, 4)
>>> next(ns); next(ns); next(ns)
jgomo3 /
Created Jan 3, 2020
Defines the ip_in_sn function to tell if an IP as string is in a Subnet as string
import ipaddress
def ip_in_sn(ip_str, sn_str):
ip = ipaddress.ip_address(ip_str)
sn = ipaddress.ip_network(sn_str)
return ip in sn
if __name__ == '__main__':
ip = ''
sn = ''
jgomo3 / edgelist.sql
Created Aug 9, 2019
Create an edge list of relations being related by foreign key [postgres]
View edgelist.sql
-- Pre: The names of the relations to consider are in a relation named nodes in
-- the public schema (it could be parametrized)
tc.table_name watcher
, ctu.table_name target
information_schema.table_constraints tc
INNER JOIN information_schema.constraint_table_usage ctu ON tc.constraint_name = ctu.constraint_name
INNER JOIN nodes pt ON tc.table_name = pt."name"
jgomo3 /
Created Jun 4, 2019 — forked from drmalex07/
An example with an oneshot service on systemd. #systemd #systemd.service #oneshot


Services declared as oneshot are expected to take some action and exit immediatelly (thus, they are not really services, no running processes remain). A common pattern for these type of service is to be defined by a setup and a teardown action.

Let's create a example foo service that when started creates a file, and when stopped it deletes it.

Define setup/teardown actions

Create executable file /opt/foo/

jgomo3 /
Created May 29, 2019
WeatherWizard Java Tutorial example without Applets
* Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
jgomo3 / publisher_worker_class_factory.rb
Created Apr 12, 2019
One way to wrap mundane things to a Sidekiq Worker perform method
View publisher_worker_class_factory.rb
module Notification
def self.publisher_worker_class(klass) do
include(Sidekiq::Worker, Wisper::Publisher)
sidekiq_options(:queue => :report)
define_method :perform do |*args, **kwargs|
success = false
context =*args, **kwargs)
broadcast(:deliveried_report_delivery, context)
You can’t perform that action at this time.