Skip to content

Instantly share code, notes, and snippets.

var elements = ['foo', 'bar', 'baz']
for(i=0; i < elements.length; i++){
elements[i].setClick(function(){
alert(i);
});
}
elements[0].click(); // what happens?
var vimBinding = document.createElement('script');
vimBinding.setAttribute('src','https://raw.github.com/marijnh/CodeMirror/master/keymap/vim.js');
var mirrors = document.querySelectorAll('.CodeMirror');
// browser support for onload may be iffy ...
vimBinding.onload = function () {
Array.prototype.forEach.call(mirrors, function (instance){
instance.CodeMirror.setOption('keyMap','vim');
<% _.forEach(projects, function (project) {%>
.<%= project.name %> {
background-img: url('img/projects/<%= project.img %>');
<% }); %>
@hankyates
hankyates / xor.js
Last active August 29, 2015 13:57
Code Fellows XOR
// Implement an exclusive OR function called `preferredName` that has the following interface:
var FirstName,
LastName;
preferredName(FirstName, LastName);
// -> false
FirstName = 'Hank';
// Given the following data structure
// implement a oldestLivingFather method
// that will return the name of the oldest
// living father.
var people = [
{
name: 'Hank',
age: 29,
father: 'Don'
// Implement a decorator function that takes
// a function as an argument and will track
// how many times the passed function was called.
function Add(x, y) {
return x + y;
}
var Add = countDecorator(Add);
@hankyates
hankyates / stringDelimiter.js
Created April 9, 2014 06:10
Javascript implementation of a string delimiter
// Write a function that takes in a string seperated by a seperator, and will return an array
// of strings in between the seperators.
var sampleInput = 'asdf$lskd1234$asdo';
stringDelemiter(sampleInput, '$');
// -> ['asdf', 'lskd1234', 'asdo']
function oldestLivingParent(people) {
var livingParents = {};
var sortedByAge = [];
var oldestLivingParent = false;
var isDead = function(p) {
return !person.age;
};
var isParent = function(p) {
return !!livingParent[p.name];
};
@hankyates
hankyates / MAGIC
Last active October 9, 2015 01:36
its magic yo
find . -type f -exec sed -i -e 's%../app/%./%g' {} \;
find . -type f -exec sed -i -e 's%../build/%./views/%g' {} \;
find . -type f -exec sed -i '' -e 's%this.getDOMNode()%ReactDOM.findDOMNode(this)%g' {} \;
// osx sed -i expects an extension
// Illegal command try export LANG=C
var wat = React.createClass({
render: function() {
return <div className="wat" onClick={function() {console.log('hi')}}/>
}
});
ReactTestUtils.renderIntoDocument(<wat/>);
var huh = ReactTestUtils.scryRenderedDOMComponentsWithTag(wat, 'div');
ReactTestUtils.Simulate.click(huh);
// Error: InstanceHandle not injected before use!