Skip to content

Instantly share code, notes, and snippets.

View mateuszmrozewski's full-sized avatar

Mateusz Mrozewski mateuszmrozewski

  • Sydney, Australia
View GitHub Profile
@mateuszmrozewski
mateuszmrozewski / gist:e6836d9dc6dd05b14761aa3081112e5b
Created September 19, 2019 01:21
Check kernerl logs for memory issues
journalctl -k | grep -i -e memory -e oom
List.of(1, 2, 3, 3, 3, 4).stream()
.distinct()
.forEach(System.out::println);
@mateuszmrozewski
mateuszmrozewski / StreamsExample.java
Created August 16, 2019 08:09
Example of functional interfaces in streams
Stream.generate(() -> Math.random())
.mapToLong(x -> (long) (x * 10))
.filter(x -> x % 2 == 0)
.limit(10)
.forEach(System.out::println);
@mateuszmrozewski
mateuszmrozewski / sses3.java
Created February 4, 2019 09:44
SSE-S3 example with header
PutObjectRequest putRequestUnencrytped = PutObjectRequest.builder()
.bucket("myunencrypted-bucket")
.key("my-file.png")
.serverSideEncryption(ServerSideEncryption.AES256)
.build();
client.putObject(putRequestUnencrytped, Paths.get("my-file.png"));
@mateuszmrozewski
mateuszmrozewski / s3.java
Last active January 5, 2019 21:04
Uploading and downloading file from S3 using SSE-C
// Generate a random 256 bit AES key and encode it in Base64
KeyGenerator keyGenerator = KeyGenerator.getInstance("AES");
keyGenerator.init(256, new SecureRandom());
SecretKey secretKey = keyGenerator.generateKey();
String secretKeyString = Base64.getEncoder().encodeToString(secretKey.getEncoded());
// Generate md5 digest of the key and encode it in Base64
MessageDigest md5 = MessageDigest.getInstance("MD5");
md5.update(secretKey.getEncoded());
byte[] digest = md5.digest();
@mateuszmrozewski
mateuszmrozewski / gist:a1c8447354aba8300a678ffde53d4281
Created June 10, 2017 09:09 — forked from sebsto/gist:19b99f1fa1f32cae5d00
Install Maven with Yum on Amazon Linux
sudo wget http://repos.fedorapeople.org/repos/dchen/apache-maven/epel-apache-maven.repo -O /etc/yum.repos.d/epel-apache-maven.repo
sudo sed -i s/\$releasever/6/g /etc/yum.repos.d/epel-apache-maven.repo
sudo yum install -y apache-maven
mvn --version
sysctl -w kern.maxfiles=20480
sysctl -w kern.maxfilesperproc=18000
@Bean
public List<Declarable> queueDeclarations()
{
boolean durable = true;
boolean autoDelete = false;
boolean exclusive = false;
Map<String, Object> args = new HashMap<>();
args.put("x-dead-letter-exchange", "dl.exchange");
args.put("x-dead-letter-queue", "dl.queue");
return Arrays.asList(
@mateuszmrozewski
mateuszmrozewski / Remove docker images and containers
Last active February 26, 2017 10:33
Remove docker images and containers
#!/bin/bash
# Delete all containers
docker rm -f $(docker ps -a -q)
# Delete all images
docker rmi -f $(docker images -q)
# Delete dangling volumes
docker volume ls -qf dangling=true | xargs -r docker volume rm
object S99_P19 {
def rotate[T](n: Int, ts: Seq[T]): Seq[T] = (n, ts) match {
case (_, Nil) => Nil
case (0, seq) => seq
case (x, seq) => rotate(x - 1, seq.last +: seq take seq.length - 1)
}
}