Skip to content

Instantly share code, notes, and snippets.

@brian-mann
brian-mann / gist:8640612
Created January 26, 2014 23:00
Coffeescript classes vs Javascript extend
// All Backbone objects have the extend method built in.
// This serves the same primary purpose as Coffeescript's extends keyword.
// After all, they were actually written by the same person: Jeremey Ashkenas
// Coffeescript Implementation for Backbone Model
class Entities.User extends Backbone.Model
defaults:
firstName: "Brian"
initialize: ->
@brian-mann
brian-mann / gist:9696358
Created March 21, 2014 20:58
why doesnt underscore wrap work
Backbone.sync = (method, entity, options = {}) ->
## THIS WORKS
_.each ["beforeSend", "complete", "error"], (fn) ->
options[fn] or= ->
orig = options[fn]
options[fn] = ->
orig.apply(entity, arguments)
methods[fn].apply(entity, arguments)
resortView: ->
@collection.each (model, index) =>
view = @children.findByModel(model)
@moveViewToIndex(view, index) if view._index isnt index
moveViewToIndex: (view, index) ->
view._index = index
sibling = view.$el.siblings().eq(index)
view.$el.insertBefore(sibling)

Example

/*
 * In window A's scripts, with A being on <http://example.com:8080>:
 */

var popup = window.open(...popup details...);

// When the popup has fully loaded, if not blocked by a popup blocker:
@brian-mann
brian-mann / gist:489ee81adaacff3992c4
Created August 11, 2015 18:27
example cypress.json
{
  "cypress": {
    "testFolder": "app/test/spec",
    "fixturesFolder": "app/test/spec/_fixtures",
    "supportFolder": "app/test/spec/_support",
    "viewportWidth": 1300,
    "viewportHeight": 660
  }
}
@brian-mann
brian-mann / deprecation.coffee
Created March 26, 2016 16:48
fun deprecation warning
chalk = require("chalk")
asciify = require("asciify")
asteriks = Array(90).join("*")
log = {
newLine: (num = 1) ->
n = Array(num).join("\n")
console.log(n)
}
@brian-mann
brian-mann / iteration.js
Last active April 27, 2016 22:59
var vs no var
// if you open your chrome dev tools
// you'll see it log out the performance
// of each iterating in the console
var array = Array(100)
console.time("var")
for (i = 0; i < array.length; i++) {
var e = array[i]
for (j = 0; j < array.length; j++) {
@brian-mann
brian-mann / spider.js
Last active May 25, 2016 18:58
spider with cypress
cy
.get("ul[class='nav menu'] a").then(function($a){
var hrefs = $a.map(function(i, el){
return Cypress.$(el).attr("href")
}).get()
hrefs.forEach(function(href){
cy.visit("http://your.url" + href).should("not.contain", "your 404 message")
// you might also try this
@brian-mann
brian-mann / arrowdown.js
Created June 7, 2016 15:17
arrowdown custom command
Cypress.addChildCommand("arrowdown", function($el){
var evt = new Event("keydown", {
bubbles: true,
cancelable: true,
altKey: false,
ctrlKey: false,
metaKey: false,
shiftKey: false,
location: 0,
charCode: 0,
Cypress.addDualCommand({
contains: function(subject, filter, text, options) {
var checkToAutomaticallyRetry, getErr, getFirstDeepestElement, getOpts, getPhrase, onConsole, resolveElements, selector, setEl;
if (options == null) {
options = {};
}
if (subject && !Cypress.Utils.hasElement(subject)) {
subject = null;
}
switch (false) {