Skip to content

Instantly share code, notes, and snippets.

View johanneslumpe's full-sized avatar

Johannes Lumpe johanneslumpe

View GitHub Profile
@johanneslumpe
johanneslumpe / gist:3cdb000b5f2816a70041c1306edc97f4
Created May 10, 2016 07:57
Selecting a consecutive entity range in draft-js
const maybeSelectConsecutiveEntity = editorState => {
const selection = editorState.getSelection();
if (!selection.isCollapsed()) {
return editorState;
}
const startKey = selection.getStartKey();
const startOffset = selection.getStartOffset();
const prevOffset = startOffset - 1;
@johanneslumpe
johanneslumpe / callModifierForSelectedBlocks.js
Last active February 23, 2022 13:54
Draft.js utilities to inspect/modify selected block ranges
import { EditorState, SelectionState } from 'draft-js';
import getSelectedBlocks from './getSelectedBlocks';
/**
* Calls a provided `modifier` function with a selection for each
* selected block in the current editor selection. Passes through additional
* arguments to the modifier.
*
* Note: At the moment it will retain the original selection and override
@johanneslumpe
johanneslumpe / gulpfile.js
Created October 14, 2015 13:57 — forked from cgmartin/gulpfile.js
Node ES6 istanbul, isparta, mocha-co gulpfile example
'use strict';
var gulp = require('gulp');
var del = require('del');
var mocha = require('gulp-mocha-co');
var istanbul = require('gulp-istanbul');
var isparta = require('isparta');
var coverageEnforcer = require('gulp-istanbul-enforcer');
var paths = {
server: {
@johanneslumpe
johanneslumpe / 0_example.js
Last active November 3, 2015 18:23 — forked from tappleby/0_example.js
redux request middleware using superagent and es6 promises.
import { createStore, applyMiddleware, compose } from 'redux';
import request from 'superagent-es6-promise';
import thunkMiddlware from 'redux-thunk';
import promiseMiddleware from 'redux-promise';
import logMiddleware from './middleware/log';
import requestMiddleware from './middleware/request';
// Create request middleware with our execute logic, return promise.
const executeRequestMiddleware = requestMiddleware((req, getState) => {
const { session: { token } } = getState();
@johanneslumpe
johanneslumpe / .js
Created July 27, 2015 16:51
pinch zoom gesture
// utils/calculateMiddlePoint.js
export default (touchA, touchB) => {
const diffX = touchA.pageX - touchB.pageX;
const diffY = touchA.pageY - touchB.pageY;
return Math.sqrt(Math.pow(diffX, 2) + Math.pow(diffY, 2));
};
// utils/calculateDistance.js
@johanneslumpe
johanneslumpe / gist:e6e6e2152b96663db4a9
Created April 29, 2015 15:46
React native tabbar rotation bug demo
'use strict';
var React = require('react-native');
var {
AppRegistry,
Component,
StyleSheet,
NavigatorIOS,
TabBarIOS,
@johanneslumpe
johanneslumpe / gist:e48acd0a820bb322790b
Created April 15, 2015 14:35
Get react-native view dimensions
var UIManager = require('NativeModules').UIManager;
// in your component, use whatever ref you have defined on the
// view you want to measure
UIManager.measure(this.refs.view.getNodeHandle(), (frameX, frameX, frameWidth, frameHeight, pageX, pageY) => {
// do something with the measured values
});
Joi.object().required().keys({
referenceParentId : Joi.number().integer().when('isReference', {is: true, then: Joi.required(), otherwise: Joi.forbidden()}),
isReference : Joi.boolean().required()
});
CREATE OR REPLACE FUNCTION public.json_append(data json, insert_data json)
RETURNS json
LANGUAGE sql
AS $$
SELECT ('{'||string_agg(to_json(key)||':'||value, ',')||'}')::json
FROM (
SELECT * FROM json_each(data)
UNION ALL
SELECT * FROM json_each(insert_data)
) t;
var Backbone = require('backbone');
var _ = require('lodash');
// extend `Backbone.AssociatedModel` with a create method, which will be
// used to create new models for us, instead of using `new`
// shamelessly inspired by Supermodel
var Cached = Backbone.AssociatedModel.extend({
_cached: false,
_ref: 0,
ref: function () {