Skip to content

Instantly share code, notes, and snippets.

View kylec32's full-sized avatar

Kyle Carter kylec32

View GitHub Profile
public void process(ExecutorService executorService) {
long startTime = System.currentTimeMillis();
try (ExecutorService executor = executorService) {
for (String url : getUrls()) {
executor.execute(() -> {
try {
new URL("https://" + url).getContent();
System.out.println("Finished processing: " + url);
} catch (IOException e) {
}
public class VirtualThread {
public static void main(String[] args) {
for (int i = 0; i < 1_000_000; i++) {
if (i%10_000 == 0) {
System.out.println(i);
}
Thread.startVirtualThread(() -> {
try {
Thread.sleep(Duration.ofMinutes(10).toMillis());
} catch (Exception e) {
public class PlatformThread {
public static void main(String[] args) {
for (int i = 0; i < 1_000_000; i++) {
if (i%10_000 == 0) {
System.out.println(i);
}
new Thread(() -> {
try {
Thread.sleep(Duration.ofMinutes(10).toMillis());
} catch (Exception e) {
Number of Items Throughput
25 5534.454
1,000 122.58
50,000 2.096
250,000 0.376
1,000,000 0.09
Java Version Number of Items Method Throughput Ops/ms
Java 17 25 Group By 1840.462
Java 17 25 Double Loop 2432.982
Java 8 25 Group By 2481.166
Java 8 25 Double Loop 2370.741
Java 17 1,000 Group By 55.222
Java 17 1,000 Double Loop 47.378
Java 8 1,000 Group By 78.105
Java 8 1,000 Double Loop 59.908
Java 17 50,000 Group By 1.09
Number of Items Method Throughput Ops/ms
25 Group By 1741.89
25 Double Loop 2337.535
1,000 Group By 54.75
1,000 Double Loop 77.319
50,000 Group By 1.085
50,000 Double Loop 0.963
250,000 Group By 0.167
250,000 Double Loop 0.14
1,000,000 Group By 0.041
@kylec32
kylec32 / PasswordChecker.java
Created January 31, 2022 02:21
Timing Side-Channel Mitigated Password Checker
private static boolean verifyPassword(String realPassword, String providedPassword) {
if (realPassword.length() != providedPassword.length()) {
return false;
}
int result = 0;
for (int i = 0; i < realPassword.length(); i++) {
result |= realPassword.charAt(i) ^ providedPassword.charAt(i);
}
@kylec32
kylec32 / PasswordChecker.java
Created January 31, 2022 01:06
Naive Password Check
private static boolean verifyPassword(String realPassword, String providedPassword) {
if (realPassword.length() != providedPassword.length()) {
return false;
}
for (int i = 0; i < realPassword.length(); i++) {
if (realPassword.charAt(i) != providedPassword.charAt(i)) {
return false;
}
}
@kylec32
kylec32 / lowercaser.py
Created May 13, 2021 04:56
Main part of S3 lowercaser
def lambda_handler(event, context):
for record in event['Records']:
try:
bucket_name = record['s3']['bucket']['name']
object_name = record['s3']['object']['key']
object_size = record['s3']['object']['size']
version_id = record['s3']['object']['versionId']
# Key's come HTML encoded, we need to remove that.
object_name = urllib.parse.unquote_plus(object_name)
@kylec32
kylec32 / serverless.yml
Created May 13, 2021 04:46
S3 Lowercaser serverless.yml
service: s3objectlowercaser
provider:
name: aws
runtime: python3.8
region: us-west-2
environment:
FAILURE_QUEUE_NAME:
Fn::GetAtt:
- FailedLowerCasingObject