This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//MillerRabin.scala | |
import scala.language.implicitConversions | |
object MillerRabin { | |
implicit class MillerRabin(n: Long) { | |
private lazy val asl : Array[BigInt] = if (n < 2047L) Array(2L) | |
else if (n < 1373653L) Array(2L, 3L) | |
else if (n < 9080191L) Array(31L, 73L) | |
else if (n < 25326001L) Array(2L, 3L, 5L) | |
else if (n < 3215031751L) Array(2L, 3L, 5L, 7L) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Usage: ./multi4.sh first_command second_command third_command fourth_command | |
tmux send-keys "$1" 'C-m' | |
tmux split-window -v | |
tmux send-keys "$2" 'C-m' | |
tmux split-window -h | |
tmux send-keys "$3" 'C-m' | |
tmux select-pane -U | |
tmux split-window -h | |
tmux send-keys "$4" 'C-m' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component | |
@Conditional(MyComponent.EnabledCondition.class) | |
public class MyComponent { | |
protected static class EnabledCondition implements Condition { | |
private static final String ENABLED_PROPERTY = "mycomponent.enabled"; | |
@Override | |
public boolean matches(final ConditionContext context, final AnnotatedTypeMetadata metadata) { | |
final Environment environment = context.getEnvironment(); | |
return environment != null && Boolean.valueOf(environment.getProperty(ENABLED_PROPERTY)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static <T> CompletableFuture<List<T>> listOfFuturesToFutureList(final List<CompletableFuture<T>> listOfFutures) { | |
final Function<List<CompletableFuture<T>>, List<T>> transformFunction = futures -> futures.stream() | |
.map(CompletableFuture::join) | |
.collect(Collectors.toList()); | |
return CompletableFuture.allOf(listOfFutures.toArray(new CompletableFuture[0])) | |
.thenApply(v -> transformFunction.apply(listOfFutures)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
s3 = boto3.client('s3') | |
obj = s3.get_object(Bucket=bucket, Key=key) | |
lines = map(lambda x: x.decode('utf-8'), obj['Body'].iter_lines()) # Iterator which yields lines in file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git fetch -p; git branch -r --merged master | grep -Ev 'master|develop|main' | sed 's/origin\///' | xargs -n1 git push --delete origin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func mapF[T any, R any](f func(T) (R, error), values ...T) ([]R, error) { | |
result := make([]R, len(values)) | |
for _, value := range values { | |
mappedValue, err := f(value) | |
if err != nil { | |
return nil, fmt.Errorf("mapF failure: %w", err) | |
} | |
result = append(result, mappedValue) | |
} | |
return result, nil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def deep_merge(dict1: dict, dict2: dict) -> dict: | |
""" Merges two dicts. If keys are conflicting, dict2 is preferred. """ | |
def _val(v1, v2): | |
if isinstance(v1, dict) and isinstance(v2, dict): | |
return deep_merge(v1, v2) | |
return v2 or v1 | |
return {k: _val(dict1.get(k), dict2.get(k)) for k in dict1.keys() | dict2.keys()} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl -s https://api.github.com/users/milanboers/repos | grep \"clone_url\" | awk '{print $2}' | sed -e 's/"//g' -e 's/,//g' | xargs -n1 git clone |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Configuration | |
@EnableCaching | |
public class CacheConfiguration { | |
@Bean | |
public JCacheManagerFactoryBean cacheManagerFactoryBean() throws Exception { | |
JCacheManagerFactoryBean jCacheManagerFactoryBean = new JCacheManagerFactoryBean(); | |
jCacheManagerFactoryBean.setCacheManagerUri(new ClassPathResource("ehcache.xml").getURI()); | |
return jCacheManagerFactoryBean; | |
} |