Print an error message without printing a traceback and close the program when a condition is not met

You can turn off the traceback by limiting its depth. Python 2.x import sys sys.tracebacklimit = 0 Python 3.x In Python 3.5.2 and 3.6.1, setting tracebacklimit to 0 does not seem to have the intended effect. This is a known bug. Note that -1 doesn’t work either. Setting it to None does however seem to … Read more

Keycloak retrieve custom attributes to KeycloakPrincipal

To add custom attributes you need to do three things: Add attributes to admin console Add claim mapping Access claims The first one is explained pretty good here: https://www.keycloak.org/docs/latest/server_admin/index.html#user-attributes Add claim mapping: Open the admin console of your realm. Go to Clients and open your client This only works for Settings > Access Type confidential … Read more

Is there a “right” way to have NSTextFieldCell draw vertically centered text?

The other answers didn’t work for multiple lines. Therefore I initially continued using the undocumented cFlags.vCentered property, but that caused my app to be rejected from the app store. I ended up using a modified version of Matt Bell’s solution that works for multiple lines, word wrapping, and a truncated last line: -(void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView … Read more

How to create a C compiler for custom CPU?

Quick overview/tutorial on writing a LLVM backend. This document describes techniques for writing backends for LLVM which convert the LLVM representation to machine assembly code or other languages. [ . . . ] To create a static compiler (one that emits text assembly), you need to implement the following: Describe the register set. Describe the … Read more

Android Using layer-list for button selector

Step-1 create three different layer_list xml under drawable folder for three different state of button. example the name of those xml is layer1.xml, layer2.xml, layer3.xml <?xml version=”1.0″ encoding=”utf-8″?> <layer-list xmlns:android=”http://schemas.android.com/apk/res/android” > <item> <shape xmlns:android=”http://schemas.android.com/apk/res/android” android:shape=”rectangle” > <gradient android:angle=”270″ android:startColor=”#0000ff” android:endColor=”#0000dd” android:type=”linear” /> </shape> </item> </layer-list> Step-2 create a selector xml named as btn_background.xml and pass … Read more

How to create a closed (circular) ListView?

My colleague Joe, and I believe we have found a simpler way to solve the same problem. In our solution though instead of extending BaseAdapter we extend ArrayAdapter. The code is as follows : public class CircularArrayAdapter< T > extends ArrayAdapter< T > { public static final int HALF_MAX_VALUE = Integer.MAX_VALUE/2; public final int MIDDLE; … Read more