Skip to content

Instantly share code, notes, and snippets.

import React, { ComponentProps, ReactElement } from 'react'
//React extends the web all of these ways!
// interface InputProps extends React.HTMLProps<HTMLInputElement>{
// icon?: string
// }
// interface InputProps extends ComponentProps<"input"> {
// icon?: string
useEffect(() => {
async function fetchServerGeneratedValue() {
try {
const response = await fetch('http://localhost:5000', {
method: 'GET',
headers: {
'Content-Type': 'application/json'
},
});
const json = await response.json();
rules: [
{
name: 'xorWithAllPaths',
params: {peers: Joi.array()},
validate(params, value, state, options) {
if (value !== null && params) {
const xOrError = Joi.object()
.keys({discountAmount: Joi.number(), discountPercentage: Joi.number()})
.xor('discountAmount', 'discountPercentage')
.options({allowUnknown: true})
@kPOWz
kPOWz / keysNavigationPlugin.js
Last active August 29, 2015 14:26
jQuery Plugin to Navigate a Table of Inputs Via Arrow Keys. Skips by disabled or cells without inputs.
(function( $ ) {
var eligibleRowSelector = 'tr:has( td:has(input:enabled))';
var eligibleRowInputSelector = 'td:has(input:enabled)';
var nextRowWithEligibleInputs = function(current){
return $(current).closest('tr').nextUntil('table', eligibleRowSelector).first();
}
var priorRowWithEligibleInputs = function(current){
@kPOWz
kPOWz / AndroidManifest.xml
Last active August 29, 2015 14:23
Patterns for Android Bound Services Survival Through Lifecycle/Config Changes
<!-- solution #1 -->
<!-- Solution #1 - Do not destory activity when device rotates -->
<!-- When to use solution #1? When activity does NOT need different resource files/layouts based on device rotation.
Usually only an option when having simple interface that doesn't vary greatly by screen size or orientation. -->
<application>
<activity
android:name=".activity.Solution1Activity"
android:configChanges="orientation|keyboardHidden|screenSize"
> <!-- tells Android activity will define consequences of these config changes & not to carry out default behaviors -->
@kPOWz
kPOWz / this.css
Created February 15, 2015 16:12
Absolutely position element inside responsive CSS grid
.bottom{
position: absolute;
bottom: 0;
right: 0;
left: 0;
}
@kPOWz
kPOWz / form.less
Last active August 29, 2015 14:15
LESS mixin produces custom, cross-browser CSS checkbox. Requires accessibility attributes on view.
// Custom checkbox
//
// Requires checkbox type input with sibling label having the 'for' attribute
// The label appears as the checkbox, while the real/orginal checkbox isn't displayed
// Unicode is used for checkmark representation
.input-checkbox-variant(@color; @background; @border; @size){
input[type='checkbox']{display: none;}
input[type='checkbox'] + label{
height: @size;
@kPOWz
kPOWz / form.less
Last active August 29, 2015 14:15
LESS mixin produces custom, cross-browser CSS checkbox for use with TWBS. Requires accessibility attributes on view.
// Custom checkbox
//
// Requires checkbox type input with sibling label having the 'for' attribute
// Relies on TWBS label display setting of 'display: inline-block;'
// The label appears as the checkbox, while the real/orginal checkbox isn't displayed
// Unicode is used for checkmark representation
.input-checkbox-variant(@color; @background; @border; @size)
when (get-unit(@size) = rem), (get-unit(@size) = em){
input[type='checkbox']{display: none;}
[
['shop',[{ request: request, callback: callback}, {request: request, callback: callback}]]
,['drink',[{}, {}]]
,['eat',[{}, {}]]
]
@kPOWz
kPOWz / IIFEModule.js
Last active August 29, 2015 14:13
Namespacing & Modularity
//anonymous immediately invoked function expression
//module pattern with anonymous closures
var WEBCOLOR = (function(){
//private, closed up into WEBCOLOR namespace
var white = 0;
var black = 255;
//private (not exposed via namespace
var func = function(var){