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
(defn prufer | |
"Convert a labelled tree to a Prüfer Sequence." | |
([graph] (prufer graph [])) | |
([graph prufer-sequence] | |
(loop [g graph p prufer-sequence] | |
(if (> (count g) 2) ; A Prüfer sequence is always of length n - 2 | |
;v finds the lowest-valued leaf node | |
(let [v (apply min-key first (filter #(= 1 (count (last %))) g))] | |
; Remove the label's node key and occurrences in edge sets, | |
; then push its neighbour's label onto front of Prüfer sequence p. |
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 PoorStripperImpl implements IStripper { | |
@Override | |
public String stripThing(String originalString) { | |
return originalString == null ? "???" : originalString.substring(0, 8); | |
} | |
} |
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 interface IStripper { | |
String stripThing(String originalThing); | |
} |
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 GoodStripperImpl implements IStripper { | |
@Override | |
public String stripThing(String originalString) { | |
return originalString.substring(0, 8); | |
} | |
} |
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
try { | |
client.makeCall(someArgument); | |
} catch (IOException e) { | |
log.error("Oh bumcakes", e); | |
return null; | |
} | |
// or even more obnoxious | |
try { | |
client.makeCall(someArgument); |
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
try { | |
client.makeCall(someArgument); | |
} catch (IOException e) { | |
log.error("Couldn't make call!", e); | |
throw new RuntimeException(e); | |
} | |
// or if you like Guava and javac does too! | |
try { | |
client.makeCall(someArgument); |
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
ImmutableMap<String, String> foo = ... | |
// take foo, add 'new' => 'kvp' | |
ImmutableMap<String, String> bar = ImmutableMap | |
.builder() | |
.addAll(foo) | |
.put("new", "kvp") | |
.build(); |
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
var shoppingCart = { | |
"apples": 2, | |
"oranges": 3 | |
}; | |
shoppingCart.sh_t = "bananas"; |
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 setup_something(): | |
# do some kind of setup | |
return 1 | |
def finish_doing_something(arg): | |
# do something else | |
print(str(arg)) | |
def do_work(work): | |
val = setup_something() |
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 setup_something(): | |
# do some kind of setup | |
return 1 | |
def finish_doing_something(arg): | |
# do something else | |
print(str(arg)) | |
def some_method_a(): | |
a = setup_something() |
NewerOlder