All posts tagged #coding all posts RSS-feed

Performance in debug mode (Java/IntelliJ)

I'd like to highlight two steps to avoid performance issues when using breakpoints. Method/field breakpoints Is your application noticeably slower in debug mode, even when not in a break point? Did this problem start suddenly? Do computation-heavy tasks take especially long (like password hashing)? Then you may have some breakpoints that cost a lot of performance (why?). Breakpoints on lines of code are fast Breakpoints or fields and methods are slow (Breakpoints on declarations/comments don't work) In my experience, over... full post»

Example log4j2.xml (development)

For local development, I like to change some things in my log4j2 configuration. Make lines shorter, e.g. no worker names (just pid) or dates (just times). Prevent all logging to files, just console. Use colors for errors and warnings so they stand out. Filter out specific types of messages, and keep only specific other ones at debug level. Use buffering and async for better performance. So here it is! <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <Configuration monitorInterval="30"> <Appenders> <Console name="Console" target="SYSTEM_OUT" bufferSize="100">... full post»

Java performance: exceptions

This was a real performance problems recently, with some details redacted. It was found that filling in translated strings took up quite a lot of time. Translation requests are spread out all across the frontend, so no single step stood out, but with the help of YourKit, the problem was uncovered. As it turns out, the main problem was with this construct: for (int i = translationFiles.length - 1; i >= 0; i--) { try { ResourceBundle bundle = ResourceBundle.getBundle(translationFiles[i],... full post»

Java findFirst stream pitfall

Java streams have findAny and findFirst methods out of the box. And they works fine, they do exactly what they say: it gets one of the matches. But in my experience, often I don't want 'one of the matches', I want there to be a single match, and I want that one. The problem For example, finding the instances in a stream of customers var formExpressionInstance = getCustomers().stream() .filter(instance -> isDateInRange(ferenceDate, instance.getDateStart(), instance.getDateEnd())) .findFirst() If there are multiple matches, maybe... full post»

Java overload + vararg pitfall

If you are using overloads In Java, and one of them uses varargs, then there's a rare pitfall to be aware of. I ran into this a while back. There were two methods, similar to this: public void method( @Nullable Object first, @Nullable String second, @Nullable Integer third, @Nullable BigDecimal fourth, @Nullable Double fifth ) throws Exception { and public void method( @Nonnull Integer... varargs ) throws Exception { Then, someone added a sixth argument to the first method. Simultaneously... full post»

Some JetBrains IDE tips

Although they're expensive I really like the JetBrains IDEs. I use IntelliJ IDEA almost every day, and PyCharm and CLion quite frequently. Here are a few features I like! Multi-caret (info) to change multiple pieces of text simultaneously. You can place carets with a hotkey, but I especially like doing a search and putting a caret at each match. Much more flexible than search/replace. String manipulator: this plugin adds a lot of text manipulation on selected text under the hotkey... full post»

Show recently changed branches (git)

To show your recent branches using git: git for-each-ref --count=10 --sort=-committerdate refs/heads/ --format='%(HEAD) %(objectname:short) %(color:green)%(refname:short)%(color:reset) - %(contents:subject) (%(committerdate:relative))' Example output: * 14d5da9 parsing3 - Update version and readme (4 weeks ago) ae05513 dev - Version 0.4.0 (4 weeks ago) 6c695f0 parsing1 - Improve underscore handling in ints (4 weeks ago) 47fece2 parsing2 - Some progress, but pest output is not close enough to AST (5 weeks ago) 6c5aba2 webui-abandoned - No JIT for now (5 weeks ago) 7c60c75 site-url -... full post»

Symmetric encryption in Rust

I'm working on a file encryption utility (endec) in Rust. Encrypting and decrypting doesn't need much code, but it took me several hours of fiddling to arrive at the final version, so I thought I'd share the result. The crates I'm using (for the symmetric encryption part) are: aes for encryption secstr to store keys in memory more safely block-modes for block cipher utils So let's get right down to the code: use ::aes::Aes256; use ::block_modes::Cbc; use ::block_modes::BlockMode; use ::block_modes::block_padding::Iso7816;... full post»

What is async/await?

I've been pretty active on Hashnode and inactive here lately. So I'm going to repost an answer I gave on Hashnode here, because I'm lazy like that... This is a conceptual explanation, not a beginner tutorial. Yes, async/await a way for the thread to not sit idle while waiting for something (usually IO like files, database or network). When you read a file synchronously, your code does not do anything while the disk is busy. This means that for programs... full post»

Some reasons I do not like javascript

It is no secret that Javascript isn't the most well-designed language, and these points have probably been made a billion times, but now it's my turn! Note that this isn't a criticism about a lack of expressiveness. You can create great things with javascript. But you can also footgun yourself very easily, which is what I'm criticizing there. Most languages are expressive, but good ones help you avoid mistakes instead of making them. You can pass more or fewer arguments... full post»

Visitor pattern and dynamic dispatch

The Design Patterns book by the infamous Gang of Four contains 23 object oriented design patterns. Some of them are kind of obvious (Adapter), or have become common knowledge since the book was published in 1994 (Iterator). My personal favourite is Visitor. Visitor "represents an operation to be performed on the elements of an object structure. Visitor lets you define a new operation without changing the classes of the elements on which it operations" [except you need to add an... full post»

Analyzing a single, trivial Java statement

Java isn't a bad language, but it is also not great, and it's age shows. Let's look at this simple Java statement: if (!Boolean.TRUE.equals(getIsRequired())) { It's very simple and common, and yet it includes a lot of the things I don't particularly like about Java: We need a getter for a trivial property access. I like the Python way with @property, or the Kotlin way with getters and setters being called implicitly. It is not explicit that getIsRequired is a... full post»

Prevent ID-mistakes using Rust types

Recently, I've been interested in designing software to make hard-to-find bugs reveal themselves at compile-time. An idea I've read about (I forgot where) that I found fascinating is the use of a special type for IDs in objects that represent database rows. Problem For example, there may be a User table and a Posts table in the database, with each post belonging to one user. Each of these would be mapped to a class/struct in the programming language. Perhaps each... full post»

Linear model vs decision tree (in R)

Linear models vs decision trees I‚Äôve used the R statistical language a bit, a long time ago. It was my first real encounter with data science, but future encounters used Matlab and Python. But lately I‚Äôve been picking up R again, as it‚Äôs popular in the data science community. As practise / demo, I thought I‚Äôd do a simple exploration of the strengths and weaknesses of linear models versus decision trees. This was inspired by Claudia Perlich at kdnuggets. Let‚Äôs... full post»

Rainbow colormap in javascript

Simple one one this time! How to make an RGB rainbow colormap in javascript? Example: This is useful, for example, when plotting charts with something like chart.js. This is the code for it. The first part is converting hsl colors to rgb ones, which you might skip depending on which browsers you want to support. The second part generates a rainbow by simply rotating the hue of a hsl color. The other parameters are optional: you can make the colormap... full post»

Fortran closures

While trying to implement the Lancsoz method (to find the spectral range of a linear operation), I had to pass a procedure with some arguments bound to it (to keep things general). However, I read that Fortran has no closures, nor have I encountered something like Python's functools.partial (or javascript's .bind), nor **kwargs. So I got stuck for a little while, but some kind people at Stack Overflow came to the rescue as usual. It seems that something like a... full post»

Bye Make, hello SCons (Fortran)

Makefiles have been around for a long time and are used in many places. And not without reason: a straightforward dependency tree with one version of the target and a specific compiler and all the source in one directory is easy to setup and is handled well by (GNU) Make. It's a common situation, and if that describes your project, there's no need to switch. But the code I'm working with has a build script and Makefile that can make... full post»

PyCharm

I've started a draft about PyCharm 5 months ago. I really love PyCharm, it's the best! Everything is just so smooth. But it's hard to summarize what makes it great, and I don't want to list all the little details. I used Eclipse before, which wasn't bad, and there's not really any giant thing in PyCharm that Eclipse lacked (stability maybe). Rather, it's the hundred little details that add up to a much better experience. I also used Wing for... full post»

Dory backup removal

Daily backups, even if incremental, can fill up your disk space pretty quickly. So I've added some functionality to Dory to remove old backups. I wanted a way to keep a number of backups, with recent backups being closer together and past ones further apart. I've ended up using the reciprocal time-distance to each neighbour, multiplied by the square root of the age, as a 'redundancy score'. This way, if there are close neighbours (e.g. .two backups made on the... full post»

Minimal logging server & clients

Having solved backups, I attacked the the next important thing that gets in the way of building actual functionality: error logging. I've had some trouble setting up Sentry (possibly more my fault than Sentry's, but it does much more than I need so it's more work). I also tried Loggly which doesn't need server setup, but it captured mostly irrelevant syslog stuff and I'd need to pay a lot to keep logs for more than 7 days. So I figured... full post»

Reset static files cache each version (Django)

Ideally, you'd want your static files to be cached so that clients don't need to request them at all. In Apache, you can achieve this with: ExpiresActive on ExpiresDefault "access plus 1 year" Header append Cache-Control public But you also want the clients to request the new version as soon as anything changes. Since this can't be achieved with cache headers (they'll not request the files, so they never get the header), you can change the name instead. There's a... full post»

Logging to files

Logging the output of a shell script is easy enough: ./script.sh 1> log.out 2> log.err But if it the output is long and you find an error, you might want to know which output corresponds to it. Logging errors to one file, and output+errors to another is a little more tricky. And there are other potentially useful features: Truncate the log file if it gets too long. Keep the last part, and ideally whole lines. Add timestamps to each line... full post»

Ubuntu macros

The macro feature of Notepad++ was really useful. On Ubuntu I've had to do without Notepad++, and anyway it would be better to have something that works inn any program. I've found/made something today, and since StackOverflow locks all questions about such things, I'll post it here. First, install xmacro using sudo apt-get install -y xmacro. The basic commands are xmacrorec2 > "$macrofile" and xmacroplay "$DISPLAY" < "$macrofile". I've made a few small improvements: Assigned hotkeys so I can use... full post»

JSON: comments, order & numpy

Natively, JSON files do not support comments. Douglas Crockford removed them early on to prevent parsing directives, and the json standard is frozen now so they'll never return. Douglas Crockford is, of course, a pretty smart guy, so I'm not going to argue that decision. But like many other people, I want comments anyway. There's a package commentjson, but unfortunately it does not support Python 3. There are several other json tricks I like, so I made my own package... full post»

The markv.nl blog!

#security, #what-I-use, #type-systems, #games, #focus, #useless, #shell, #science, #imadethis, #java, #ide, #society

Comments

  1. Some reasons I do not like javascript @Mark A side effect of implicit type conversions https://kahde...
  2. Some reasons I do not like javascript @Mark Another interesting one https://twitter.com/sharifsbeat/...
  3. Some reasons I do not like javascript @sander yea fuck javascript man!
  4. Rainbow colormap in javascript @Mark The post has been expanded to include non-rainbow colorm...
  5. "Invite" someone to ssh into your machine without port forwarding or firewall changes @Mark Added details about how to use the established tunnel in...
  6. Rainbow colormap in javascript @Mark Now finally with color-coded source!
  7. Bye Make, hello SCons (Fortran) @Mark For SCons' own comparison against alternatives, have a l...
  8. Ubuntu macros @Mark Macro locks have been made more reliable, to prevent any...
  9. Ubuntu macros @Mark Updated after moving the files to https://github.com/mve...