Skip to content

Instantly share code, notes, and snippets.

View steve-taylor's full-sized avatar

Steve Taylor steve-taylor

  • Sydney, Australia
View GitHub Profile
@steve-taylor
steve-taylor / react-bacon-connect.html
Created September 1, 2017 05:29
Example of connecting a React component to Bacon streams and buses
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>bacon.js and baconjs-router POC</title>
<script src="https://unpkg.com/babel-standalone@6.15.0/babel.min.js"></script>
<script src="https://unpkg.com/react@latest/dist/react.js"></script>
<script src="https://unpkg.com/react-dom@latest/dist/react-dom.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bacon.js/0.7.95/Bacon.js"></script>
</head>
@steve-taylor
steve-taylor / react-bacon.js
Last active October 27, 2021 11:03
Connect a React component to Bacon.js streams and buses
import React from 'react';
import Bacon from 'baconjs';
/**
* Create a factory of higher order components that render the specified inner
* component using the specified mapping of property names to the streams that
* feed them values and the specified mapping of callback property names to
* the buses onto which the callbacks' first parameter is pushed when called.
*
* This is similar in concept to react-redux's connect() function, but for
@steve-taylor
steve-taylor / react-bacon-page.html
Last active August 29, 2017 06:16
Routing to React pages using Page.js
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>React + Bacon.js + Page.js</title>
<script src="https://unpkg.com/babel-standalone@6.15.0/babel.min.js"></script>
<script src="https://unpkg.com/react@latest/dist/react.js"></script>
<script src="https://unpkg.com/react-dom@latest/dist/react-dom.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bacon.js/0.7.95/Bacon.min.js"></script>
<script src="https://cdn.rawgit.com/visionmedia/page.js/master/page.js"></script>
@steve-taylor
steve-taylor / react-bacon-router-test.html
Last active August 29, 2017 02:36
Failed attempt at using Bacon.js and Bacon.js Router
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>bacon.js and baconjs-router POC</title>
<script src="https://unpkg.com/babel-standalone@6.15.0/babel.min.js"></script>
<script src="https://unpkg.com/react@latest/dist/react.js"></script>
<script src="https://unpkg.com/react-dom@latest/dist/react-dom.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bacon.js/0.7.95/Bacon.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.min.js"></script>
/**
* <p>Create a function that can generate BEM classes based on the specified block.</p>
* <p>Suppose you have the following code:</p>
* <pre>
* const bem = bemFor('my-block');
* </pre>
* Then:
* <ul>
* <li><code>bem()</code> will return <code>"my-block"</code></li>
* <li><code>bem('my-element')</code> will return <code>"my-block__my-element"</code></li>
class MyComponent extends React.Component {
static propTypes = {
photoUrl: PropTypes.string,
initialButtonVisible: PropTypes.bool
};
static defaultProps = {
photoUrl: '',
initialButtonVisible: true
};
class MyComponent extends React.Component {
constructor(props) {
this.state = {
photoVisible: this.props.initialPhotoVisible
};
this.togglePhotoVisible = this.togglePhotoVisible.bind(this);
}
togglePhotoVisible() {
create table budget_category
(
id bigserial,
name text not null,
constraint pk_budget_category primary key (id)
);
create table financial_source
(
id bigserial,
@steve-taylor
steve-taylor / postgres-times-json.sql
Last active December 23, 2015 16:19
PostgreSQL JSON generation example: Generating an array of time arrays, where each outer array element represent a date and each inner element represents a time on the date represented by its parent element. This is useful for generating compact JSON if the returned date range is known. (The date range can easily be known as it is user specified…
with
a as (select * from generate_series(0, 6) s), -- 6 is user specified number of days - 1
b as (select ('2013-03-01'::date + s * interval '1 day')::date appt_date from a), -- 2013-03-01 is user specified start date
c as (select * from generate_series('2013-03-02 00:00'::timestamp without time zone, '2013-03-05 23:59'::timestamp without time zone, '10 minutes') appt), -- Dummy data - appointment times
d as (select appt::date appt_date, to_char(appt, 'HH24:MI') appt_time from c), -- Split out the date and time
e as (select appt_date, json_agg(appt_time order by appt_time) times from d group by appt_date), -- Aggregate times into an array per day
f as (select appt_date, coalesce(times, '[]'::json) times from b left join e using (appt_date)) -- Left join onto the generated date series to produce an array for all days including empty ones
select json_agg(times order by appt_date) from f -- Aggregate the result into a single array of arrays
@steve-taylor
steve-taylor / OpenJPA in OSGi.md
Last active December 17, 2015 13:39
This is intended primarily as a brief explanation for devs working with an existing Java codebase that uses OpenJPA within an OSGi environment. It should help you figure out how the pieces fit together. Essentially there are three types of components: 1. An OSGi component in any bundle that exports itself as a javax.sql.DataSource to OSGi using …

OpenJPA in OSGi

  1. Create a data source and export it as a JNDI service.

    Java:

    @Component(service=javax.sql.DataSource.class, property="osgi.jndi.service.name=jdbc/myDataSource")
    public class MyDataSource extends SomeDbVendorDataSourceImpl implements javax.sql.DataSource {
    	// ...