Skip to content

Instantly share code, notes, and snippets.

@simontabor
simontabor / Performance Finder.js
Created May 13, 2012 12:48
Find the connection time and response time for easy server monitoring.
try {
// connecttime is the time taken for the user agent to establish a connection to the server.
var connecttime = window.performance.timing.connectEnd - window.performance.timing.connectStart;
console.log('Connect Time: '+connecttime+'ms');
// responsetime is the time difference between recieving the first byte of data and the last byte from the server.
var responsetime = window.performance.timing.responseEnd - window.performance.timing.responseStart;
console.log('Response Time: '+responsetime+'ms');
}
catch(e) {
// some complicated shit can go on here to get the details the hard way... probably
@simontabor
simontabor / placeholder-replace.js
Created May 13, 2012 16:01
Replaces all placeholders with values if placeholders aren't supported by the browser.
if (!Modernizr.input.placeholder) {
$('input').each(function() {
if ((!($(this).val())) && ($(this).attr('placeholder'))) {
$(this).val($(this).attr('placeholder'));
$(this).attr('onclick','this.value = ""');
}
})
}
@simontabor
simontabor / ew.js
Last active December 14, 2015 11:19
Anti-auto-height-animate-awfulness
$('header .expand').on('click',function() {
var h = $('header').toggleClass('expanded');
var animate = {
'-webkit-transition':'height .2s ease-out',
'-moz-transition':'height .2s ease-out',
'transition':'height .2s ease-out'
};
if (!h.hasClass('expanded')) {
h.css(animate).height('');
@simontabor
simontabor / embed.html
Created April 19, 2013 12:06
GoSquared Embeddable Dashboard
<!DOCTYPE html>
<html>
<head>
<title>Dashboard integration example</title>
</head>
<body>
<div id="dashboard"></div>
<script>
var GS = {
dashboardContainer: '#dashboard',
@simontabor
simontabor / backbone-tracking.js
Created April 24, 2013 14:22
GoSquared Tracking for Backbone.js
var MyRouter = Backbone.Router.extend({
routes: {
// your routes
},
initialize: function() {
// we must listen to all router events and track a pageview each time
this.on('all',function() {
var mysql = require('mysql')
http = require('http'),
url = require('url');
http.createServer(function (request, response) {
// Get the query
var query = url.parse(request.url, true).query.q;
mysql.query(query, function(e, r) {
@simontabor
simontabor / keybase.md
Created May 20, 2014 13:33
keybase.md

Keybase proof

I hereby claim:

  • I am simontabor on github.
  • I am simontabor (https://keybase.io/simontabor) on keybase.
  • I have a public key whose fingerprint is 3AB5 32BF FA6D AE2B 6AA4 5AA2 48D0 7F18 B727 8097

To claim this, I am signing this object:

@simontabor
simontabor / rebalanceRedis.js
Created February 19, 2015 14:53
Redis Cluster slot balancing
var async = require('async');
var Redis = require('redis');
/*
* Rebalance a Redis cluster
*
* 1. Keeps slot allocations in blocks to maintain tidy configuration.
* 2. Moves slots to the coldest node from the hottest node, so the cluster stays healthy whilst rebalancing (`liveBalance`)
*/
@simontabor
simontabor / liveBalance-slot-order.js
Created February 19, 2015 15:01
Ordering of slot movements based on `liveBalance` parameter
[ { from: '11.11.12.71:6381', to: '11.11.12.70:6380', slot: 6553 },
{ from: '11.11.12.72:6381', to: '11.11.12.71:6381', slot: 9829 },
{ from: '11.11.12.72:6381', to: '11.11.12.70:6381', slot: 10922 },
{ from: '11.11.12.71:6380', to: '11.11.12.72:6381', slot: 16383 },
{ from: '11.11.12.70:6381', to: '11.11.12.72:6381', slot: 13321 },
{ from: '11.11.12.72:6381', to: '11.11.12.70:6381', slot: 10921 },
{ from: '11.11.12.70:6381', to: '11.11.12.72:6381', slot: 13109 },
{ from: '11.11.12.72:6381', to: '11.11.12.70:6381', slot: 10920 },
{ from: '11.11.12.70:6381', to: '11.11.12.72:6381', slot: 13110 },
{ from: '11.11.12.72:6381', to: '11.11.12.70:6381', slot: 10919 },
@simontabor
simontabor / wixTracker.html
Last active September 3, 2015 17:09
GoSquared Tracking for Wix sites (add as an iFrame widget then replace YOUR-SITE-TOKEN on line 10 with your site token)
<html>
<head>
<script src="//sslstatic.wix.com/services/js-sdk/1.43.0/js/wix.min.js"></script>
<script>
!function(g,s,q,r,d){r=g[r]=g[r]||function(){(r.q=r.q||[]).push(
arguments)};d=s.createElement(q);q=s.getElementsByTagName(q)[0];
d.src='//d1l6p2sc9645hc.cloudfront.net/tracker.js';q.parentNode.
insertBefore(d,q)}(window,document,'script','_gs');
_gs('YOUR-SITE-TOKEN', false);