Skip to content

Instantly share code, notes, and snippets.

View m0wfo's full-sized avatar

Chris Mowforth m0wfo

  • Planet Earth
View GitHub Profile
@m0wfo
m0wfo / gist:940422
Created April 25, 2011 12:10
Prüfer Sequence algorithm
(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.
public PoorStripperImpl implements IStripper {
@Override
public String stripThing(String originalString) {
return originalString == null ? "???" : originalString.substring(0, 8);
}
}
public interface IStripper {
String stripThing(String originalThing);
}
public GoodStripperImpl implements IStripper {
@Override
public String stripThing(String originalString) {
return originalString.substring(0, 8);
}
}
try {
client.makeCall(someArgument);
} catch (IOException e) {
log.error("Oh bumcakes", e);
return null;
}
// or even more obnoxious
try {
client.makeCall(someArgument);
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);
ImmutableMap<String, String> foo = ...
// take foo, add 'new' => 'kvp'
ImmutableMap<String, String> bar = ImmutableMap
.builder()
.addAll(foo)
.put("new", "kvp")
.build();
var shoppingCart = {
"apples": 2,
"oranges": 3
};
shoppingCart.sh_t = "bananas";
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()
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()