Skip to content

Instantly share code, notes, and snippets.

import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Map;
import java.util.function.BiConsumer;
public class EntryList<K,V> extends ArrayList<Map.Entry<K,V>> {
public boolean add(K key, V value) {
return this.add(new AbstractMap.SimpleEntry<>(key, value));
}
When did this:
Optional.ofNullable(value)
.map(MyType::getProp)
.map(x -> x.equals(MyEnum.VALUE))
.orElse(Boolean.FALSE)
get sexier than this:
value != null && MyEnum.VALUE.equals(value.getProp())
; Display the the byte in A as two hex digits at the current
; screen position
;
; Inputs:
; A byte to display
;
; Destroys A
display_hex:
pha
lsr
import (
"net/http"
)
func firstOrDefault(r *http.Request, key string, defaultValue string) string {
first := r.Header.Get(key)
if first != "" {
return first
}
return defaultValue
package main
import (
"net/http"
"fmt"
"io/ioutil"
"math/rand"
)
var letters = []byte("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
@adamv
adamv / maven-nexus.py
Created November 18, 2010 17:11
Uploading to Nexus using Maven from the command line (in Python). Requires Maven and Curl.
def local2(command, print_command=False):
"Run a command, returning the exit code, output, and stderr."
from subprocess import Popen, PIPE
p = Popen(command, stdout=PIPE, stderr=PIPE)
if print_command: print " ".join(command)
output, errput = p.communicate()
return p.returncode, output, errput
Process: CoQ [33933]
Path: /Users/USER/Library/Application Support/Steam/*/CoQ.app/Contents/MacOS/CoQ
Identifier: unity.Freehold Games.CavesOfQud
Version: 2.0.1 (0)
Code Type: X86 (Native)
Parent Process: ??? [1]
Responsible: CoQ [33933]
User ID: 501
Date/Time: 2017-04-22 14:01:07.053 -0700
class Stuff {
void method() {
/*.. in a catch block ..*/
throw translate(ex);
}
@SuppressWarnings("UnusedReturnValue")
private static RuntimeException translate(Exception ex)
throws SomeCheckedException, SomeOtherException {
if (ex instanceof SomeException) {
@adamv
adamv / watch_log.sh
Created November 4, 2010 22:35
Colorize access_log
#!/bin/bash
# Escaped color codes
BLACK=`echo -e '\033[0;30m'`
DK_GREY=`echo -e '\033[1;30m'`
RED=`echo -e '\033[0;31m'`
PINK=`echo -e '\033[1;31m'`
GREEN=`echo -e '\033[0;32m'`
LT_GREEN=`echo -e '\033[1;32m'`
BROWN=`echo -e '\033[0;33m'`
package codenotes;
public class Main {
public static void main(String[] args) {
Result r = new Result(Result.FIRST_NAME_FLAG|Result.LAST_NAME_FLAG|Result.ADDRESS_FLAG);
Result.Match m1 = Result.Match.atLeast().firstName().lastName();
System.out.println(r.matches(m1)); // true
Result.Match m2 = Result.Match.exactly().firstName().lastName().address();