Skip to content

Instantly share code, notes, and snippets.

@predic8
predic8 / splat.js
Created November 19, 2013 18:38
Takes a function with a parameter list and returns a function that takes an array contatning the parameters.
function splat(fn) {
return function(array) {
return fn.apply(null, array);
};
}
var power = splat(Math.pow);
console.log( power([2,8]));
@predic8
predic8 / wrap-demo.js
Last active December 28, 2015 19:29
Sample for underscore.js's wrap function node wrap-demo.js
var _ = require('underscore');
var niceAlert = _.wrap( console.log, function() {
var args = _.toArray(arguments);
var fn = _.first(args);
var rest = _.rest(args);
rest = _.map(rest, function(s) {
if (s === 'f*ck') s = 'Well';
return s;
<?xml version="1.0" encoding="UTF-8"?>
<blueprint
xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
<camelContext xmlns="http://camel.apache.org/schema/blueprint">
<route>
<from uri="file:in" />
'use strict';
const Hapi = require('hapi');
const server = new Hapi.Server();
server.connection({
host: 'localhost',
port: 8000
});
@predic8
predic8 / books.json
Last active September 17, 2017 19:39
{
"e746eec0-9bde-11e7-b0a1-194366ce7859" : {
"id": "e746eec0-9bde-11e7-b0a1-194366ce7859",
"title" : "Moby-Dick",
"author" : "Herman Melville",
"year" : 1851
},
"f1817e50-9bde-11e7-b0a1-194366ce7859" : {
"id": "f1817e50-9bde-11e7-b0a1-194366ce7859",
"title" : "Vingt mille lieues sous les mers",
INSERT INTO joke (joke) VALUES ('Jon Skeet does not have performance bottlenecks. He just makes the universe wait its turn.')
INSERT INTO joke (joke) VALUES ('Users do not mark Jon Skeets answers as accepted. The universe accepts them out of a sense of truth and justice.')
INSERT INTO joke (joke) VALUES ('Jon Skeet coded his last project entirely in Microsoft Paint, just for the challenge.')
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Getting Started: Serving Web Content</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link href="webjars/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" media="screen"/>
</head>
<body>
<div class="container">
<h1>The Jokes</h1>
@predic8
predic8 / WebConfig.java
Created February 7, 2018 14:45
WebFlux Config
package de.predic8.reactiveweb;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.config.EnableWebFlux;
import org.springframework.web.reactive.config.WebFluxConfigurer;
import org.springframework.web.reactive.function.server.RequestPredicates;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;
import org.springframework.web.reactive.function.server.ServerResponse;
@predic8
predic8 / main.txt
Created February 7, 2018 14:49
WebFlux main with Netty
public static void main(String[] args) {
ApplicationContext ctx = SpringApplication.run(ReactiveWebApplication.class, args);
HttpHandler handler = WebHttpHandlerBuilder.applicationContext(ctx).build();
ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler);
HttpServer.create("localhost", 8080).newHandler(adapter).block();
}
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:spring="http://camel.apache.org/schema/spring"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd">
<spring:camelContext>