Skip to content

Instantly share code, notes, and snippets.

@makiftutuncu
makiftutuncu / Either.java
Last active June 8, 2023 23:01
A Basic Implementation of Scala's Either in Java 8
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
public abstract class Either<L, R> {
public static final class Left<L, R> extends Either<L, R> {
public Left(L left) {
super(left, null);
}
@slaypni
slaypni / pmap.kt
Last active January 9, 2020 11:37
Parallel map for kotlin
import kotlinx.coroutines.experimental.async
import kotlin.coroutines.experimental.CoroutineContext
suspend fun <T, R> Iterable<T>.pmap(context: CoroutineContext, transform: suspend (T) -> R): List<R> {
return this.map {
async(context) {
transform(it)
}
}.map { it.await() }
}
@kovagoz
kovagoz / Dockerfile
Created September 2, 2016 05:03
Alpine Linux with PHP 5.6 FPM and Mongo module
FROM php:5.6-fpm-alpine
RUN apk update && apk add autoconf openssl-dev g++ make && \
pecl install mongo && \
docker-php-ext-enable mongo && \
apk del --purge autoconf openssl-dev g++ make
<?php
$ytdlPath = '/whereever/your/youtube-dl'; //change this
ob_start();
$url = trim(rawurldecode($_SERVER['QUERY_STRING']));
$qStr = parse_url($url, PHP_URL_QUERY );
parse_str($qStr, $get);
if (!isset($get['v']) || !preg_match('~[a-zA-Z0-9_-]{11}~',$get['v']) ) {
@bradrydzewski
bradrydzewski / generate_docker_cert.sh
Last active March 12, 2024 17:00
Generate trusted CA certificates for running Docker with HTTPS
#!/bin/bash
#
# Generates client and server certificates used to enable HTTPS
# remote authentication to a Docker daemon.
#
# See http://docs.docker.com/articles/https/
#
# To start the Docker Daemon:
#
# sudo docker -d \
@morhekil
morhekil / nginx.conf
Created August 14, 2014 12:18
Full request/response body logging in nginx
http {
log_format bodylog '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent" $request_time '
'<"$request_body" >"$resp_body"';
lua_need_request_body on;
set $resp_body "";
body_filter_by_lua '
@digulla
digulla / AnnotatedBeanLocator.java
Last active March 20, 2019 02:38
Locate beans in an ApplicationContext by annotation on the method which defines the bean.
import java.lang.annotation.Annotation;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.type.StandardMethodMetadata;
import com.google.common.base.Preconditions;
import com.google.common.base.Predicate;
@MohamedAlaa
MohamedAlaa / tmux-cheatsheet.markdown
Last active May 11, 2024 07:10
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@harlanji
harlanji / Demo.java
Created August 29, 2011 23:42
Best way to add custom converters to spring-data-mongodb?
MongoTemplate mongo = ...;
List<Converter> converters = new ArrayList<Converter>();
converters.add(new Converter<DBObject, Participant>() {
public Participant convert(DBObject s) {
throw new UnsupportedOperationException("Not supported yet 1.");
}
});
converters.add(new Converter<Participant, DBObject>() {