Skip to content

Instantly share code, notes, and snippets.

View opensourcekam's full-sized avatar
🎯
Focusing

✨OSKAM✨ opensourcekam

🎯
Focusing
View GitHub Profile
import React from 'react';
import packageJson from '../package.json';
global.appVersion = packageJson.version;
// version from response - first param, local version second param
const semverGreaterThan = (versionA, versionB) => {
const versionsA = versionA.split(/\./g);
const versionsB = versionB.split(/\./g);
while (versionsA.length || versionsB.length) {
@opensourcekam
opensourcekam / CalendarExport.ts
Created May 8, 2020 20:50
A calendar service for exporting to various calendar types
import moment from 'moment';
export type CalendarEvent = {
title: string;
description: string;
location: string;
startDate: string;
endDate: string;
};
export const on = (obj: any, ...args: any[]) => obj.addEventListener(...args);
export const off = (obj: any, ...args: any[]) => obj.removeEventListener(...args);
@opensourcekam
opensourcekam / styleHelpers.js
Created November 26, 2019 17:26
some cool style helpers
export const prefersReducedMotion = css`
@media (prefers-reduced-motion: reduce) {
animation: none;
transition: none;
}
`;
@opensourcekam
opensourcekam / useForm.js
Created October 1, 2019 22:27
form hook
import { useState } from "react";
export const useForm = cb => {
const [values, setValues] = useState({});
const handleSubmit = event => {
if (event) event.preventDefault();
if (cb && typeof cb === "function") cb(values);
};
@opensourcekam
opensourcekam / useStateLocalStorage.js
Last active October 1, 2019 22:26
use state with persistent storage
import { useState, useEffect } from 'react';
export const useStateLocalStorage = (localStorageKey, initialState = "") => {
const init = localStorage.getItem(localStorageKey) || initialState;
const [value, setValue] = useState(init);
useEffect(() => {
localStorage.setItem(localStorageKey, value);
}, [value]);
@opensourcekam
opensourcekam / CustomCodeForm.js
Created September 12, 2019 18:00
Just a custom code form
import React, { useState } from "react";
import styled, { keyframes } from "react-emotion";
const useForm = cb => {
const [values, setValues] = useState({});
const handleSubmit = event => {
if (event) event.preventDefault();
if (cb && typeof cb === "function") cb(values);
};
@opensourcekam
opensourcekam / styled-component.ts
Created April 21, 2019 20:37
How to type a styled component
import styled, { StyledFunction } from "styled-components"
interface YourProps {
invalid: boolean
}
const input: StyledFunction<YourProps & React.HTMLProps<HTMLInputElement>> = styled.input
const Input = input`
border: ${p => p.invalid ? 'red' : 'blue'};
@opensourcekam
opensourcekam / colorVars.css
Created March 19, 2019 04:26 — forked from softpunch/colorVars.css
CSS Variables For Color Manipulation
/* ----
css custom properties to manipulate color
MIT - 2017 - Soft Punch
https://gist.github.com/softpunch/
set initial "main" color via HSL values.
automatically calculate harmonies and variations of that color with pure css.
harmonies are determined solely by hue.
@opensourcekam
opensourcekam / .bash_profile
Created March 11, 2019 20:06
My current bash profile
################
#### RAND ##
################
export PS1="👻 --> "
alias ..="cd .. && ls"
alias up='cd .. && ls'
alias down='cd && ls'
alias pwdc="pwd && pwd | tr -d '\n' | pbcopy"
################