Skip to content

Instantly share code, notes, and snippets.

View ghengeveld's full-sized avatar

Gert Hengeveld ghengeveld

View GitHub Profile
@ghengeveld
ghengeveld / accordion.js
Created February 1, 2018 20:47
React Accordion
class Accordion extends React.Component {
constructor(props) {
super(props)
this.state = {
activeItem: null,
}
}
toggle = (event, index) => this.setState(state => ({ activeItem: state.activeItem === index ? null : index }))
render() {
return (
@ghengeveld
ghengeveld / select-all.js
Last active February 15, 2017 10:34
AngularJS Select All directive
/**
* Directive to instantly enable/disable multiple checkboxes based on a master checkbox.
* Changing slave checkboxes will update the master checkbox accordingly, including the indeterminate state.
*
* Usage example:
*
* <label><input type="checkbox" select-all="theProperties"> Select all</label>
* <div ng-repeat="property in properties">
* <label><input type="checkbox" rel="theProperties" ng-model="property.checked"> {{ property.label }}</label>
* </div>
@ghengeveld
ghengeveld / products.json
Created August 16, 2016 13:22
Demo products
{
"products": [
{
"id": 448082,
"title": "GoPro HERO4 Silver",
"price": 36900,
"description": "De GoPro HERO4 Silver is een waardige opvolger van GoPro 3-serie.",
"thumbnail": "https://image.coolblue.io/products/448082?width=200&height=200"
},
{
@ghengeveld
ghengeveld / implicitly_passing_props.js
Created July 22, 2016 09:05
Implicitly passing props
function App(props) {
return <Header title="Fancy" />;
}
function Header(props) {
return <Title {...props} />;
}
function Title(props) {
return <div>{props.title}</div>;
@ghengeveld
ghengeveld / asyncActionSpec.js
Created June 20, 2016 09:50
How to test an async action (by monkeypatching the dispatch function)
/* async-action.js */
import SomeService from './some-service';
export function doAsync(arg) {
return dispatch => {
// SomeService.doSomething returns a promise which resolves to the passed argument
SomeService.doSomething(arg).then(result => {
const action = { type: 'ASYNC_SUCCESS', payload: result };
dispatch(action);
}).catch(error => {
@ghengeveld
ghengeveld / parseNumeric
Created October 8, 2013 12:24
Helper function, parses numeric input also ending with %
/**
* parseNumeric('123') === 123
* parseNumeric('10 abc') === undefined
* parseNumeric('10.10%') === 10.1
* parseNumeric(' 10.1000 ') === 10.1
* parseNumeric('10. 01%' ) === undefined
* parseNumeric('10.0 %') === 10
*/
function parseNumeric(number) {
var num = ('' + number).trim();
@ghengeveld
ghengeveld / angular-ui-router-dynamic-template.js
Created October 2, 2013 12:04
Dynamic templateUrl for Angular UI Router
$stateProvider.state('projects.edit.section', {
url: '/:sectionCode',
templateUrl: function(stateParams) {
return 'partials/project/' + stateParams.sectionCode + '.html';
}
});
@ghengeveld
ghengeveld / nametrainer.js
Created October 27, 2015 08:33 — forked from raboof/nametrainer.js
Poor man's Xebia name-trainer
/*
* Usage:
* - open https://updates.xebia.com/smoelenboek/
* - paste this file into chrome developer tools js console
* - look at the picture in the top-left corner and choose from the names in the js console
*/
images = jQuery('dt.portrait img')
answer = [ , , , ]
function embed(data, sizes) {
const formattedData = {};
for (let uuid in sizes) {
if (sizes.hasOwnProperty(uuid) && data[uuid]) {
formattedData[uuid] = {
name: uuid,
w: sizes[uuid].width,
h: sizes[uuid].height,
vars: {
id: data[uuid],
<?php
if (!defined('SED_CODE')){die('Wrong URL.'); }
$currenttpl = file_get_contents($mskin);
if (mb_strpos($currenttpl, "{PAGE_TEXT_ID_") !== false)
{
$matches = array();
preg_match_all("#{(?P<tag>PAGE_TEXT_ID_(?P<id>[0-9]+))}#", $currenttpl, $matches, PREG_SET_ORDER);
foreach ($matches as $match){
$p_tag = $match['tag'];