Skip to content

Instantly share code, notes, and snippets.

View hejrobin's full-sized avatar
👠

Robin Grass hejrobin

👠
View GitHub Profile
INSERT INTO `chapter` (`name`) VALUES ('Tjena');
SET @chapter_id = LAST_INSERT_ID();
INSERT INTO `user` (`email`) VALUES ('[email protected]');
SET @user_id = LAST_INSERT_ID();
INSERT INTO `membership` (`chapter_id`, `user_id`) VALUES (@chapter_id, @user_id);
--- repeat
@hejrobin
hejrobin / useEventListener.js
Created February 26, 2020 11:05
Commonly used React Hooks
import { useRef, useEffect } from 'react';
const useEventListener = (
eventName,
eventCallback,
eventTarget = window,
eventParams = null
) => {
const savedCallback = useRef();
/* @flow */
/* @type-dependencies */
import type MixedObjectType from './generics';
export default function dissect( sourceObject : MixedObjectType, ...dissectKeys : Array<string> ) : [ MixedObjectType, MixedObjectType ] {
const remainingObject : MixedObjectType = {};
const dissectedObject : MixedObjectType = {};
for ( const [ key, value ] of Object.entries( sourceObject ) ) {
export function zlatanify( string ) {
return string
.replace(/s/g, 'z')
.replace(/S/g, 'Z')
.replace(/ß/g, 'zz');
}
(function( global ) {
var scriptRootNode;
var scriptNamespace = 'embed';
var scriptNameRegex = /.*embed.js/;
var scriptPath = 'https://domain.tld/widget-app.js';
var stylePath = 'https://domain.tld/widget-app.css';
if ( ! global[ scriptNamespace ] )
global[ scriptNamespace ] = {};
@hejrobin
hejrobin / rendercontext.js
Created May 16, 2017 11:57
ES6 Component for conditional render contexts.
/* @flow */
/**
* @type ComponentProperties
*/
type ComponentProperties = { [ key : any ] : any }
/**
* @type ComponentNodeTree
*/
/* @flow */
// The following three lines are from https://gist.github.com/nmn/b20a92e848c68d88f7fdb8353c71b1ca
type $Object<V> = { +[ key : string] : V }
type $ObjectValues<V, O : $Object<V>> = V
type $Values<O: Object> = $ObjectValues<*, O>
type Enumerables = { [ key : string ] : any }
const UserRoles : Enumerables = {
@hejrobin
hejrobin / EventEmitter.es7.js
Last active January 27, 2017 14:43
Common ES7 modules I use for a simple Flux architecture.
/**
* @const int EVENT_MIN_LISTENERS
*/
const EVENT_MIN_LISTENERS = 1;
/**
* @const int EVENT_MAX_LISTENERS
*/
const EVENT_MAX_LISTENERS = 10;
/**
* Object.omit
*
* Returns a (shallow) copy of an object, with specified keys omitted.
*
* @param object sourceObject
* @param string omitKeys, ...
*
* @return object
*/
class RestfulController {
static validRequestMethods = [
'get', 'post', 'put', 'patch', 'delete'
];
constructor() {
let implementedRequestMethods = [];
if(new.target === RestfulController) {