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 / 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 / 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],
@ghengeveld
ghengeveld / getClassName.js
Created September 22, 2015 13:07
Get object constructor name (class name) in IE
let getClassName = obj => {
if (obj.constructor.name) {
return obj.constructor.name;
}
const regex = new RegExp(/^\s*function\s*(\S*)\s*\(/);
getClassName = obj => obj.constructor.toString().match(regex)[1];
return getClassName(obj);
};
@ghengeveld
ghengeveld / gist:72de564987d438db423b
Last active August 29, 2015 14:17
SPF record voor rt-opderails.nl

De TXT record voor rt-opderails.nl moet worden:

"v=spf1 a mx ip4:195.211.72.0/22 ip4:141.138.168.0/21 ip6:2a03:3c00:a001::/48 include:spf.factuursturen.nl ~all"

Uiteraard kan de bestaande TXT record worden verwijderd.

@ghengeveld
ghengeveld / qPromiseTransformDecorator.js
Last active August 29, 2015 13:56
Decorator to add 'transform' and 'transformError' methods to $q promise chain.
/**
* Decorator to add 'transform' and 'transformError' methods to promises.
* These can manipulate the result without catching errors so the 'then'
* functions will still work as expected.
*/
$provide.decorator('$q', function($delegate) {
var defer = $delegate.defer;
$delegate.defer = function() {
var deferred = defer();
deferred.promise.transform = function(fn) {
@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>