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));
}
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")
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
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) {
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();
package codenotes.model;
import javax.annotation.Nullable;
public class Data {
private String name;
public Data(@Nullable String name) {
this.name = name;
}
@adamv
adamv / cmus
Last active May 20, 2016 15:42
#!/bin/bash
# kill the media key program on exit
trap 'kill $(jobs -p)' EXIT
# prevent iTunes from capturing media keys
launchctl unload -w /System/Library/LaunchAgents/com.apple.rcd.plist 2>/dev/null
# launch the media key program in the background
(cmus-media-keys) &