Skip to content

Instantly share code, notes, and snippets.

View raupachz's full-sized avatar

Björn Raupach raupachz

View GitHub Profile
@raupachz
raupachz / SecretHash.md
Last active July 3, 2023 15:38
Amazon Cognito User Pools - SecretHash computation with OpenSSL

If your Amazon Cognito User Pool is configured with a Secret you need to append a SecretHash to the API's query argument. Otherwise you end up with error messages.

An error occurred (NotAuthorizedException) when calling the InitiateAuth operation: Client examplefoobar is configured for secret but secret was not received

Unfortunately the AWS Command Line Interface is unable to compute the SecretHash for you. Instead they provide you with a Python Script to do the computation for you.

You can also compute the SecretHash with OpenSSL. I do this in Bash Scripts. For example here is a little script to

@raupachz
raupachz / UserBean.java
Created January 9, 2022 18:02
Decoding a JWT in a JavaServer Faces backing bean
@Named
@SessionScoped
public class UserBean implements Serializable {
private Map<String, Object> claims;
@PostConstruct
public void postConstruct() {
FacesContext facesContext = FacesContext.getCurrentInstance();
HttpServletRequest httpServletRequest = (HttpServletRequest) facesContext.getExternalContext().getRequest();
@raupachz
raupachz / JWT.java
Created January 9, 2022 17:54
Very basic decoding of a JWT
public class JWT {
private static ObjectMapper objectMapper = new ObjectMapper();
public static Map<String, Object> of(String token) {
String[] parts = token.split("\\.");
String payload = parts[1];
String json = new String(Base64.getUrlDecoder().decode(payload), StandardCharsets.UTF_8);
TypeReference<HashMap<String,Object>> typeRef = new TypeReference<HashMap<String,Object>>() {};
try {
@raupachz
raupachz / latency.txt
Created January 7, 2021 09:24 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
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
@raupachz
raupachz / LambdaFunction.java
Created August 15, 2019 06:54
Code for my Medium article AWS Lambda for Java Developers
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
public class LambdaFunction implements RequestHandler<Void, String> {
private final long classloaderTime = System.currentTimeMillis();
private final long constructorTime;
private long methodTime;
public LambdaFunction() {
@raupachz
raupachz / Cores.java
Last active April 4, 2019 11:56
Code for my Medium article about wether or not more memory gives you more cores
public class Cores {
public Integer handle(Object o) {
return Runtime.getRuntime().availableProcessors();
}
}
@raupachz
raupachz / Prime.java
Created November 28, 2018 09:56
The code for my Medium story "Choosing the right amount of memory for your AWS Lambda Function"
public class Prime {
public int nth(int n) {
int p = 2;
for (int i = 0; i < n; ) {
if (prime(p++)) {
i++;
}
}
@raupachz
raupachz / Mail.java
Last active October 7, 2022 18:27
JavaMail API with Amazon Simple Email Service (SES) using the SMTP Interface
import com.sun.mail.smtp.SMTPTransport;
import java.io.IOException;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
/**
@raupachz
raupachz / raupach@twitter
Last active October 17, 2018 08:09
Public key for Twitter
-----BEGIN PGP PUBLIC KEY BLOCK-----
mQENBFvG7WkBCADAsVVUwImdMMbsoeNLlJvOckeNNnkC2tzR24AEBc0FUSBj0CcH
n6iJIJR/V3C4QIlbf+WHp8AyNV7wZnKS0BeM/lGRqWQwhI3ThQOz7tMBl3nPBBJ2
xiHAyXUtIRlCN5q1z0ZuaOH/1Ncd5oDA52oIl+eRLXaEF+fDhIJtBgf3FdEdtvKD
E73bVsf3sVigH5Q4Uvs6sTfdk8n/rIo4RZf2jkWDHvd/FW3xKqyGeDE+Gk53ofIv
wbhDNtGXcpaSycoysIlkJzb4u5GXyOA+ivq0iVKNpMg4jr8K2n1qRO2fdUPhlGOB
DlQPSNIVRhDvgFPHO7DYUoAn5JNa7pvQfJHBABEBAAG0GXJhdXBhY2ggPHJhdXBh
Y2hAdHdpdHRlcj6JAVQEEwEIAD4WIQQypcPuCKuHAN3VFkbKMNoulCXM4gUCW8bt
aQIbAwUJAeEzgAULCQgHAgYVCgkICwIEFgIDAQIeAQIXgAAKCRDKMNoulCXM4jmo
### Keybase proof
I hereby claim:
* I am raupachz on github.
* I am raupach (https://keybase.io/raupach) on keybase.
* I have a public key ASA5aglR8YssRwA-urEoMtWr9b2om5Y6mesKsEk7PnCvMAo
To claim this, I am signing this object: