Skip to content

Instantly share code, notes, and snippets.

View sanderploegsma's full-sized avatar
💭
I may be slow to respond.

Sander Ploegsma sanderploegsma

💭
I may be slow to respond.
View GitHub Profile
function fish_prompt
set last_status $status
if test $last_status -eq 0
set_color green
else
set_color red
end
echo -n '=> '
set_color normal
const path = require("path");
const pageTemplate = path.resolve("gatsby-page-template.js");
const pagesQuery = `
query Pages($language: String!) {
wordpress(language: $language) {
pages {
nodes {
id
slug
exports.plugins = [
{
resolve: `gatsby-source-graphql`,
options: {
typeName: `WordPressNL`,
fieldName: `wordpressNL`,
url: `example.com/graphql`
}
},
{
#!/bin/sh
CLUSTER_CONFIG="/data/nodes.conf"
if [ -f ${CLUSTER_CONFIG} ]; then
if [ -z "${POD_IP}" ]; then
echo "Unable to determine Pod IP address!"
exit 1
fi
echo "Updating my IP to ${POD_IP} in ${CLUSTER_CONFIG}"
sed -i.bak -e '/myself/ s/[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}/${POD_IP}/' ${CLUSTER_CONFIG}
fi
class PCollectionUtilsTest {
@get:Rule
private val pipeline : TestPipeline = TestPipeline.create()
@Test
fun `PCollection - filter should correctly filter items`() {
val input = pipeline.apply(Create.of(1, 2, 3, 4, 5))
val output = input.filter { it > 3 }
inline fun <T> PCollection<T>.filter(name: String = "Filter", crossinline predicate: (T) -> Boolean): PCollection<T>
= this.apply(name, Filter.by(SerializableFunction<T, Boolean> { predicate(it) }))
inline fun <T, R> PCollection<T>.map(name: String = "Map", crossinline apply: (T) -> R): PCollection<R>
= this.apply(name, MapElements.into(object : TypeDescriptor<R>(){}).via({ apply(it) }))
class BeamExamples2 {
public fun process(input: PCollection<Person>): PCollection<String> {
return input.filter("Filter by age") { it.age >= 18 }
.map("Map to first name") { it.firstName }
}
}
class BeamExamples {
public fun filterByAge(input: PCollection<Person>, age: Int)
= input.apply("Filter by age", Filter.by(SerializableFunction<Person, Boolean> { it.age >= age })
}
@sanderploegsma
sanderploegsma / BeamExamples.java
Last active October 9, 2019 13:14
Apache Beam + Kotlin examples
class BeamExamples {
public PCollection<Person> filterByAge(PCollection<Person> input, int age) {
return input.apply("Filter by age", Filter.by(p -> p.getAge() >= age));
}
}