Skip to content

Instantly share code, notes, and snippets.

Avatar

Mateusz Mrozewski mateuszmrozewski

View GitHub Profile
View gist:e6836d9dc6dd05b14761aa3081112e5b
journalctl -k | grep -i -e memory -e oom
View distinct.java
List.of(1, 2, 3, 3, 3, 4).stream()
.distinct()
.forEach(System.out::println);
@mateuszmrozewski
mateuszmrozewski / StreamsExample.java
Created Aug 16, 2019
Example of functional interfaces in streams
View StreamsExample.java
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 Feb 4, 2019
SSE-S3 example with header
View sses3.java
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 Jan 5, 2019
Uploading and downloading file from S3 using SSE-C
View s3.java
// 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();
View gist:a1c8447354aba8300a678ffde53d4281
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
View Open files limit OSX
sysctl -w kern.maxfiles=20480
sysctl -w kern.maxfilesperproc=18000
View Rabbit_MQ_dead_letter.java
@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 Feb 26, 2017
Remove docker images and containers
View 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
View Scala problem 19
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)
}
}