Tutorial by Examples: al

// Java: List<String> namesOfMaleMembersCollect = roster .stream() .filter(p -> p.getGender() == Person.Sex.MALE) .map(p -> p.getName()) .collect(Collectors.toList()); // Kotlin: val namesOfMaleMembers = roster.filter { it.gender == Person.Sex.MALE }.map { it.nam...
// Java: List<String> filtered = items.stream() .filter( item -> item.startsWith("o") ) .collect(Collectors.toList()); // Kotlin: val filtered = items.filter { item.startsWith('o') }
// Java: String shortest = items.stream() .min(Comparator.comparing(item -> item.length())) .get(); // Kotlin: val shortest = items.minBy { it.length }
// Java: Arrays.stream(new int[] {1, 2, 3}) .map(n -> 2 * n + 1) .average() .ifPresent(System.out::println); // 5.0 // Kotlin: arrayOf(1,2,3).map { 2 * it + 1}.average().apply(::println)
// Java: Stream.of("a1", "a2", "a3") .map(s -> s.substring(1)) .mapToInt(Integer::parseInt) .max() .ifPresent(System.out::println); // 3 // Kotlin: sequenceOf("a1", "a2", "a3") .map { it.substring(1) } ...
// Java: IntStream.range(1, 4) .mapToObj(i -> "a" + i) .forEach(System.out::println); // a1 // a2 // a3 // Kotlin: (inclusive range) (1..3).map { "a$it" }.forEach(::println)
// Java: long count = items.stream().filter( item -> item.startsWith("t")).count(); // Kotlin: val count = items.filter { it.startsWith('t') }.size // but better to not filter, but count with a predicate val count = items.count { it.startsWith('t') }
// Java: List<String> myList = Arrays.asList("a1", "a2", "b1", "c2", "c1"); myList.stream() .filter(s -> s.startsWith("c")) .map(String::toUpperCase) .sorted() .forEach(System.out::println); // C1 ...
// Java: String phrase = persons .stream() .filter(p -> p.age >= 18) .map(p -> p.name) .collect(Collectors.joining(" and ", "In Germany ", " are of legal age.")); System.out.println(phrase); // In Germany Max and Peter a...
<link rel="stylesheet" href="path/to.css" type="text/css"> The standard practice is to place CSS <link> tags inside the <head> tag at the top of your HTML. This way the CSS will be loaded first and will apply to your page as it is loading, rather th...
Creating ***bold italic*** text is simply a matter of using both **bold** (two asterisks) and *italic* (one asterisk) at the same time, for a total of three asterisks on either side of the text you want to format at once. Creating bold italic text is simply a matter of using both bold (two a...
Have you ever forgotten to add a trap to clean up a temporary file or do other work at exit? Have you ever set one trap which canceled another? This code makes it easy to add things to be done on exit one item at a time, rather than having one large trap statement somewhere in your code, which may...
Template Definition template linux.bonding { subject = {{.Last.Status}}: {{.Eval .Alert.Vars.by_host}} bad bond(s) on {{.Group.host}} body = `{{template "header" .}} <h2>Bond Status</h2> <table> <tr><th>Bond</th><th>Slave&...
Templates can be previewed and edited using the Rule Editor tab in Bosun. Use the Jump to links to select the alert you want to edit, then you can use the template button next to macro to switch between the alert an template sections of the configuration. If an alert has multiple instances you can u...
It often is faster to use a generic template when first creating a new alert and only specialize the template when you need to display more information. The following template will display a subject with a numerical value, custom formatting, and description string and then a body with up to two grap...
Using .Graph will filter the results to only include those that match the tagset for the alert. For instance an alert for os.low.memory{host=ny-web01} would only include series with the host=ny-web01 tags. If multiple series match then only the first matching result will be used. template graph.tem...
Using .GraphAll will include all the results in the graph. template graph.template { subject = ... body = `{{template "header" .}} <strong>GraphAll</strong> <div>{{.GraphAll .Alert.Vars.graph}}</div> <strong>GraphAll With Y Axis...
Graph queries can be defined inline if you don't want to use an Alert variable. template graph.template { subject = ... body = `{{template "header" .}} <strong>Graph With Inline Query</strong> <div>{{.Graph "q(\"avg:300s-avg:os.mem.perce...
This uses the Dropbox Java SDK to create a shared link for a file at the Dropbox path /test.txt: try { SharedLinkMetadata sharedLinkMetadata = client.sharing().createSharedLinkWithSettings("/test.txt"); System.out.println(sharedLinkMetadata.getUrl()); } catch (CreateSharedLinkW...
Git lets you use non-git commands and full sh shell syntax in your aliases if you prefix them with !. In your ~/.gitconfig file: [alias] temp = !git add -A && git commit -m "Temp" The fact that full shell syntax is available in these prefixed aliases also means you can us...

Page 17 of 269