Skip to content

Instantly share code, notes, and snippets.

View lava.util.CopyableRecord.java
/*
* MIT License
*
* Copyright (c) 2020 Sebastian Teumert <https://sebastian.teumert.net>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
@NetzwergX
NetzwergX / RecordMutabilityTest.java
Last active May 8, 2020
Demonstration of mutability of records & defensive copying to address it
View RecordMutabilityTest.java
import static org.junit.jupiter.api.Assertions.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.junit.jupiter.params.ParameterizedTest;
@NetzwergX
NetzwergX / ReadMe.md
Last active Dec 24, 2019
Eclipse configuration
View ReadMe.md

These are settings I found most helpful (start with Window > Preferences):

> Java > Code Style > Organize Imports > Number of static imports needed for .* (e.g. java.lang.Math.*): 1
Setting this to one prevents eclipse from messing up deliberately chosen static imports.

> Java > Editor > Syntax Coloring > Java > Type Variables > Enable [x]
(Choose bold and a good color e.g. cyan blue)

This allows one to use reasonable type variables, e.g. class Entity<Id> or MyMap<Key, Value>
instead of only non-descript single-letter type variables without confusing them for actual types.

@NetzwergX
NetzwergX / OptionalExt.java
Created Feb 13, 2019
Extension methods for Optional<E> via Manifold
View OptionalExt.java
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Supplier;
import manifold.ext.api.Extension;
import manifold.ext.api.This;
/**
* Extends {@link Optional<T>} with two new methods for acquiring values.
*/
@NetzwergX
NetzwergX / latency.txt
Created Dec 3, 2018 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
View latency.txt
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@NetzwergX
NetzwergX / SceneGraphDebugAppState.java
Last active May 18, 2020
Scene graph information display for JME3. Provides an app state that shows which geometry is picked, its parents & their controls and allows toggling wireframe on/off for picked geometry.
View SceneGraphDebugAppState.java
/*
* Copyright (c) 2018 Sebastian Teumert (<http://teumert.net>)
* Some rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
@NetzwergX
NetzwergX / DatePickerTableCell.java
Last active May 18, 2020
DatePickerTableCell, an implementation of a TableCell containing a DatePicker, with support for a custom DateTimeFormatter
View DatePickerTableCell.java
/*
* Copyright (c) 2017 Sebastian Teumert (<http://teumert.net>)
* Some rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
@NetzwergX
NetzwergX / CoordinateUtil.java
Created Aug 26, 2016
Simple utility for jme3 to convert cartesian to spherical coordinates and vice-versa
View CoordinateUtil.java
/*
* Copyright (c) 2016 Sebastian Teumert (<http://teumert.net>)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
View StackOverflow.cpp
/*
* written by Sebastian Teumert in 2016.
* Released into Public Domain. No Rights Reserved.
*/
#include "stdafx.h"
#include <string>
#include<map>
#include<vector>
View net\teumert\swt\ImageButton.java
/*
* Copyright (c) 2014 Sebastian Teumert (<http://teumert.net>)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
You can’t perform that action at this time.