Skip to content

Instantly share code, notes, and snippets.

View chris-kobrzak's full-sized avatar

Chris Kobrzak chris-kobrzak

View GitHub Profile
@chris-kobrzak
chris-kobrzak / logic-in-jsx.js
Last active January 13, 2017 18:35
Demonstrate poor practice of JSX intertwined with logic, coupled with multi-line ternary operator statements
render () {
const { visible } = this.props
return (
<div className={ visible ? 'expanded' : 'collapsed' }>
{
visible ? <div>
// Dozens of lines of JSX code here
// Dozens of lines of JSX code here
// Dozens of lines of JSX code here
// Dozens of lines of JSX code here
@chris-kobrzak
chris-kobrzak / es6-module-only-babel-transpilation-example.js
Last active April 20, 2016 08:06
Code sample with only ES6 modules transpiled by Babel
class TextInputControl extends _react2.default.Component {
constructor(props) {
super(props);
this.bindInstanceMethods('handleBlurEvent', 'handleChangeEvent');
this.handleChangeEventDebounced = (0, _debounce2.default)(this.handleChangeEvent, props.inputChangeDebounceWait);
}
bindInstanceMethods(...methods) {
methods.forEach(method => this[method] = this[method].bind(this));
@chris-kobrzak
chris-kobrzak / .babelrc
Created April 19, 2016 22:16
Pure ES6/React development environment
{
"presets": ["react"],
"plugins": ["transform-es2015-modules-commonjs"]
}
@chris-kobrzak
chris-kobrzak / Create app symlinks.sh
Last active January 4, 2016 15:09
Use this script to create shortcuts to commonly used applications. Then drag the directories to the OS X Dock to enable the Downloads-like shortcut functionality.
@chris-kobrzak
chris-kobrzak / .babelrc
Created January 1, 2016 23:06
Minimal configuration for bundling React classes with ES6 and JSX syntaxes
{
"presets": ["es2015", "react"]
}
@chris-kobrzak
chris-kobrzak / Vim cheat sheet.md
Last active August 16, 2018 11:05
My Vim editor cheat sheet

Saving files

Save file even if it was opened without write permissions

:w !sudo tee %

Write/append lines from file to another file (optionally overwrite)

:5,25w [!] [>>] new_file
@chris-kobrzak
chris-kobrzak / calculateMedian.js
Last active November 18, 2015 22:10
Sample implementation of a median calculation function in JavaScript
function calculateMedian( array ) {
var arraySize = array.length
if ( arraySize === 1 ) {
return array[0]
}
var isOddLength = isOdd( arraySize ),
middleIndex = Math.floor( arraySize / 2.0 )
array.sort( subtract )
@chris-kobrzak
chris-kobrzak / WindowResizeManager.js
Last active November 8, 2015 19:13
Sample implementation of the browser window resize observer that throttles native browser events and emits custom events instead. This might be useful if you don't need to respond to resize events immediately and performance is a major concern.
WindowResizeManager = function( debounceWait ) {
this.debounceWait = debounceWait || 200;
_.bindAll(this, "handleWindowResizeEvent", "triggerWindowResizeCompleteEvent");
this.cacheDom();
this.bindWindowResizeEvent();
};
WindowResizeManager.prototype.cacheDom = function() {
this.window: $(window);
};
@chris-kobrzak
chris-kobrzak / isPalindrome.js
Created October 21, 2015 22:54
Sample implementation of palindrome checking function in JavaScript
function isPalindrome( string ) {
var notWordPattern = /\W/g,
alphaNumericOnly = string
.replace( notWordPattern, "" )
.toLowerCase(),
alphaNumericOnlyReversed = alphaNumericOnly.reverse()
return alphaNumericOnly == alphaNumericOnlyReversed
}
@chris-kobrzak
chris-kobrzak / generated-names.js
Created July 31, 2015 21:03
Sample fake data generator that can be used with json-server
module.exports = function() {
var faker = require("faker"),
_ = require("lodash");
return {
people: _.times(100, function (n) {
return {
id: n,
name: faker.name.findName(),
jobTitle: faker.name.jobTitle()
}