Skip to content

Instantly share code, notes, and snippets.

@mattisfrommars
mattisfrommars / Cell.js
Created June 5, 2020 17:45
Recursive maze drawing algorithm
function Cell(i, j, w, rows, cols) {
let x, y;
this.i = i;
this.j = j;
this.w = w;
this.x = x = i * w;
this.y = y = j * w;
this.walls = [
[x, y, x + w, y], // TOP
[x + w, y, x + w, y + w], // RIGHT
function createCombinations(input, result = []) {
return multiply(input)
}
function multiply(inputArrays, result = []) {
const [input, ...rest] = inputArrays
if (!input) return result
@mattisfrommars
mattisfrommars / index.d.ts
Last active October 24, 2017 15:14 — forked from pierre-H/index.d.ts
Expo TypeScript Definitions
declare module 'expo' {
import {EventSubscription} from 'fbemitter';
import {ViewProperties, ViewStyle} from 'react-native';
/**
* Expo Accelerometer
*/
export namespace Accelerometer {
// TODO: good export type of x, y and z
export interface AccelerometerObject {
@mattisfrommars
mattisfrommars / Ugh.js
Created March 8, 2017 14:31
Either I'm having a brain fart, or there's no nice way of doing this. I have 3 independent boolean variables and need to render a view based on those states
const a = Math.random() >= 0.5;
const b = Math.random() >= 0.5;
const c = Math.random() >= 0.5;
if (a) {
if (b) {
if (c) {
return '111';
} else {
return '110';
@mattisfrommars
mattisfrommars / gist:baefcea88abb2f4dcec5
Last active August 29, 2015 14:18
Things Valentin Hates
[
"Patent Trolls",
"David Cameron",
"Xenophobia",
"Everything",
"Irresponsible Drug Policy",
"Money",
"Jay Walking",
"Spicy Food",
"Caffeine",
@mattisfrommars
mattisfrommars / pre-commit
Last active August 29, 2015 14:14
Run gulp before commit
######################################################################
# Unit Tests: Run unit tests/specs before committing
######################################################################
./node_modules/.bin/gulp
EXIT_CODE=$?
if [[ ${EXIT_CODE} -ne 0 ]]; then
echo "[ERRROR] code = " ${EXIT_CODE}
echo "Tests failed."
echo "Commit aborted."
exit 1
@mattisfrommars
mattisfrommars / gist:0036138d379b56d87db1
Created November 12, 2014 17:20
Tech Test for loop
'use strict';
/**
* @returns {Promise} that will be resolved
*/
function doSomething () {
return new Promise(function( resolve, reject ){
setTimeout(function(){
resolve();
}, Math.random() * 1000 );
@mattisfrommars
mattisfrommars / gist:2ae1c33c96650d6a1291
Last active August 29, 2015 14:01
Leap motion pointer tracking
function giveMe ( n, callable ) {
return Array.apply( null, new Array( n ) ).map( callable );
}
function Canvas ( id ) {
this.canvas = document.getElementById( id );
// fullscreen
this.canvas.width = window.innerWidth;
this.canvas.height = window.innerHeight;
// create a rendering context
@mattisfrommars
mattisfrommars / ScalarParallaxAnimation.js
Last active August 29, 2015 13:58
Javascript class to perform parallax scrolling animations on arbitrary css properties
function ScalarParallaxAnimation( selector, cssProp, scaleMin, scaleMax, valueMin, valueMax, isInteger ) {
isInteger = isInteger || false;
this.$target = $(selector);
this.cssProp = cssProp;
this.scaleMin = scaleMin;
this.scaleMax = scaleMax;
this.valueMin = valueMin;
this.valueMax = valueMax;
this.isInteger = isInteger;
this.setCssValue( valueMin );
@mattisfrommars
mattisfrommars / AndroidManifest.xml
Last active August 29, 2015 13:56
Overrides the onCreate method to set the content view to activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="uk.co.mattjewell.app" >
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity