Skip to content

Instantly share code, notes, and snippets.

View paulbares's full-sized avatar
🎯
Focusing

Paul Bares paulbares

🎯
Focusing
View GitHub Profile
@paulbares
paulbares / notificationtable.txt
Last active June 3, 2020 11:30
notification table
+--------------------+--------+---------------------------------------------------------+
| column | type | description |
+--------------------+--------+---------------------------------------------------------+
| id | int | Primary key |
+--------------------+--------+---------------------------------------------------------+
| type | string | A type, can be used to group notifications |
+--------------------+--------+---------------------------------------------------------+
| message | string | The message to send and display |
+--------------------+--------+---------------------------------------------------------+
| created_at | Instant| Timestamp of the notification creation date |
@paulbares
paulbares / recipienttable.txt
Last active June 8, 2020 14:05
recipient table
+--------------------+--------+---------------------------------------------------------+
| column | type | description |
+--------------------+--------+---------------------------------------------------------+
| id | int | Primary key |
+--------------------+--------+---------------------------------------------------------+
| notification_id | int | The id of the notification in the Notification table |
+--------------------+--------+---------------------------------------------------------+
| user_id | string | The receiver user id |
+--------------------+--------+---------------------------------------------------------+
| group_id | string | The receiver group id |
@paulbares
paulbares / notificationtablerow1.txt
Created June 3, 2020 11:31
notificationtablerow1
+----+--------+--------------+---------------------------+-----------+-------------+
| id | type | message | created_at | is_active | business_id |
+----+--------+--------------+---------------------------+-----------+-------------+
| 0 | "task" | "my message" | 2020-06-03T11:29:04+00:00 | true | "7" |
+----+--------+--------------+---------------------------+-----------+-------------+
@paulbares
paulbares / recipientrows1.txt
Last active June 8, 2020 14:04
recipientrows1
+----+-----------------+---------+----------+---------+
| id | notification_id | user_id | group_id | is_read |
+----+-----------------+---------+----------+---------+
| 0 | 0 | "user1" | null | 0 |
| 1 | 0 | "user2" | null | 0 |
| 2 | 0 | "user3" | null | 0 |
| 3 | 0 | null | "group1" | 0 |
| 4 | 0 | null | "group2" | 0 |
+----+-----------------+---------+----------+---------+
@Override
public void notify(DelegateTask delegateTask) {
String taskId = delegateTask.getId(); // This is our business_id
// Only support 2 types of event for the time being.
switch (delegateTask.getEventName()) {
case TaskListener.EVENTNAME_CREATE:
// Extract the candidate users and groups.
Set<String>[] candidates = extractCandidates(delegateTask.getCandidates());
// TODO send new notification to subscribers
break;
### Keybase proof
I hereby claim:
* I am paulbares on github.
* I am paulbares (https://keybase.io/paulbares) on keybase.
* I have a public key ASBYPOCzlKPl7hi5H-UoSxTP1FJcYa6nuNA_o_J9uJ8idQo
To claim this, I am signing this object:
@paulbares
paulbares / UUIDEncoder.java
Created August 27, 2020 12:44
Encode a UUID into a String of 16 characters (using ISO-8859-1 encoding)
import java.nio.charset.Charset;
import java.util.UUID;
public class UUIDEncoder {
/**
* Use this charset because each character is encoded as a single eight-bit code value so a UUID can be represented
* with 16 characters.
*/
private static final Charset CHARSET = Charset.forName("ISO-8859-1");
@paulbares
paulbares / server.js
Last active May 31, 2021 11:03
Node js server with https (self-signed certificate)
const https = require('https');
const fs = require('fs');
const mimeTypes = {
"html": "text/html",
"jpeg": "image/jpeg",
"jpg": "image/jpeg",
"png": "image/png",
"svg": "image/svg+xml",
"json": "application/json",
"js": "text/javascript",
File file = new File(CsvGenerator.FILE_PATH);
Iterator<String> iterator = Files.lines(file.toPath()).iterator();
AggregateResult result = new AggregateResult();
while (iterator.hasNext()) {
String line = iterator.next();
String[] values = line.split(",");
int year = Integer.parseInt(values[0]);
int mileage = Integer.parseInt(values[1]);
double price = Double.parseDouble(values[2]);
FileInputStream fileInputStream = new FileInputStream(CsvGenerator.FILE_PATH);
MyConsumer consumer = new MyConsumer();
read(fileInputStream, consumer);
...
private static void read(FileInputStream fileInputStream,
Consumer consumer) throws IOException {
FileChannel fileChannel = fileInputStream.getChannel();
ByteBuffer byteBuffer = ByteBuffer.allocate(capacity);