Skip to content

Instantly share code, notes, and snippets.

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

Michel Weststrate mweststrate

💭
I may be slow to respond.
View GitHub Profile
@mweststrate
mweststrate / impl1.java
Created July 6, 2012 13:55
xpath example java 1
private String implementation1(String name, Category category, Long offset) throws CoreException
{
StringBuilder b = new StringBuilder();
//create the xpath
String xpath =
"//Products.Product[Products.Product_ProductState/Products.ProductState[Published = true() or PublishAnyway = true()]]" +
"[Products.Product_Category = '" + category.getGUID() + "']" +
"[Name = '" + name + "']";
@mweststrate
mweststrate / xpath2.java
Created July 13, 2012 08:34
xpath example java 2
//...
//create the xpath
String xpath = String.format("//%s[%s/%s[%s = true() or %s = true()]][%s = '%s'][%s = '%s']",
Product.entityName,
Product.MemberNames.Product_ProductState, ProductState.entityName,
ProductState.MemberNames.Published, ProductState.MemberNames.PublishAnyway,
Product.MemberNames.Product_Category, category.getGUID(),
Product.MemberNames.Name, name
);
//...
@mweststrate
mweststrate / gist:3103734
Created July 13, 2012 08:49
xpath example 4
private String implementation4(String name, Category category, Long offset) throws CoreException
{
StringBuilder b = new StringBuilder();
//create the xpath
XPath<Product> xpath = XPath.create(getContext(), Product.class)
.subconstraint( Product.MemberNames.Product_ProductState , ProductState.entityName )
.eq( ProductState.MemberNames.Published , true )
.or()
.eq( ProductState.MemberNames.PublishAnyway , true )
var CartEntryView = mobxReact.observer(React.createClass({
render: function() {
return (<li>
// etc...
@mweststrate
mweststrate / gist:5c1a29ee80832f28f3be
Last active February 26, 2016 18:04
data model using mobservables
function Article(name, price) {
mobx.extendObservable(this, {
name: name,
price: price
});
}
function ShoppingCartEntry(article) {
mobx.extendObservable(this, {
article: article,
var CartView = React.createClass({
render: function() {
function renderEntry(entry) {
return (<CartEntryView entry={entry} cart={this.props.cart} key={entry.id} />);
}
return (<div>
<ul id="cart">{this.props.cart.entries.map(renderEntry)}</ul>
<div><b>Total: <span id="total">{this.props.cart.total}</span></b></div>
</div>)
}
@mweststrate
mweststrate / mobx-repl.sh
Last active February 26, 2016 18:03
install and run MobX in REPL
npm init -y && npm install mobx --save && node -e "global.mobx=require('mobx'); require('repl').start({ useGlobal: true});"
@mweststrate
mweststrate / gist:2789bd206a4e055581ab
Last active October 8, 2019 08:51
pure rendering over time using MOBservable
// The state of our app
var state = mobx.observable({
nrOfSeats : 500,
reservations : [],
seatsLeft : function() { return this.nrOfSeats - this.reservations.length; }
});
// The UI; a function that is applied to the state
var ui = mobx.computed(function() {
return "\n<div>Seats left: " + state.seatsLeft +
@mweststrate
mweststrate / gist:0d6edd6645845a9aca47
Created July 15, 2015 19:52
pure rendering over time using MOBservable - output
<div>Seats left: 500<hr/>Attendees: </div>
<div>Seats left: 499<hr/>Attendees: Michel</div>
<div>Seats left: 498<hr/>Attendees: Michel, You?</div>
<div>Seats left: 498<hr/>Attendees: @mweststrate, You?</div>
<div>Seats left: 748<hr/>Attendees: @mweststrate, You?</div>
@mweststrate
mweststrate / autorun.js
Last active February 26, 2016 17:59
Object.observe is dead. Long live Mobservable.observe
// JSBin: http://jsbin.com/xoyehi/edit?js,console
import {observable, autorun} from "mobx";
const todos = observable([{
title: "Find napkin",
completed: false
}]);
autorun(() =>
console.log(todos