Skip to content

Instantly share code, notes, and snippets.

View Klaasvaak's full-sized avatar

Joep van der Heijden Klaasvaak

View GitHub Profile
@Klaasvaak
Klaasvaak / suggestions.js
Created January 14, 2018 14:30
Base suggestions code with RxJS
const cities = ['rome', 'madrid', 'paris', 'brussels', 'eindhoven', 'berlin', 'copenhagen', 'stockholm'];
const myAwesomeSearch = value => cities.filter(city => city.indexOf(value) !== -1);
const input = document.querySelector('input');
const suggestions = document.querySelector('#suggestions');
Rx.Observable.fromEvent(input, 'keyup')
.pluck('target', 'value')
.map(value => myAwesomeSearch(value))
.map(cities => cities.map(city => `<li>${city}</li>`).join(''))
@Klaasvaak
Klaasvaak / gist:dba6e72bf03e62de06ea
Created February 2, 2015 13:28
MySQL JSON search
Instead of using regexp like so:
ancestors column would be something like: {"category": 1}
WHERE `ancestors` REGEXP '(.*\"category\":\"1\")'
Use the JSON functions:
WHERE JSON_EXTRACT(`ancestors`, 'category') = 1
Arrays:
WHERE JSON_SEARCH(JSON_EXTRACT('{"categories": [1,2,3]}', 'categories'), "1") != null