Skip to content

Instantly share code, notes, and snippets.

View Klaasvaak's full-sized avatar

Joep van der Heijden Klaasvaak

View GitHub Profile
Klaasvaak / suggestions.js
Created January 14, 2018 14:30
Base suggestions code with RxJS
View suggestions.js
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 => => `<li>${city}</li>`).join(''))
Klaasvaak / gist:dba6e72bf03e62de06ea
Created February 2, 2015 13:28
MySQL JSON search
View gist:dba6e72bf03e62de06ea
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
WHERE JSON_SEARCH(JSON_EXTRACT('{"categories": [1,2,3]}', 'categories'), "1") != null