Skip to content

Instantly share code, notes, and snippets.

View p14n's full-sized avatar

Dean Chapman p14n

View GitHub Profile
@p14n
p14n / gist:3963607
Created October 27, 2012 08:51
Scala maven continuous compile
<profiles>
<profile>
<id>scalac-prod</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<fsc.once>true</fsc.once>
<fsc.compilation>all</fsc.compilation>
</properties>
@p14n
p14n / gist:4143213
Created November 25, 2012 11:49
Spray with embedded Jetty
package com.example
import spray.servlet.Servlet30ConnectorServlet
import spray.servlet.Initializer
import org.eclipse.jetty.server.Server
import org.eclipse.jetty.server.bio.SocketConnector
import org.eclipse.jetty.webapp.WebAppContext
import org.eclipse.jetty.servlet.ServletContextHandler
object JettyServer {
@p14n
p14n / gist:4673436
Last active December 11, 2015 22:58
public class RemoteErrorActor extends UntypedActor {
@SuppressWarnings("rawtypes")
@Override
public void onReceive(Object o) throws Exception {
if (o instanceof RemoteClientWriteFailed) {
RemoteClientWriteFailed fail = (RemoteClientWriteFailed) o;
if (fail.getRequest() instanceof Tuple3) {
Tuple3 t3 = (Tuple3) fail.getRequest();
if (t3._2() instanceof Some) {
(ns gameapp)
(def gamemod
"Create a gameapp module within Angular.js"
(.module js/angular "gameapp" (array)))
(.directive gamemod "gameslist"
(fn []
(js-obj
"restrict" "E"
<!doctype html>
<html ng-app="gameapp">
<head>
<script src="angular.min.js"></script>
<script src="cljs-w-directive.js"></script>
</head>
<body>
<h2>Game names</h2>
<div ng-controller="gameapp.GameCtrl">
<gameslist games="mygames"/>
@p14n
p14n / payform.js
Created May 15, 2018 19:56
User input
const PayForm = ({ account, dispatch }) => (
<Form
onSubmit={submittedValues => {
dispatch({ type: "pay", payee: account, ...submittedValues });
}}
>
{formApi => (
<form onSubmit={formApi.submitForm} id="pform">
<label htmlFor="password">Password</label>
<Text field="password" id="password" />
@p14n
p14n / middleware.js
Created May 15, 2018 20:05
middleware
const contractService = store => next => action => {
switch (action.type) {
...
case "pay":
contract
.withdraw(action.password, { from: action.payee })
.catch(e => next(failed(e)));
...
default:
next(action);
@p14n
p14n / contractevents.js
Created May 15, 2018 20:09
Contract events
const eventToAction = name => (err, result) => {
store.dispatch({ type: "event", name: name, ...result.args });
};
contract.PaidEvent().watch(eventToAction("paid"));
contract.ReclaimedEvent().watch(eventToAction("reclaimed"));
contract.Instantiated().watch(eventToAction("created"));
contract.KilledStateChange().watch(eventToAction("killed"));
@p14n
p14n / reducer.js
Created May 15, 2018 20:14
Reducer
const eventAction = (state = {}, action) => {
switch (action.type) {
...
case "event":
...
switch (action.name) {
case "created":
if (state.account == action.from) {
return { ...state, events: ev, status: "reclaimable" };
} else {
@p14n
p14n / forms.js
Created May 15, 2018 20:19
Forms
export const Forms = ({ status, killed, account, dispatch }) => {
if (killed) return <KillForm />;
return (
<div>
{status ? <span /> : <CreateForm dispatch={dispatch} account={account} />}
{status == "payable" ? (
<PayForm dispatch={dispatch} account={account} />
) : (
<span />
)}