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 / Raspbian vs. Hypriot Linux kernel config
Last active August 29, 2015 14:23
2015-05-05-raspbian-wheezy vs. hypriot-rpi-20150416-201537
# Linux/arm 3.18.11-hypriotos Kernel Configuration | # Linux/arm 3.18.11 Kernel Configuration
CONFIG_HAVE_ARCH_AUDITSYSCALL=y | ---------------------------------------------
# CONFIG_AUDITSYSCALL is not set | ---------------------------------------------
CONFIG_CPUSETS=y | # CONFIG_CPUSETS is not set
CONFIG_PROC_PID_CPUSET=y | ---------------------------------------------
CONFIG_MEMCG_SWAP=y | # CONFIG_MEMCG_SWAP is not set
CONFIG_MEMCG_SWAP_ENABLED=y | ---------------------------------------------
CONFIG_CGROUP_PERF=y | # CONFIG_CGROUP_PERF is not set
CONFIG_UPROBES=y | # CONFIG_UPROBES is not set
CONFIG_HAVE_ARCH_SECCOMP_FILTER=y | ---------------------------------------------
@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()
}
@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 / 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 / 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 / .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 / 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 April 19, 2016 22:16
Pure ES6/React development environment
{
"presets": ["react"],
"plugins": ["transform-es2015-modules-commonjs"]
}
@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 / logic-in-jsx-improved.js
Last active September 23, 2016 22:07
Less logic in JSX resulting in code that's easier to read and transpiled to a simpler and more compact block of code
render () {
const { visible } = this.props
let visibleContent
if (visible) {
visibleContent = this.getVisibleContent()
}
return (
<div className={ visible ? 'expanded' : 'collapsed' }>
{ visibleContent } // No more logic here and useless "null"