Skip to content

Instantly share code, notes, and snippets.

Avatar
👠

Robin Grass hejrobin

👠
View GitHub Profile
View tjena-macarena.sql
INSERT INTO `chapter` (`name`) VALUES ('Tjena');
SET @chapter_id = LAST_INSERT_ID();
INSERT INTO `user` (`email`) VALUES ('en-unik-epost@tjena.com');
SET @user_id = LAST_INSERT_ID();
INSERT INTO `membership` (`chapter_id`, `user_id`) VALUES (@chapter_id, @user_id);
--- repeat
@hejrobin
hejrobin / useEventListener.js
Created Feb 26, 2020
Commonly used React Hooks
View useEventListener.js
import { useRef, useEffect } from 'react';
const useEventListener = (
eventName,
eventCallback,
eventTarget = window,
eventParams = null
) => {
const savedCallback = useRef();
View dissect.js
/* @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 ) ) {
View zlatanify.js
export function zlatanify( string ) {
return string
.replace(/s/g, 'z')
.replace(/S/g, 'Z')
.replace(/ß/g, 'zz');
}
View widget.js
(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
ES6 Component for conditional render contexts.
View rendercontext.js
/* @flow */
/**
* @type ComponentProperties
*/
type ComponentProperties = { [ key : any ] : any }
/**
* @type ComponentNodeTree
*/
View enum-annotations.js
/* @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 Jan 27, 2017
Common ES7 modules I use for a simple Flux architecture.
View EventEmitter.es7.js
/**
* @const int EVENT_MIN_LISTENERS
*/
const EVENT_MIN_LISTENERS = 1;
/**
* @const int EVENT_MAX_LISTENERS
*/
const EVENT_MAX_LISTENERS = 10;
View Object.omit.js
/**
* Object.omit
*
* Returns a (shallow) copy of an object, with specified keys omitted.
*
* @param object sourceObject
* @param string omitKeys, ...
*
* @return object
*/
View restful-es7-class.js
class RestfulController {
static validRequestMethods = [
'get', 'post', 'put', 'patch', 'delete'
];
constructor() {
let implementedRequestMethods = [];
if(new.target === RestfulController) {