Instantly share code, notes, and snippets.

🏠
Working from home

# Jesús Gómezjgomo3

🏠
Working from home
• Sort options
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) http://cep.xor.aps.anl.gov/software/qt4-x11-4.2.2/qtopiacore-testingframebuffer.html */
Last active Feb 21, 2020
Return the first n elements of a collection by natural order of by a key function
View top.py
 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):
Created Feb 6, 2020
View evenword.py
 from collections import Counter def even_word(word): return sum(1 for w, n in Counter(word).items() if n%2 != 0)
Created Jan 14, 2020
Merge periods or ranges in a collection of them
View unificar.py
 ''' >>> 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))
Created Jan 7, 2020
Kind of range, but for anything that supports adding, or can be combined by a given optional function
View series.py
 ''' 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 provided. >>> ns = serie(10, 4) >>> next(ns); next(ns); next(ns) 10
Created Jan 3, 2020
Defines the ip_in_sn function to tell if an IP as string is in a Subnet as string
View ipinsubnet.py
 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 = '192.0.2.1' sn = '192.0.2.0/24'
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) SELECT tc.table_name watcher , ctu.table_name target FROM 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"
Created Jun 4, 2019 — forked from drmalex07/README-oneshot-systemd-service.md
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/setup-foo.sh`:

Created May 29, 2019
WeatherWizard Java Tutorial example without Applets
View WeatherWizard.java
 /* * 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. *
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) Class.new do include(Sidekiq::Worker, Wisper::Publisher) sidekiq_options(:queue => :report) define_method :perform do |*args, **kwargs| success = false begin context = klass.new.perform(*args, **kwargs) broadcast(:deliveried_report_delivery, context)
You can’t perform that action at this time.