Skip to content

Instantly share code, notes, and snippets.

View sirdlx's full-sized avatar

Sir Charles White sirdlx

View GitHub Profile
class StorageDriver {
constructor (conf = {}) {
this.conf = conf
if (
typeof this.conf.storage.getItem !== 'function' ||
typeof this.conf.storage.removeItem !== 'function' ||
typeof this.conf.storage.setItem !== 'function'
) {
throw new Error('Given Storage doesn\'t have methods `getItem`, `setItem` and `removeItem`.')
@sirdlx
sirdlx / index.android.js
Created March 19, 2017 22:53
Alternative to react-navigation's replace action
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React from 'react';
import {
AppRegistry,
StyleSheet,
@sirdlx
sirdlx / square.js
Created February 1, 2017 03:13
Node server for help with squareup.
"use strict";
var decimalOnly = /^\s*-?[1-9]\d*(\.\d{1,2})?\s*$/;
var cleanText = (function (textin) {
return textin.replace(/[^\w-]/g, '').toLowerCase();
});
var express = require('express');
var router = express.Router();
var request = require("request");
var squareBaseURLv1 = "https://connect.squareup.com/v1/";
var squareBaseURLv2 = "https://connect.squareup.com/v2/";
@sirdlx
sirdlx / cloudSettings
Last active October 12, 2016 18:39
Visual Code Sync Settings
{"lastUpload":"2016-10-12T18:39:35.964Z"}
@sirdlx
sirdlx / formatBytesText.js
Created June 9, 2016 20:37
format bytes to text: 243.6 BG
let bytesText = function formatBytesText(bytes) {
if(bytes < 1024) return bytes + " Bytes";
else if(bytes < 1048576) return(bytes / 1024).toFixed(2) + " KB";
else if(bytes < 1073741824) return(bytes / 1048576).toFixed(2) + " MB";
else return(bytes / 1073741824).toFixed(2) + " GB";
};
@sirdlx
sirdlx / webcoponents_support.js
Created April 17, 2016 18:02
conditionally load webcomponentsjs
var webComponentsSupported = ('registerElement' in document
&& 'import' in document.createElement('link')
&& 'content' in document.createElement('template'));
if (!webComponentsSupported) {
var wcPoly = document.createElement('script');
wcPoly.src = '/../bower_components/webcomponentsjs/webcomponents-lite.js';
wcPoly.onload = lazyLoadPolymerAndElements;
document.head.appendChild(wcPoly);
} else {
@sirdlx
sirdlx / check.decimal.only.js
Created November 10, 2015 03:36
regex for two decimal spaces
var decimalOnly = /^\s*-?[1-9]\d*(\.\d{1,2})?\s*$/;
STARTUP_VERSION=1
PARTITION_MARK=/var/startup.partition.$STARTUP_VERSION
RESIZE_MARK=/var/startup.resize.$STARTUP_VERSION
# Repartition the disk to full size
function partition() {
start_sector=$(sudo fdisk -l | grep ^/dev/sda1 | awk -F" " '{ print $3 }')
cat <<EOF | sudo fdisk -c -u /dev/sda
d
@sirdlx
sirdlx / designer.html
Created August 29, 2014 12:31
designer
<link rel="import" href="../core-icon-button/core-icon-button.html">
<link rel="import" href="../core-toolbar/core-toolbar.html">
<link rel="import" href="../core-header-panel/core-header-panel.html">
<link rel="import" href="../core-drawer-panel/core-drawer-panel.html">
<link rel="import" href="../core-menu/core-submenu.html">
<link rel="import" href="../core-item/core-item.html">
<link rel="import" href="../core-animated-pages/core-animated-pages.html">
<link rel="import" href="../core-animated-pages/transitions/hero-transition.html">
<link rel="import" href="../core-animated-pages/transitions/cross-fade.html">
<link rel="import" href="../core-animated-pages/transitions/slide-down.html">