Skip to content

Instantly share code, notes, and snippets.

View gurbuzali's full-sized avatar
🏠
Working from home

Ali Gurbuz gurbuzali

🏠
Working from home
View GitHub Profile
public class IsAnagram {
boolean anagram(String s1, String s2) {
if(s1.length() != s2.length()) {
return false;
}
int[] counts = new int[26];
for(int i=0; i<s1.length(); i++) {
//'a' - 'a' -> 0, 'b' - 'a' -> 1 ....
counts[s1.charAt(i)-'a']++;
@gurbuzali
gurbuzali / terminationprotection.sh.txt
Created July 4, 2020 02:25 — forked from huevos-y-bacon/aws_ec2_termination_protection.md
Enable or disable EC2 instance "Termination Protection" via AWS CLI (shell)
# Loop through all EC2 instances and enable termination protection
for I in $(aws ec2 describe-instances --query 'Reservations[].Instances[].[InstanceId]' --output text); do aws ec2 modify-instance-attribute --disable-api-termination --instance-id $I; done
# Loop through all EC2 instances and disable termination protection
for I in $(aws ec2 describe-instances --query 'Reservations[].Instances[].[InstanceId]' --output text); do aws ec2 modify-instance-attribute --no-disable-api-termination --instance-id $I;done
import com.hazelcast.config.Config;
import com.hazelcast.config.EventJournalConfig;
import com.hazelcast.jet.config.JetConfig;
import com.hazelcast.jet.pipeline.JournalInitialPosition;
import com.hazelcast.jet.pipeline.Pipeline;
import com.hazelcast.jet.pipeline.Sinks;
import com.hazelcast.jet.pipeline.Sources;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
package jet.avro;
import com.hazelcast.jet.Traverser;
import com.hazelcast.jet.Traversers;
import com.hazelcast.jet.core.AbstractProcessor;
import com.hazelcast.jet.core.ProcessorMetaSupplier;
import com.hazelcast.jet.core.ProcessorSupplier;
import com.hazelcast.jet.function.DistributedBiFunction;
import com.hazelcast.jet.impl.util.Util;
import org.apache.avro.file.DataFileReader;
package jet;
import com.hazelcast.ringbuffer.StaleSequenceException;
public class RingBuffer<T> {
private T[] ringItems;
private long tailSequence = -1;
/*
* Copyright (c) 2008-2017, Hazelcast, Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
/*
* Copyright (c) 2008-2017, Hazelcast, Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
/*
* Copyright (c) 2008-2017, Hazelcast, Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
HazelcastInstance instance = Hazelcast.newHazelcastInstance();
IMap<Integer, Integer> map = instance.getMap("map");
IntStream.range(0, 90000).parallel().forEach(i -> map.put(i, i));
PagingPredicate<Integer, Integer> pagingPredicate = new PagingPredicate<>(100);
Set<Map.Entry<Integer, Integer>> entrySet = map.entrySet(pagingPredicate);
int count = 0;
for (Map.Entry<Integer, Integer> entry : entrySet) {
assertEquals(count++, entry.getKey());
/*
* Copyright (c) 2008-2016, Hazelcast, Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software