Skip to content

Instantly share code, notes, and snippets.

View cpitt's full-sized avatar

Cameron Pitt cpitt

View GitHub Profile
g=git
ga='git add'
gaa='git add --all'
gam='git am'
gama='git am --abort'
gamc='git am --continue'
gams='git am --skip'
gamscp='git am --show-current-patch'
gap='git apply'
gapa='git add --patch'
@cpitt
cpitt / documentToMUIComponents.tsx
Created July 24, 2020 17:07
translate conentful document into material-ui components
import {
documentToReactComponents,
Options,
} from '@contentful/rich-text-react-renderer';
import { Document, BLOCKS, INLINES } from '@contentful/rich-text-types';
import { Typography, Divider, Link } from '@material-ui/core';
/**
* a wrapper around documentToReactComponents that has material-ui component defaults
**/
@cpitt
cpitt / useIdleTimer.test.tsx
Created June 30, 2020 22:07
useIdleTimer React hook
import { renderHook, act } from '@testing-library/react-hooks';
import useIdleTimer from './useIdleTimer';
import { fireEvent } from '@testing-library/react';
jest.useFakeTimers();
describe('useIdleTimer', function() {
it('should start timer when startIdleTimer is called', function() {
const { result } = renderHook(() => useIdleTimer());
@cpitt
cpitt / memoizeLocalStorage.js
Last active April 12, 2024 07:36
Memoize a function using local storage as it's cache
/**
* memoizes a function using localStorage as the cache
* @param {function|Promise} fn function or promise you wish to memoize
* @param {Object} [options] additional configuration
* @param {number} [options.ttl=0] time to live in seconds
* @param {Boolean} [options.backgroundRefresh=false] whether the cache should be refreshed asynchronously,
* Note: new results won't resolve until next execution
* @return {Promise} Promise object represents memoized result
*/
function memoizeLocalStorage(
@cpitt
cpitt / Dockerfile
Last active February 23, 2018 05:25
docker java install work around
FROM node:9.0
WORKDIR /usr/src/app
RUN echo "===> add webupd8 repository..." && \
echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu artful main" | tee /etc/apt/sources.list.d/webupd8team-java.list && \
echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu artful main" | tee -a /etc/apt/sources.list.d/webupd8team-java.list && \
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys EEA14886 && \
apt-get update
RUN echo "===> install Java" && \
cd /var/lib/dpkg/info && \
echo debconf shared/accepted-oracle-license-v1-1 select true | debconf-set-selections && \
@cpitt
cpitt / main.go
Created January 18, 2018 20:50
k8s go-client in cluster pod creation
package main
import (
// "encoding/json"
"os"
log "github.com/sirupsen/logrus"
"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"

Keybase proof

I hereby claim:

  • I am cpitt on github.
  • I am cpitt (https://keybase.io/cpitt) on keybase.
  • I have a public key whose fingerprint is 8AF3 B1D2 E995 86E7 B32D 6C00 D8CA F5E3 5052 7865

To claim this, I am signing this object:

let g:spf13_bundle_groups=['general', 'programming', 'misc', 'writing', 'javascript', 'html', 'ruby', 'youcompleteme' ]
let g:airline_powerline_fonts=1
@cpitt
cpitt / confirmation-directive.html
Created October 10, 2014 06:37
A Simple Directive for Bootstrap confirmation modals using ui-bootstrap
<div class="modal-header">
<div class="modal-title">
<h3>{{confirmTitle}}</h3>
</div>
</div>
<div class="modal-body">
{{confirmMessage}}
</div>
<div class="modal-footer">
<button class="btn btn-default" ng-click="cancel()"> {{cancelText}} </button>
@cpitt
cpitt / bootstrap-validation-directive.js
Last active August 29, 2015 14:02
angular bootstrap validation
angular.module('bootstrap.validation', [])
/*
If you want errors to show up after submit is hit then your submit action needs to
set your form's controller's .submitted value to true
*/
/* example of a custom validation */
.directive('dateValidation', function(){
return{
restrict: 'A',