Skip to content

Instantly share code, notes, and snippets.

View snoblenet's full-sized avatar

Steven Noble snoblenet

View GitHub Profile
@snoblenet
snoblenet / react_props_contract_respected_and_enforced.js
Last active October 30, 2018 05:16
The contracts between the components and the container are enforced by the specs
// containers/form_container.js
import Form from '../components/form_component';
export const mapStateToProps = state => ({ username: state.username });
export default connect(mapStateToProps)(Form);
// components/form_component.js
import PropTypes from 'prop-types';
import React from 'react';
const Form = class extends React.Component {
@snoblenet
snoblenet / utils_contract_respected_and_enforced.js
Last active September 19, 2018 02:59
The contract between getPrefix() and prefixWord() is enforced by the specs
// utils/get_prefix.js
export const getPrefix = (lang) => {
if (lang === 'fr') return 'méga';
return 'mega';
};
// utils/prefix_word.js
export const prefixWord = (prefixGetter, wordToPrefix) => prefixGetter() + wordToPrefix;
// spec/fixtures/prefix_fixtures.js
@snoblenet
snoblenet / react_props_contract_violated_with_proptype_inconsistency.js
Last active September 19, 2018 03:12
The contracts between the components and the container are violated by the modules, but this is not detected by the specs
// containers/form_container.js
import Form from '../components/form_component';
// The container passes a 'username' prop (type: string) to Form
export const mapStateToProps = state => ({ username: state.username });
export connect(mapStateToProps)(Form);
// components/form_component.js
import PropTypes from 'prop-types';
import React from 'react';
@snoblenet
snoblenet / react_props_contract_respected_but_not_enforced.js
Last active September 19, 2018 03:10
The contracts between the components and the container are respected by the modules but not enforced by the specs
// containers/form_container.js
import Form from '../components/form_component';
export const mapStateToProps = state => ({ username: state.username });
export default connect(mapStateToProps)(Form);
// components/form_component.js
import PropTypes from 'prop-types';
import React from 'react';
@snoblenet
snoblenet / utils_contract_violated_with_return_type_inconsistency.js
Last active September 19, 2018 03:05
The contract between getPrefix() and prefixWord() is violated but this is not detected by the specs
// utils/get_prefix.js
// Changed the return value type from string to object
export const getPrefix = () => ({ en: 'mega', fr: 'méga' });
// utils/prefix_word.js
export const prefixWord = (prefixGetter, wordToPrefix) => prefixGetter() + wordToPrefix;
// spec/utils/get_prefix.js
import getPrefix from '../../utils/get_prefix';
@snoblenet
snoblenet / utils_contract_violated_with_return_value_inconsistency.js
Last active September 19, 2018 02:09
The contract between getPrefix() and prefixWord() is violated but this is not detected by the specs
// utils/get_prefix.js
// Changed the return value from 'mega' to 'hyper'
export const getPrefix = () => 'hyper';
// utils/prefix_word.js
export const prefixWord = (prefixGetter, wordToPrefix) => prefixGetter() + wordToPrefix;
// spec/utils/get_prefix_spec.js
import getPrefix from '../../utils/get_prefix';
@snoblenet
snoblenet / utils_contract_respected_but_not_enforced.js
Last active September 19, 2018 03:03
The contract between getPrefix() and prefixWord() is respected by the modules but not enforced by the specs
// utils/get_prefix.js
export const getPrefix = () => 'mega';
// utils/prefix_word.js
export const prefixWord = (prefixGetter, wordToPrefix) => prefixGetter() + wordToPrefix;
// spec/utils/get_prefix_spec.js
import getPrefix from '../../utils/get_prefix';
describe('getPrefix()', => {
@snoblenet
snoblenet / conflicted.sh
Created October 5, 2017 06:40
Instant Git Merge Practice
#!/bin/bash
rm my-code.txt > /dev/null 2>&1 &
rm -rf .git > /dev/null 2>&1 &
touch my-code.txt
git init
git add my-code.txt

Keybase proof

I hereby claim:

  • I am snoblenet on github.
  • I am snoblenet (https://keybase.io/snoblenet) on keybase.
  • I have a public key ASCMBay3aYDRi7nJy9DUqfqJSWUfgLj4bTBoESEfFojnUgo

To claim this, I am signing this object:

@snoblenet
snoblenet / warn.vim
Last active May 5, 2017 04:08
Caps Lock and Insert mode warning for Vim
" ensure you have xset in your shell
" change 'solarized' to the name of your colorscheme
" presumes that your colorscheme, like solarized, provides both dark and light modes
function! CapsWarn()
let CapsState = system('xset -q | grep -oE "Caps Lock: on"')
if CapsState =~ "on"
highlight Normal ctermbg=Red
redraw
sleep 100m