Skip to content

Instantly share code, notes, and snippets.

View DarkSeraphim's full-sized avatar

Mark Hendriks DarkSeraphim

View GitHub Profile
@DarkSeraphim
DarkSeraphim / ListenerRegistry.java
Last active June 7, 2021 16:01
lock-free, eventually consistent Listener queues, with concurrent adds, iteration and removes. (CAUTION: definitely not tested properly)
interface Listener<T> {
boolean isActive(); // active, default true
void remove(); // active = false
void fire(T event);
}
private final AtomicInteger next = new AtomicInteger(0);
private final AtomicInteger listenerCount = new AtomicInteger(0);
private final AtomicInteger removed = new AtomicInteger(0);
@DarkSeraphim
DarkSeraphim / app.js
Created March 10, 2021 12:26
Pluggable PUT/GET service for Nexus testing
const Fastify = require('fastify');
const fastify = new Fastify();
const fs = require('fs');
const path = require('path');
const uploads = path.resolve(process.env.UPLOAD_DIR);
fs.mkdirSync(uploads, { recursive: true });
@DarkSeraphim
DarkSeraphim / EmbedBuilder.js
Created April 10, 2020 23:34
Discord.js live embed builder
const { RichEmbed, MessageEmbed } = require('discord.js');
const Embed = RichEmbed || MessageEmbed;
const commands = {
'title': (embed, input) => embed.setTitle(input),
'description' (embed, input) => embed.setDescription(input),
// etc
}
public interface Particles {
static Particles LT9 = new ParticlesLT9();
static Particles GE9 = new ParticlesGE9();
void summonParticles(Player p, String particles);
private static Particles getParticles() {
return getVersionNumber() < 9 ? LE9 : GE9;
}
@DarkSeraphim
DarkSeraphim / FieldResolver.java
Last active June 19, 2019 17:02
GraphQL4J design v2
public interface FieldResolver extends BiFunction<SelectionSet, Map<String, Object>, CompletableFuture<?>> {
}
@DarkSeraphim
DarkSeraphim / Query.java
Last active June 12, 2019 17:31
GraphQL design
public class Query {
private User.Query user;
private Query(Builder builder) {
user = builder.user;
}
public static Builder builder() {
return new Builder();
}
@DarkSeraphim
DarkSeraphim / MarkdownFormatter.java
Created June 10, 2019 13:58
Formatting Markdown to HTML
import java.util.Deque;
import java.util.Objects;
import java.util.Queue;
import java.util.Set;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map;
import java.util.HashMap;
class MarkdownFormatter {
@DarkSeraphim
DarkSeraphim / ignore-errors.js
Created March 27, 2019 11:02
Ignoring Discord.js errors that are expected and ignoreable
const { Constants: { APIErrors }} = require('discord.js');
const errorCodes = new Set(Object.values(APIErrors));
/**
* Usage:
* const {APIErrors: {CANNOT_MESSAGE_USER}, ignore} = require('./ignore-errors.js');
* try {
* let message = await user.send('Hello world').catch(ignore(CANNOT_MESSAGE_USER));
* if (message === null) {
* // User has DMs closed
const fs = require('fs');
const path = require('path');
function getStat(path) {
try {
return fs.statSync(path);
} catch (e) {
return null;
}
}
@DarkSeraphim
DarkSeraphim / Email.txt
Created February 4, 2019 19:14
Spam email from "KPN"
Received: from HK2APC01HT106.eop-APC01.prod.protection.outlook.com (2603:10a6:209:7f::27) by AM6PR08MB4246.eurprd08.prod.outlook.com with HTTPS via AM6P191CA0050.EURP191.PROD.OUTLOOK.COM; Mon, 4 Feb 2019 05:21:53 +0000
Received: from HK2APC01FT025.eop-APC01.prod.protection.outlook.com (10.152.248.53) by HK2APC01HT106.eop-APC01.prod.protection.outlook.com (10.152.249.166) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1580.10; Mon, 4 Feb 2019 05:21:52 +0000
Authentication-Results: spf=none (sender IP is 5.157.86.28) smtp.mailfrom=administratie.nl; live.nl; dkim=pass (signature was verified) header.d=pbandenvervanger.nl;live.nl; dmarc=none action=none header.from=administratie.nl;
Received-SPF: None (protection.outlook.com: administratie.nl does not designate permitted sender hosts)
Received: from filter03.hostcontrol.com (5.157.86.28) by HK2APC01FT025.mail.protection.outlook.com (10.152.248.170) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_