Skip to content

Instantly share code, notes, and snippets.

@mmgj
mmgj / Konami.as
Created January 1, 2010 22:20
Konami Code in ActionScript
package com.ctrloptcmd.string {
/**
* Konami.as
* Up Up Down Down Left Right Left Right B A
*
* @langversion: ActionScript 3.0
* @playerversion: Flash 9.0
*
@mmgj
mmgj / Keys.as
Created January 1, 2010 22:23
Keys.as - Facilitates working with keys in as3.
package com.ctrloptcmd.string {
/**
* Keys.as
*
* @langversion: ActionScript 3.0
* @playerversion: Flash 9.0
*
* @author: Martin Jacobsen
* @site : http://ctrloptcmd.com
@mmgj
mmgj / Download WP.txt
Created January 3, 2010 10:37
Download latest Wordpress release to current dir, unzip, move wp-install to root and remove the now superfluous "latest.zip" and empty "wordpress/".
wget http://wordpress.org/latest.zip && unzip latest.zip ; mv wordpress/* ../* ; rm -rf wordpress ; rm latest.zip ; exit
package com.ctrloptcmd.utils {
/**
* XTrace.as
*
* @langversion : ActionScript 3.0
* @playerversion : Flash 9.0
*
* @author : Martin Jacobsen
* @since : 24-03-2009
package com.ctrloptcmd.string {
/**
* Copyright 2009 Martin Jacobsen.
*
* @langversion ActionScript 3.0
* @playerversion Flash 10.0
*
* @author Martin Jacobsen
* @since 2009-02-02
@mmgj
mmgj / getShape.js
Last active June 8, 2018 20:13
Returns PropTypes.shape({}) for given object
export function getShape(object, depth = 1) {
const tab = ' ';
const prefix = tab;
let output = '{\n';
Object.keys(object).forEach((key) => {
const type = typeof (object[key]);
let desc = '';
if (type === 'function') {
desc = 'func';
@mmgj
mmgj / noment.js
Last active June 8, 2018 20:20
Simple date operations
export function isDateInRange(checkPointIn, startPointIn, endPointIn) {
if ([checkPointIn, startPointIn, endPointIn].some((point) => point === undefined)) {
console.warn('Function expects three parameters; checkPoint: Date, startPoint: Date, endPoint: Date');
return;
}
const checkPoint = new Date(checkPointIn).getTime();
const startPoint = new Date(startPointIn).getTime();
const endPoint = new Date(endPointIn).getTime();
return checkPoint > startPoint && checkPoint < endPoint;
@mmgj
mmgj / getType.js
Last active June 8, 2018 20:18
Get type for any object
export function getBaseType(input) {
return ({}).toString.call(input).match(/\s([a-zA-Z]+)/)[1];
}
export function getType(input, restricted = false) {
let output = getBaseType(input);
if (restricted) return output;
if (output.toLowerCase() === 'object') output = input.type ? input.type.name : input.constructor.name;
return output;
}
@mmgj
mmgj / art-embellish.js
Created September 22, 2018 17:02
Sanity -> Webtask.io
/**
* Cloud function triggered by changes in dataset which will generate metadata for art asset.
*/
const Promise = require('es6-promise').Promise;
const sanityClient = require('@sanity/client');
/** Setup */
const client = token => sanityClient({
projectId: '<projectId>',
/**
* This sets up a very lightweight App State based on React Context API
* with a familiar reducer / actions / dispatcher syntax, and also exposes
* this to Redux Devtools which is good and not bad.
* More info here: https://medium.com/simply/state-management-with-react-hooks-and-context-api-at-10-lines-of-code-baf6be8302c
* ...and here: https://github.com/troch/reinspect
*/
import React, { createContext, useContext } from 'react';
import { useReducer } from 'reinspect';
import PropTypes from 'prop-types';