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 / 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 / Vagrantfile
Created February 10, 2016 16:23 — forked from ndemonner/Vagrantfile
Sample Vagrantfile for easy Elixir-based development
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.network "private_network", ip: "192.168.33.10"
config.vm.provision "shell", inline: <<-SHELL
wget https://packages.erlang-solutions.com/erlang-solutions_1.0_all.deb && sudo dpkg -i erlang-solutions_1.0_all.deb
sudo apt-get update
sudo apt-get install -y nodejs
# Aggregates are just collections of command functions, which emit events,
# and event handlers, which mutate state.
# In order to hold state, they should be also structs.
# There is no new() function because aggregates aren't supposed to appear
# out of the blue, they are always the result of a command.
# In this case, %OpenAccount{}.
defmodule Bank.Account do
defstruct [:account_number, :balance]
@slashdotdash
slashdotdash / README.md
Last active July 21, 2017 12:29
Domain-driven design shipping example implemented using Commanded

Domain-driven design shipping example implemented using Commanded

Inspired by Peter C Marks' ddd_elixir_stage1_umbrella repo.

I've implemented the cargo event handling workflow using the approach dictated by the Commanded CQRS/ES library for Elixir.

The flow is as follows:

  1. HandlingEventController web controller constructs a TrackHandling command struct from given POST params.
  2. TrackHandling command is dispatched using the CommandRouter, which has configured the command to handler/aggregate mapping.
@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 / cart.ex
Last active September 14, 2017 10:35
Example shopping cart aggregate using Chronik
defmodule Example.Cart do
use Chronik.Aggregate
alias Example.Cart
alias Example.DomainEvents.{CartCreated, ItemsAdded, ItemsRemoved}
defstruct [id: nil, items: %{}]
## Public API