Skip to content

Instantly share code, notes, and snippets.

@meleyal
meleyal / search.md
Last active December 18, 2015 07:29
Disable integrated Google search in latest Chrome

Create a new default search engine without the {google:instantExtendedEnabledParameter} token:

Before:

{google:baseURL}search?q=%s&{google:RLZ}{google:originalQueryForSuggestion}{google:assistedQueryStats}{google:searchFieldtrialParameter}{google:searchClient}{google:sourceId}{google:instantExtendedEnabledParameter}ie={inputEncoding}

After:

{google:baseURL}search?q=%s&{google:RLZ}{google:originalQueryForSuggestion}{google:assistedQueryStats}{google:searchFieldtrialParameter}{google:searchClient}{google:sourceId}ie={inputEncoding}

###
**ConditionalField** toggles the visibility of other elements
based on the state of a form field.
Usage:
<input data-show="#example1" data-unless="blank">
<input data-hide="#example2" data-if="['A', 'B', 'C']">
$('[data-if], [data-unless]').conditionalField()
###
**TextUpdater**: change the text of one or more elements when another element changes.
Usage:
<input data-updates="#price, #vat-price" data-price="40 €" data-vat-price="48 €">
<input data-updates="#price, #vat-price" data-price="80 €" data-vat-price="88 €">
$('[data-updates]').textUpdater()
Example 1:
@meleyal
meleyal / backbone-plugin-view.coffee
Created May 28, 2013 10:31
Backbone.PluginView latest
###
Backbone.PluginView
https://github.com/meleyal/backbone.pluginview
Copyright (c) 2012 William Meleyal
MIT License
Make jQuery plugins from your Backbone Views.
Backbone.PluginView extends Backbone.View with some simple helpers for creating jQuery plugins ($.fn).
@meleyal
meleyal / memory.coffee
Last active December 17, 2015 10:58
Tools for debugging memory leaks
# Get all the jQuery bound events on an element:
console.log $._data(el, 'events')
# Create and remove multiple instances of a view:
window.installTest = ->
views = []
viewClass = MyView
options = {}
@meleyal
meleyal / testing.md
Last active December 16, 2015 07:28
Notes on testing
  • If you've already wrote the code, try commenting it all out, then start testing it piece by piece.

  • Test the public API (not internal/implementation details)

  • Test as little as possible to reach a given level of confidence

  • Test the critical parts of your application

  • Test expectations not implementations

@meleyal
meleyal / view-gc-test.coffee
Last active December 16, 2015 02:48
Test Backbone views for memory leaks
window.installTest = ->
views = []
viewClass = app.NotificationsView
options = { collection: new Backbone.Collection }
views.push(new viewClass(options)) for i in [0...500]
view.remove() for view in views
views = []
console.log "#{viewClass.name} installed and removed x #{i}"
@meleyal
meleyal / plugin-gc-test.coffee
Created March 15, 2013 15:32
Test jQuery plugins for memory leaks
window.installTest = ->
for i in [0...500]
els = $('[data-behavior~=plugin]')
els.each (idx, el) -> $(el).plugin().data('plugin').uninstall()
console.log i
@meleyal
meleyal / setup-sync-sublime-over-dropbox.sh
Created December 6, 2012 22:25
Set-up Sublime settings + packages sync over Dropbox
#!/bin/sh
#
# Set-up Sublime settings + packages sync over Dropbox
#
# Will sync settings + Installed plug-ins
#
# Tested on OSX - should support Linux too as long as
# you set-up correct SOURCE folder
#
# Copyright 2012 Mikko Ohtamaa http://opensourcehacker.com
@meleyal
meleyal / jquery.draghover.js
Created September 27, 2012 13:52
jquery.draghover.js
/*
jquery.draghover.js
Emulates draghover event by tracking
dragenter / dragleave events of element + children.
https://gist.github.com/gists/3794126
http://stackoverflow.com/a/10310815/4196