Skip to content

Instantly share code, notes, and snippets.

View bradphelan's full-sized avatar

Brad Phelan bradphelan

View GitHub Profile
@bradphelan
bradphelan / Window.cs
Created February 20, 2014 08:41
Window
/// <summary>
/// Projects each element of an observable sequence into consecutive non-overlapping windows.
///
/// </summary>
/// <typeparam name="TSource">The type of the elements in the source sequence, and in the windows in the result sequence.</typeparam><typeparam name="TWindowBoundary">The type of the elements in the sequences indicating window boundary events.</typeparam><param name="source">Source sequence to produce windows over.</param><param name="windowBoundaries">Sequence of window boundary markers. The current window is closed and a new window is opened upon receiving a boundary marker.</param>
/// <returns>
/// An observable sequence of windows.
/// </returns>
/// <exception cref="T:System.ArgumentNullException"><paramref name="source"/> or <paramref name="windowBoundaries"/> is null.</exception>
public static IObservable<IObservable<TSource>> Window<TSource, TWindowBoundary>(this IObservable<TSource> source, IObservable<TWindowBoundary> windowBoundarie
@bradphelan
bradphelan / DisposeWith.cs
Created April 14, 2014 04:34
DisposeWith.cs
public static void DisposeWith( this IDisposable This, FrameworkElement control )
{
Observable.Merge
(
control.Events().Unloaded,
control.Dispatcher.Events().ShutdownStarted
)
.Take(1)
.Subscribe(e => This.Dispose());
}
public static Task<string> httpRequest(HttpWebRequest request)
{
var httpClient = new HttpClient();
var response = await httpClient.GetAsync("http://www.google.com")
return response.Content.ReadAsStringAsync();
}
@bradphelan
bradphelan / DependentTypes.cs
Created July 16, 2014 13:24
Type system abuse to simulate dependent types in C#
public interface IDigit {
int Value { get; }
}
public class _0 : IDigit { public int Value { get { return 0;} } }
public class _1 : IDigit { public int Value { get { return 1;} } }
public class _2 : IDigit { public int Value { get { return 2;} } }
public class _3 : IDigit { public int Value { get { return 3;} } }
public interface ILength {
int Value { get; }
#I @"../../lib/Fake/tools"
#r @"FakeLib.dll"
#load @"Fake.DSC.fsx"
open Fake
open System.IO
open Fake.DSC
// Fake isn't really like make even though it pretends to be. The cool thing about make
// is that it only builds stuff when it needs to be changed. Fake builds everything every time. You
root@ip-10-228-74-131:/tmp/ohai/ohai# rake gems
(in /tmp/ohai/ohai)
rake aborted!
no such file to load -- spec/rake/spectask
/tmp/ohai/ohai/Rakefile:5
(See full trace by running task with --trace)
root@ip-10-228-75-101:/tmp/ohai# ohai domain
/usr/lib/ruby/1.8/logger.rb:314:in `<': comparison of Fixnum with :info failed (ArgumentError)
from /usr/lib/ruby/1.8/logger.rb:314:in `add'
from /usr/lib/ruby/1.8/logger.rb:348:in `debug'
from /usr/lib/ruby/gems/1.8/gems/mixlib-log-1.0.3/lib/mixlib/log.rb:70:in `send'
from /usr/lib/ruby/gems/1.8/gems/mixlib-log-1.0.3/lib/mixlib/log.rb:70:in `method_missing'
from /usr/lib/ruby/gems/1.8/gems/ohai-0.3.7/lib/ohai/system.rb:192:in `require_plugin'
from /usr/lib/ruby/gems/1.8/gems/ohai-0.3.7/lib/ohai/system.rb:182:in `each'
from /usr/lib/ruby/gems/1.8/gems/ohai-0.3.7/lib/ohai/system.rb:182:in `require_plugin'
from /usr/lib/ruby/gems/1.8/gems/ohai-0.3.7/lib/ohai/system.rb:116:in `all_plugins'
^[[Aroot@ip-10-228-75-101:~# . install.sh 2>&1 | tee log
Hit http://ppa.launchpad.net jaunty Release.gpg
Ign http://ppa.launchpad.net jaunty/main Translation-en_US
Hit http://security.ubuntu.com jaunty-security Release.gpg
Ign http://security.ubuntu.com jaunty-security/main Translation-en_US
Hit http://ppa.launchpad.net jaunty Release
Ign http://security.ubuntu.com jaunty-security/restricted Translation-en_US
Ign http://security.ubuntu.com jaunty-security/universe Translation-en_US
Ign http://security.ubuntu.com jaunty-security/multiverse Translation-en_US
Hit http://security.ubuntu.com jaunty-security Release
# site-cookbooks/awssecrets/attrbutes/default.rb
# Trying to provide a common recipe and error checking
# to make sure the AWS secrets are there.
if not self.key? :awssecrets or not self[:awssecrets].key? :access_key or not self[:awssecrets].key? :secret_key
raise <<-EOF
Please set the awssecrets[:accesskey] and awssecrets[:secretkey] attributes
EOF
end
# ec2 ami-1515f67c
sudo sed -i 's/universe/multiverse universe/' /etc/apt/sources.list
sudo apt-get update
sudo apt-get install -y ruby ruby1.8-dev libopenssl-ruby1.8 rdoc ri irb build-essential wget ssl-cert rubygems git-core rake librspec-ruby libxml-ruby thin zlib1g-dev libxml2-dev
sudo gem sources -a http://gems.opscode.com
sudo gem install cucumber merb-core jeweler uuidtools json libxml-ruby --no-ri --no-rdoc
mkdir ~/src
cd ~/src
git clone git://github.com/opscode/chef.git
git clone git://github.com/opscode/ohai.git