Skip to content

Instantly share code, notes, and snippets.

View outofthisworld's full-sized avatar

Dale outofthisworld

  • Auckland, New Zealand
View GitHub Profile
const sign_in = async ({ username, password }) => {
await driver.get(constants.TRADE_ME_AUTH_URL);
return new Promise((resolve, reject) => {
setTimeout(async () => {
try {
await driver
.findElement(selenium.By.id(constants.view.emailInputElementId))
.sendKeys(username);
await driver
.findElement(selenium.By.id(constants.view.passwordInputElementId))
@outofthisworld
outofthisworld / phone-unlcok.js
Created February 24, 2019 10:37
Phone unlock edges
let Node = function(n) {
this.name = n;
this.edges = []
}
function calcCombinations(node, length) {
let currentPath = [];
let combinations = [];
@outofthisworld
outofthisworld / react-slider-pose.js
Last active May 21, 2019 13:36
React pose slider
import React from "react";
import ReactDOM from "react-dom";
import { useState, useEffect, useRef } from "react";
import posed, { PoseGroup } from "react-pose";
import "./styles.css";
let AnimatableDiv = posed.div({
enter: {
y: 0,
x: 0,
@outofthisworld
outofthisworld / react-hooks-visible.js
Last active June 1, 2019 20:58
React hooks animate element on visible
import React from "react";
import ReactDOM from "react-dom";
import {
useEffect,
useState,
useRef,
useReducer,
useContext,
useCallback,
useMemo,
const util = require("util");
function doSomethingAsync(count, callback) {
setTimeout(function() {
callback(null,'hi');
}, 0);
}
function asyncCallback(asyncFunc, ...args) {
return util.promisify(asyncFunc)(...args);
const getElementInfo = (domElement, obj = {}) => {
const toNumber = (thing) => {
//console.log('converting ' + thing + ' to ' + Number(thing.replace(/[^0-9]+/,'')));
return Number(thing.replace(/[^0-9]+/, ''));
}
//Our offset from our parent, could be the first positioned parent element or the document body
const parentOffsetTop = domElement.offsetTop;
const parentOffsetLeft = domElement.offsetLeft;
function rgba2hex(orig) {
var a, isPercent,
rgb = orig.replace(/\s/g, '').match(/^rgba?\((\d+),(\d+),(\d+),?([^,\s)]+)?/i),
alpha = (rgb && rgb[4] || "").trim(),
hex = rgb ?
(rgb[1] | 1 << 8).toString(16).slice(1) +
(rgb[2] | 1 << 8).toString(16).slice(1) +
(rgb[3] | 1 << 8).toString(16).slice(1) : orig;
@outofthisworld
outofthisworld / react-lazy-img.js
Last active September 16, 2018 03:48
Simple react lazy image loading
const getElementInfo = (domElement, obj = {}) => {
const toNumber = (thing) => {
//console.log('converting ' + thing + ' to ' + Number(thing.replace(/[^0-9]+/,'')));
return Number(thing.replace(/[^0-9]+/, ''));
}
//Our offset from our parent, could be the first positioned parent element or the document body
const parentOffsetTop = domElement.offsetTop;
const parentOffsetLeft = domElement.offsetLeft;
@outofthisworld
outofthisworld / reduxasync.js
Created August 25, 2018 06:24
Redux async store
import { createStore } from 'redux'
/*
Define the async reducer
*/
const arrayAppend = async (state, action) => {
return [...state, action.toAdd];
}
@outofthisworld
outofthisworld / generate_graphql.js
Created August 23, 2018 12:58
Generate graphql
const scriptArgs = process.argv.slice(2)
const [typeName, schemaName] = scriptArgs;
const Schema = require(`../database/models/${schemaName}`);
const getType = (key, value) => {
const formatKey = (key) => {
let formatted = `${key[0].toUpperCase() + key.substring(1)}`;
formatted = formatted.endsWith('s') ? formatted.slice(0, -1) : formatted;