Skip to content

Instantly share code, notes, and snippets.

@jmreidy
jmreidy / test_mocha.opts
Last active January 9, 2018 11:49
Unit test React Native with Mocha
--compilers js:./test/support/compiler
--require ./test/support/init
@Daniel15
Daniel15 / gist:7969014
Last active May 27, 2017 15:42
Item/List classes in React
var Item = React.createClass({
render: function() {
return(
<li>
... Item goes here ...
<input type="checkbox" checked={this.props.selected} onChange={this.onChange} />
</li>
);
},
onChange: function(event) {
@davemo
davemo / README.md
Last active September 14, 2018 00:33
A pre-commit hook for git running on OS X to abort if it detects keywords in specified files (this version is setup for .coffee and .js files).

Git pre-commit Hooks

The pre-commit file listed here is setup to scan files for invalid keywords prior to commit to avoid debug or logging information making its way into production files. Right now it is setup to scan only .js and .coffee files for the following keywords:

KEYWORDS_REGEX="console\.(debug|info|log|warn)\(|alert\(|debugger"
EXTENSIONS_REGEX="(.js$|.coffee$)"

Installing the Hook

# Test setup, with jasmine-given
Given -> spyOn(Backbone.Model.prototype.fetch, 'call').andReturn
done: (callback) -> callback()
# Source, fetch override in model
fetch: (options) ->
Backbone.Model.prototype.fetch.call(@, options).done @callback
@domenic
domenic / promises.md
Last active June 24, 2024 03:11
You're Missing the Point of Promises

This article has been given a more permanent home on my blog. Also, since it was first written, the development of the Promises/A+ specification has made the original emphasis on Promises/A seem somewhat outdated.

You're Missing the Point of Promises

Promises are a software abstraction that makes working with asynchronous operations much more pleasant. In the most basic definition, your code will move from continuation-passing style:

getTweetsFor("domenic", function (err, results) {
 // the rest of your code goes here.
@clarkware
clarkware / lyrics.rb
Created September 10, 2012 20:05
Random Lyrics
#!/usr/bin/env ruby
# API Documentation at http://api.wikia.com/wiki/LyricWiki_API
require 'open-uri'
require 'json'
require 'tmpdir'
ARTIST = "Johnny Cash"
@davemo
davemo / prod.js
Created June 21, 2012 17:51
A way to spy on and verify the selector when using this.$(selector) with a Backbone.View
// The production code in question, part of a backbone view
showSearch: function () {
this.$('.dataTables_filter').show();
}
describe "app.Agent", ->
Given -> @car = new Backbone.Model
Given -> spyOn(@car, "get")
Given -> @car.get.when('phone').thenReturn("123-456-789")
Given -> @car.get.when('name').thenReturn("juice")
Then -> expect(@car.get).toHaveBeenCalledWith('phone')
Then -> expect(@car.get).toHaveBeenCalledWith(jasmine.any(String))
Then -> expect(@car.get).toHaveBeenCalledWith jasmine.argThat (arg) ->
arg.length < 5
@JosephPecoraro
JosephPecoraro / shell-execution.rb
Last active September 10, 2023 10:12
Shell Execution in Ruby
# Ways to execute a shell script in Ruby
# Example Script - Joseph Pecoraro
cmd = "echo 'hi'" # Sample string that can be used
# 1. Kernel#` - commonly called backticks - `cmd`
# This is like many other languages, including bash, PHP, and Perl
# Synchronous (blocking)
# Returns the output of the shell command
# Docs: http://ruby-doc.org/core/classes/Kernel.html#M001111