Skip to content

Instantly share code, notes, and snippets.

@engineersamuel
engineersamuel / gist:5416671
Created April 18, 2013 22:14
Example knockout expressions
<!-- variable (usually a property of the current view model -->
<div data-bind="visible: shouldShowMessage">...</div>
<!-- comparison and conditional -->
The item is <span data-bind="text: price() > 50 ? 'expensive' : 'cheap'"></span>.
<!-- function call and comparison -->
<button data-bind="enable: parseAreaCode(cellphoneNumber()) != '555'">...</button>
<!-- function expression -->
@engineersamuel
engineersamuel / gist:5416673
Created April 18, 2013 22:15
Example knockout expressions
<!-- variable (usually a property of the current view model -->
<div data-bind="visible: shouldShowMessage">...</div>
<!-- comparison and conditional -->
The item is <span data-bind="text: price() > 50 ? 'expensive' : 'cheap'"></span>.
<!-- function call and comparison -->
<button data-bind="enable: parseAreaCode(cellphoneNumber()) != '555'">...</button>
<!-- function expression -->
@engineersamuel
engineersamuel / ko_expressions.html
Created April 18, 2013 22:15
Example knockout expressions
<!-- variable (usually a property of the current view model -->
<div data-bind="visible: shouldShowMessage">...</div>
<!-- comparison and conditional -->
The item is <span data-bind="text: price() > 50 ? 'expensive' : 'cheap'"></span>.
<!-- function call and comparison -->
<button data-bind="enable: parseAreaCode(cellphoneNumber()) != '555'">...</button>
<!-- function expression -->
@engineersamuel
engineersamuel / gist:5416674
Created April 18, 2013 22:15
Example knockout expressions
<!-- variable (usually a property of the current view model -->
<div data-bind="visible: shouldShowMessage">...</div>
<!-- comparison and conditional -->
The item is <span data-bind="text: price() > 50 ? 'expensive' : 'cheap'"></span>.
<!-- function call and comparison -->
<button data-bind="enable: parseAreaCode(cellphoneNumber()) != '555'">...</button>
<!-- function expression -->
@engineersamuel
engineersamuel / gist:5416681
Created April 18, 2013 22:16
Example knockout expressions
<!-- variable (usually a property of the current view model -->
<div data-bind="visible: shouldShowMessage">...</div>
<!-- comparison and conditional -->
The item is <span data-bind="text: price() > 50 ? 'expensive' : 'cheap'"></span>.
<!-- function call and comparison -->
<button data-bind="enable: parseAreaCode(cellphoneNumber()) != '555'">...</button>
<!-- function expression -->
@engineersamuel
engineersamuel / thread_utils.py
Created August 27, 2013 13:40
Simple thread pool in python
class OneOffThreadPool(threading.Thread):
def __init__(self, max_concurrent_threads=10):
threading.Thread.__init__(self)
self.threads = []
self.threads_running = []
self.thread_count = 0
self.max_concurrent_threads = max_concurrent_threads
self.log = logging.getLogger(name="OneOffThreadPool")
self.log.setLevel(logging.INFO)
constructor(props, context) {
super(props, context);
// Copied from http://codepen.io/desandro/pen/nFrte
this.filterFns = {
// show if number is greater than 50
numberGreaterThan50: function () {
var number = $(this).find('.number').text();
return parseInt( number, 10 ) > 50;
},
@engineersamuel
engineersamuel / IsotopeResponseRenderer.jsx
Created January 6, 2016 12:54
shouldComponentUpdate
shouldComponentUpdate(nextProps, nextState) {
return !shallowEqual(this.props, nextProps) || !shallowEqual(this.state, nextState);
}
import React from "react";
import shallowEqual from "react-pure-render/shallowEqual"
// Flux
import connectToStores from 'alt/utils/connectToStores';
import FilterSortActions from '../flux/actions/FilterSortActions';
import FilterSortStore from '../flux/stores/FilterSortStore';
@connectToStores
export default class IsotopeResponseRenderer extends React.Component {
@engineersamuel
engineersamuel / IsotopeResponseRenderer.jsx
Created January 6, 2016 13:16
componentWillReceiveProps
componentWillReceiveProps(nextProps) {
if (nextProps.filter && !_.isEqual(nextProps.filter, this.props.filter)) {
this.iso.arrange({ filter: this.filterFns[nextProps.filter] || nextProps.filter });
}
if (nextProps.sort != null) {
this.iso.arrange({sortBy: nextProps.sort});
}
}