Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Guillermo Gutiérrez ggalmazor

🏠
Working from home
View GitHub Profile
@ggalmazor
ggalmazor / read_description.cpp
Last active Jul 16, 2021
funcion para leer la frecuencia de transceptor por puerto serie (Arduino)
View read_description.cpp
void read_frequency() {
if (Serial.available() <= 0)
return;
String description = read_serial_message(0xFD);
if (!is_valid(description))
return;
return parse_frequency(description);
View keybase.md

Keybase proof

I hereby claim:

  • I am ggalmazor on github.
  • I am ggalmazor (https://keybase.io/ggalmazor) on keybase.
  • I have a public key ASAbZuXpyLdy8y8QZR-YKb2L5yVNgcFhlzkWN3dgyNr8MAo

To claim this, I am signing this object:

@ggalmazor
ggalmazor / README.md
Last active Feb 16, 2019
Stopping background jobs: a Java concurrency refactoring case
View README.md

Stopping background jobs: a Java parallel code refactoring case

I spend most of my working day helping to maintain and evolve the awesome OpenDataKit tool kit, which includes ODK Briefcase, a Java desktop application (Swing) that takes care of pulling, pushing and exporting forms.

Before continuing, I feel like I should give a disclaimer. It's a long post that's served me to put my thoughts together and fix in my head what I've learned. You could read on and miss some obvious and much simpler solution to some problem. If that happens, please, please, write a comment! I'm not trying to write any foundational text. I'm just a guy figuring out how to do parallel jobs in Java, and I'm probably wrong.

The challenge

Briefcase interacts with servers that store blank forms and answered form submissions using an HTTP API to download them to a user's computer for post-processing.

View Job.java
public class Job<T> {
private final JobAwareSupplier<T> block;
private Job(JobAwareSupplier<T> block) {
this.block = block;
}
public static <U> Job<U> supply(JobAwareSupplier<U> supplier) {
return new Job<>(supplier);
}
@ggalmazor
ggalmazor / Source.java
Last active Feb 8, 2019
Medium - Java Concurrency - Block that launches the pull process
View Source.java
public ExecutorService pull(List<FormStatus> forms) {
ExecutorService executor = new ForkJoinPool(
commonPool().getParallelism(),
commonPool().getFactory(),
this::handleError,
commonPool().getAsyncMode()
);
forms.stream()
.map(form -> pullOne(form, executor))
@ggalmazor
ggalmazor / ExportPanelForm.java
Created Mar 20, 2018
Indirection without abstraction - Snippet 3
View ExportPanelForm.java
public class ExportPanelForm {
private static final String EXPORTING = "Exporting";
private static final String DOT = ".";
private JLabel exportingLabel;
public void updateExportingLabel() {
String newText = cycle(exportingLabel.getText(), 19);
exportingLabel.setText(newText);
}
@ggalmazor
ggalmazor / ExportPanelForm.java
Last active Mar 20, 2018
Indirection without abstraction - Snippet 2
View ExportPanelForm.java
public class ExportPanelForm {
private static final String EXPORTING = "Exporting";
private static final String DOT = ".";
private JLabel exportingLabel;
public void updateExportingLabel() {
String text = exportingLabel.getText();
if (text.equals(EXPORTING + DOT + DOT + DOT + DOT + DOT + DOT + DOT + DOT + DOT + DOT)) {
text = EXPORTING + DOT;
} else {
@ggalmazor
ggalmazor / ExportPanelForm.java
Last active Mar 20, 2018
Indirection without abstraction - Snippet 1
View ExportPanelForm.java
public class ExportPanelForm {
private JLabel exportingLabel;
public void updateExportingLabel() {
String text = exportingLabel.getText();
if (text.equals("Exporting..........")) {
text = "Exporting.";
} else {
text += ".";
}