Skip to content

Instantly share code, notes, and snippets.

View slashdotdash's full-sized avatar

Ben Smith slashdotdash

View GitHub Profile
@slashdotdash
slashdotdash / gist:74299
Created March 5, 2009 11:05
jQuer Polling Plugin
// jQuery Polling Plugin
// http://www.buntin.org/2008/sep/23/jquery-polling-plugin/
(function($) {
$.fn.poll = function(options){
var $this = $(this);
// extend our default options with those provided
var opts = $.extend({}, $.fn.poll.defaults, options);
setInterval(update, opts.interval);
// method used to update element html
/// <summary>
/// Draw a progress bar at the current cursor position.
/// Be careful not to Console.WriteLine or anything whilst using this to show progress!
/// </summary>
/// <param name="progress">The position of the bar</param>
/// <param name="total">The amount it counts</param>
private static void DrawTextProgressBar(int progress, int total)
{
//draw empty progress bar
Console.CursorLeft = 0;
@slashdotdash
slashdotdash / gist:190361
Created September 21, 2009 16:29
MySQL, Alter Table, and How to Observe Progress
#!/bin/bash
(while(true); do \
(mysql -e 'show innodb status \G' | grep undo\ log\ entries ; sleep 1 ; \
mysql -e 'show innodb status \G' | grep undo\ log\ entries ) | \
egrep '[0-9][0-9][0-9][0-9]' |awk '{print $10;}' ; done ) | \
perl -e '$t = ROWS_IN_TABLE; while(1) { \
$n ++; $nn; $a = <>; $b = <>; $nn += ($b-$a); \
printf "Rate: %d, avg: %d, %0.3f%% complete, done in %d sec\n", \
$b-$a, $nn/$n, ($b/$t)*100, ($t-$b)/($nn/$n); }';
@slashdotdash
slashdotdash / JavaScript Singleton
Created December 14, 2009 15:57
JavaScript Singleton
// http://prototyp.ical.ly/index.php/2007/03/01/javascript-design-patterns-1-the-singleton/
// http://books.google.co.uk/books?id=za3vlnlWxb0C&printsec=frontcover&source=gbs_navlinks_s#v=onepage&q=singleton&f=false
var mySingleton = function()
{
/* private attributes */
var _created = new Date();
/* private methods */
var _calculateAge = function()
{
# http://www.makemacwork.com/disable-automatic-updates.htm
for USER in `ls -1 /Users | \
sed -e '/Shared/d' -e '/Deleted Users/d' -e '/.localized/d'`; \
do \
sudo -u $USER softwareupdate --schedule off; \
done
/**
* ## Merging mixin views in backbone.js ##
*
* really just more a test for tumblr gistr
*/
/**
* Merge the mixin (a Backbone.View) into another Backbone.View. Automatically merge events, defaults, and call the parent initializer.
**/
function mergeMixin(view, mixin) {
@slashdotdash
slashdotdash / index.html
Last active August 25, 2017 01:30
React + D3
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>React + D3</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.2/underscore.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/react/0.8.0/react.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/react/0.8.0/JSXTransformer.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/d3/3.3.13/d3.js"></script>
@slashdotdash
slashdotdash / README.md
Last active September 19, 2019 18:30
React + D3 (v2)

Multi-series bar chart rendered using React and D3.

@slashdotdash
slashdotdash / README.md
Last active April 9, 2019 12:52
React + D3 (v3)

Multi-series line chart rendered using React and D3.

@slashdotdash
slashdotdash / Gruntfile.js
Created February 19, 2014 22:15
Grunt config to with task to compile React .jsx files to .js
/*global module:false*/
module.exports = function(grunt) {
grunt.initConfig({
react: {
jsx: {
files: [
{
expand: true,
cwd: 'public/js',