Skip to content

Instantly share code, notes, and snippets.

View paulo-raca's full-sized avatar

Paulo Costa paulo-raca

View GitHub Profile
@paulo-raca
paulo-raca / unicode_input.py
Last active February 18, 2023 22:56
Using UInput to enter unicode text
from evdev import UInput, ecodes as e
import time
# This class sends CTRL+SHIFT+U+<HEXCODE> sequences to produces arbitrary unicode characters.
# It works fine on Gnome applications, but not on KDE
# in https://en.wikipedia.org/wiki/Unicode_input#In_X11_.28Linux_and_other_Unix_variants.29
class UnicodeInput:
def __init__(self):
keys = [
e.KEY_LEFTCTRL,
@paulo-raca
paulo-raca / Asynchroneous transforms in Spark
Last active July 6, 2018 10:52
Spark is awesome for synchronous work (Usually CPU-bond). But once in a while, you need to throw an asynchronous operation in the middle (Usually IO-bound, e.g., calling a web server)
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaRDD;
@paulo-raca
paulo-raca / pcb.py
Last active January 5, 2017 02:00
A tiny PCB netlist generator in Python
from collections import OrderedDict, deque
class PcbObject:
def __init__(self, name=None, parent=None):
self._parent = parent
self._name = name or self.__class__.__name__
def symbol_prefix(self):
return self.__class__.__name__.upper().strip("_")
@paulo-raca
paulo-raca / RangeMultiMap.java
Last active May 12, 2016 04:18
A MultiMap-like data structure which maps ranges to values. You can lookup all values that enclose/are enclosed/intercept the query range
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.SortedMap;
import java.util.TreeMap;
@paulo-raca
paulo-raca / CNP.java
Created August 11, 2016 13:39
CPF e CNPJ
public abstract class CNP {
private final int digits;
private final int[] weight;
public static final CNP CNPJ = new CNP(6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2) {
public String format(String cnp) {
cnp = normalize(cnp);
return cnp.substring(0, 2) + "." + cnp.substring(2, 5) + "." + cnp.substring(5, 8) + "/" + cnp.substring(8, 12) + "-" + cnp.substring(12);
};
};
@paulo-raca
paulo-raca / pins_arduino.h
Last active August 15, 2016 01:40
Arduino support for ATMEGA2560 -- With ALL ports
/*
pins_arduino.h - Pin definition functions for Arduino
Part of Arduino - http://www.arduino.cc/
Copyright (c) 2007 David A. Mellis
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
package test;
class Outer {
public class A1 {}
protected class A2 {}
private class A3 {}
/*package*/ class A4 {}
public static class B1 {}
protected static class B2 {}
@paulo-raca
paulo-raca / AndroidManifest.xml
Last active April 13, 2022 01:02
getActiveNotifications() using NotificationListenerService
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="testapp.android.gradle.inutilfutil.com.myapplication">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
@paulo-raca
paulo-raca / scan.cpp
Created March 1, 2018 19:45
Seach for data on an array region with decreasing step sizes
#include <stdio.h>
#include <inttypes.h>
#include <stdlib.h>
void scan(uint64_t min, uint64_t max, uint64_t min_step = 1) {
uint64_t step = 1L<<63;
printf("%02" PRIu64 "\n", min);
while (step > min_step) {
for (uint64_t i = min + step / 2; i<max; i+=step) {
package com.crowdstrike.android.playstorecontroller.util;
import android.Manifest;
import android.app.ActivityThread;
import android.app.Instrumentation;
import android.app.UiAutomation;
import android.graphics.Bitmap;
import android.nfc.Tag;
import android.os.Build;
import android.os.Debug;