Skip to content

Instantly share code, notes, and snippets.

View jonkemp's full-sized avatar

Jonathan Kemp jonkemp

View GitHub Profile
@jonkemp
jonkemp / HelloWorld.js
Last active February 29, 2024 14:10
React Component in Next.js with Styled Components, Jest, React Testing Library and Storybook [Template]
import React from 'react';
import styled from 'styled-components';
import PropTypes from 'prop-types';
const Wrapper = styled.div``;
const HelloWorld = () => {
return <Wrapper>
<h1>Hello World!</h1>
<Wrapper />;
@jonkemp
jonkemp / index.js
Created March 29, 2021 17:55
The Module Pattern from Learning JavaScript Design Patterns by Addy Osmani
const testModule = (() => {
let counter = 0;
return {
incrementCounter() {
return counter++;
},
@jonkemp
jonkemp / do-not-use-switch.md
Last active April 10, 2024 14:44
'Don’t use switch' excerpted from 'Programming JavaScript Applications' by Eric Elliott, https://www.oreilly.com/library/view/programming-javascript-applications/9781491950289/

Don't Use switch

JavaScript has pretty normal control-flow statements that use blocks delineated by curly braces. There is an exception to this: the switch ... case statement. The strange thing about switch ... case is that you must include the keyword break at the end of each case to prevent control from falling through to the next case. Fall through is a trick that allows you to let more than one case be executed. Control will fall through automatically to the next case unless you explicitly tell it not to with break. However, like the optional semicolons and curly braces, it's possible to forget break when you really should have used it. When that happens, the bug is difficult to find because the code looks correct. For that reason, the break statement should never be left off of a case, even by design.

With that said, JavaScript has an elegant object-literal syntax and first-class functions, which makes it simple to create a keyed method lookup. The object you create for your method lookup is call

@jonkemp
jonkemp / .editorconfig
Last active April 11, 2017 17:20
gulp-jquery-t3 sample project
# editorconfig.org
root = true
[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
@jonkemp
jonkemp / bookmarklets.html
Created January 30, 2017 04:14
Bookmarklets
<!-- switch to htts if available -->
<a href="javascript:(function(){if(location.protocol!='https:'){location.href='https:'+window.location.href.substring(window.location.protocol.length);}})();">HTTPS Switcher</a>
@jonkemp
jonkemp / OSX-junos_pulse_listenToMe.sh
Created March 8, 2016 15:31 — forked from Andrewpk/OSX-junos_pulse_listenToMe.sh
wtf juniper. Anyone else find it irritating that junos pulse services and pulse tray must always running in OS X regardless of whether or not you're currently connected? Yeah, me too. I added the following as aliases to my shell to fix this problem. Be sure to change your /Library/LaunchAgents/net.juniper.pulsetray.plist file to reflect the `Kee…
#################################################################################
# start and stop the vpn from the command line from now on with these two commands
# or rename the aliases as you see fit.
#################################################################################
alias startvpn="sudo launchctl load -w /Library/LaunchDaemons/net.juniper.AccessService.plist; open -a '/Applications/Junos Pulse.app/Contents/Plugins/JamUI/PulseTray.app/Contents/MacOS/PulseTray'"
alias quitvpn="osascript -e 'tell application \"PulseTray.app\" to quit';sudo launchctl unload -w /Library/LaunchDaemons/net.juniper.AccessService.plist"
@jonkemp
jonkemp / dev_server.md
Last active October 17, 2022 01:09
Starting a development server

Start a dev server to preview your work using Python, Ruby or Node.js

Requirements

Mac OS: Ruby and Python are pre-installed. Install Node.js.

Windows: First install Ruby, Python or Node.js

Ruby

@jonkemp
jonkemp / templateManager.js
Last active June 8, 2016 08:09
Load and cache external templates with jQuery and Underscore. Returns a promise. Useful for JavaScript MVC frameworks, such as Backbone.js.
/* global $, _ */
var TemplateManager = {};
(function () {
'use strict';
var cache = {};
TemplateManager.template = function (path) {
@jonkemp
jonkemp / README.md
Last active August 29, 2015 14:01
Bootstrap 'Digg-Style' Pagination template for Backbone
@jonkemp
jonkemp / diffObjKeys.js
Created March 4, 2014 21:36
Compare 2 objects based on their keys: WIP
var _ = _ || {};
_.contains = function (obj, target) {
if (obj == null) return false;
if (Array.prototype.indexOf && obj.indexOf === Array.prototype.indexOf) return obj.indexOf(target) != -1;
return obj.some(function(value) {
return value === target;
});
};