Skip to content

Instantly share code, notes, and snippets.

View BenConstable's full-sized avatar

Ben Constable BenConstable

  • Mediatonic
  • Fareham, UK
  • 06:29 (UTC +01:00)
View GitHub Profile
@BenConstable
BenConstable / backbone-bootstrap.js
Created June 25, 2012 13:15
Neat wrapper for Backbone.js application bootstrapping. Very basic but works nicely!
/*
* Wrap up the Backbone application in a simple interface
*/
// Using Jquery...
(function ($) {
// Create application
var MyApp = (function () {
@BenConstable
BenConstable / dotfiles.rb
Created July 22, 2012 12:39
Simple script to link dotfiles stored in Dropbox to the local home directory
# Link dotfiles
dropboxPath = File.expand_path(File.dirname(__FILE__))
targetPath = File.expand_path('~')
files = 0
Dir.foreach(dropboxPath) do |file|
if (file != '.') && (file != '..') && (file != File.basename(__FILE__))
%x[ln -sF #{dropboxPath}/#{file} #{targetPath}/#{file}]
files += 1
end
@BenConstable
BenConstable / move-commits.sh
Created November 9, 2012 10:41
Move commits onto feature branch
#
# If, for example, you've accidentally made some commits to master
# that should be on a feature branch, this set of commands will
# move those commits over to a feature branch and reset master to
# where it should be both locally and on the remote.
#
# References:
#
# - http://stackoverflow.com/questions/1628563/move-recent-commit-to-a-new-branch
# - http://stackoverflow.com/questions/1377845/git-reset-hard-and-a-remote-repository
@BenConstable
BenConstable / git-merge-feature
Last active December 9, 2015 23:38
After a Pull Request of yours is merged, you will want to make sure that your master branch has the changes, and that the feature branch you were working on gets properly tidied up. This simple Git extension does just that.
#!/bin/sh
#
# This script deletes a feature branch you've been
# working on, assuming that it's been merged as part
# of a Pull Request, and pulls it into your master
# branch.
#
# You need a typical setup, and a reference to the
# forked repo, called `upstream`.
@BenConstable
BenConstable / jquery-autocomplete-blur.js
Created January 15, 2013 22:30
Make the jQuery UI Autocomplete widget appear on blur, not keypress.
/*
* Use the small setup below to make the
* jQuery Autocomplete widget show on input-blur,
* rather than on every keypress.
*/
(function ($) {
var field = $('.selector');
field.autocomplete({
@BenConstable
BenConstable / external-tabs.html
Last active December 16, 2015 09:18
Allow jQuery UI Tabs that act as regular links.
<ul class="ui-tabs">
<li>
<a href="#tab-1">My Tab 1</a>
</li>
<li>
<a href="#tab-2">My Tab 2</a>
</li>
<li>
<a data-external="http://www.example.com">My External Tab</a>
</li>
@BenConstable
BenConstable / db-size.sql
Last active December 16, 2015 12:18
Little MySQL query to find the size of database.
# Adapted from http://stackoverflow.com/questions/1733507/how-to-get-size-of-mysql-database
SELECT Round(Sum(data_length + index_length) / 1024 / 1024, 1) "DB Size in MB"
FROM information_schema.tables
WHERE table_schema = "database_name" # Replace this with the name of the database you want to inspect
GROUP BY table_schema;
@BenConstable
BenConstable / rvm_to_rbenv.md
Created November 23, 2013 16:54
Switching from RVM to rbenv on Mavericks

Moving from RVM to rbenv on Mavericks

These are the few steps I ran to completely remove RVM and install rbenv:

Remove RVM

To remove pretty much everything:

$ rvm implode
@BenConstable
BenConstable / app.js
Created December 30, 2013 13:40
Control Aruduino over WebSocket.
var express = require('express')
, app = express()
, server = require('http').createServer(app)
, io = require('socket.io').listen(server)
, five = require('johnny-five')
, board = new five.Board({ port:'/dev/tty.usbmodemfa131'} )
, led;
// Listen for lights change
io.sockets.on('connection', function (socket) {
@BenConstable
BenConstable / view.js
Last active August 29, 2015 14:02
Backbone events example
var MyView = Backbone.View.extend({
events: function () {
var mobile = false
if (mobile) {
return {
"touch": function () { console.log('touched') }
}
} else {