Skip to content

Instantly share code, notes, and snippets.

View vpryim's full-sized avatar

Vasyl Pryimachuk vpryim

View GitHub Profile

TodoMVC React

export default class Test extends React.Component {
state = this.search({
find: {
activePanel: _`?panel`,
programmingLanguage: _`?pl`
},
where: [
[':app', ':panel', _`?panel`],
[':app', ':pl', _`?pl`]
@vpryim
vpryim / index.js
Created February 21, 2017 13:31
EAV <-> JSON
// JSON
var data = {
articles: [{
title: 'article #1',
text: 'zero',
comments: [{
text: 'comment #1'
}]
}, {
title: 'article #2',
@vpryim
vpryim / index.js
Last active February 21, 2017 12:49
Logic Variables defined as inline Symbols
var name = 'John';
var query = {
find: [_`?year`, _`?month`, _`day`],
where: [
[_`?artist`, ':artist/name', name], // data clause
[_`?artist`, ':artist/startDay', _`?day`],
[_`?artist`, ':artist/startMonth', _`?month`],
[_`?artist`, ':artist/startYear', _`?year`],
[_`?year`, y => y > 2010], // expression clause, predicate
@vpryim
vpryim / index.js
Created February 20, 2017 13:57
Chain syntax for datalog query
function findArtistTracklist(db, artistName) {
var [artist, track, year, name] = createVariables();
// Query syntax is similar to the one used in d3.js
// Every function returns a new function
var allTracks = query(db)
.match([artist, ":artist/name", artistName])
.match([track, ":track/artist", artist])
.match([track, ":track/name", name])
.match([track, ":track/year", year])
@vpryim
vpryim / index.js
Created February 18, 2017 09:12
Range using generators
function* range(min, max) {
for (var i = min; i < max; i++) {
yield i;
}
}
[...range(0, 5)] // [0, 1, 2, 3, 4]
@vpryim
vpryim / index.js
Last active February 13, 2017 17:06
Deductive Database Interface for React
class App extends Component {
state = {
db: createLocalStorageDb("db")
}
onDbError = error => console.log(`DbError: `, error)
render() {
var { user } = this.props;
var { db } = this.state;
@vpryim
vpryim / ReduxComponent.js
Created October 16, 2016 09:45
ReduxComponent
const TOGGLE_PLAY = 'TOGGLE_PLAY';
const STOP = 'STOP';
class App extends ReduxComponent {
state = {
isPlaying: false,
track: 123
}
reduce(state, action) {
@vpryim
vpryim / .js
Last active September 15, 2016 12:48
WeakMap
let myMap = new WeakMap();
// We store two objects in our Weakmap
myMap.set(window, 'window');
myMap.set(document.body, 'myelement');
document.body.parentNode.removeChild(document.body);
myMap.get(document.body); // undefined
// module: YearAssesment
var _ = require('underscore');
function shouldBePromoted(assignments, minimumPassingPercentage) {
if (!minimumPassingPercentage) {
minimumPassingPercentage = 0.6;
}
return _.compose(