Skip to content

Instantly share code, notes, and snippets.

View danielmoore's full-sized avatar

Daniel Moore danielmoore

View GitHub Profile
# Git functions
# Mark Embling (http://www.markembling.info/)
# Is the current directory a git repository/working copy?
function isCurrentDirectoryGitRepository {
if ((Test-Path ".git") -eq $TRUE) {
return $TRUE
}
# Test within parent dirs
Get-ChildItem $psScriptRoot -filter *.ps1 | foreach { . $_.FullName }
if(Get-Module prompt) { Remove-Module prompt }
$prompt_kind = if($args[0]) { $args[0] } else { "bash" }
if($prompt_kind -eq "bash") {
function prompt {
@danielmoore
danielmoore / gist:961532
Created May 8, 2011 17:43
Testing light compile for INPC to RX
public static class NotifyPropertyChangedExtensions
{
public static IObservable<TProp> GetPropertyChanges<TSource, TProp>(this TSource source, Expression<Func<TSource, TProp>> propertySelector, bool lightCompile = true)
where TSource : INotifyPropertyChanged
{
var propertyName = GetPropertyName(propertySelector);
return Observable
.FromEvent<PropertyChangedEventHandler, PropertyChangedEventArgs>(
h => new PropertyChangedEventHandler((s, e) => h(e)),
@danielmoore
danielmoore / gist:987860
Created May 23, 2011 23:32
Transcript trying to run WPK Hello World
**********************
Windows PowerShell Transcript Start
Start time: 20110523192949
Username : NORTHHORIZON\daniel
Machine : POLARIS (Microsoft Windows NT 6.1.7601 Service Pack 1)
**********************
Transcript started, output file is C:\Users\daniel\Documents\PowerShell_transcript.20110523192949.txt
PS C:\Users\daniel>
2 > Import-Module powershellpack
PS C:\Users\daniel>
@danielmoore
danielmoore / New-PieChart.ps1
Created May 28, 2011 22:58
Creates a new pie chart using WPK
param([string] $CountProperty = 'Count',
[string] $NameProperty = 'Name',
[double] $Width = 400,
[double] $Height = 300,
[string] $WindowTitle = 'Pie Graph',
[string] $ChartTitle = $null,
[Parameter(ValueFromPipeline = $true)] $Items,
[switch] $Show = $false)
begin {
Import-Module wpk
@danielmoore
danielmoore / IsAlives.cs
Created May 29, 2011 07:05 — forked from ScottWeinstein/IsAlives.cs
Rx IsAlive UnitTests
// doesn't detect Never()
public static IObservable<bool> IsAlive_Merge<T>(this IObservable<T> source, TimeSpan timeout, IScheduler sched)
{
return source.Select(_ => true)
.Merge(source.Select(_ => false).Throttle(timeout, sched))
.DistinctUntilChanged();
}
// D.Moore, 29 May: using the buffer count should cause this to fire as soon as it's available.
public static IObservable<bool> IsAlive_Buffer<T>(this IObservable<T> source, TimeSpan timeout, IScheduler sched)
@danielmoore
danielmoore / gist:1068800
Created July 7, 2011 02:31
Scheduler Testing
Console.ReadLine();
var sched = Scheduler.TaskPool;
var count = Observable
.Return(new Unit(), sched)
.Repeat()
// Use NewThread to avoid bias on the cutoff.
.TakeUntil(Observable.Timer(TimeSpan.FromSeconds(5), Scheduler.NewThread))
.Count()
@danielmoore
danielmoore / gist:1074060
Created July 9, 2011 23:36
bad code style?
private bool IsIncluded(LazyMemberInfo memberInfo)
{
var accessors = memberInfo.GetAccessors().Where(a => a != null);
var types = accessors.Select(m => m as Type ?? m.DeclaringType);
var assemblies = types.Select(t => t.Assembly).Distinct().Where(a => a != null);
var scopeSets = new[]
{
// Local Scopes
@danielmoore
danielmoore / Get-MeetupRsvps.ps1
Created July 19, 2011 00:16
Gets a list of meetup RSVPs using the meetup API.
function Get-MeetupRsvps([string]$eventId, [string]$apiKey) {
$nameWord = "[\w-']{2,}"
$regex = "^(?'first'$nameWord) ((\w\.?|($nameWord )+) )?(?'last'$nameWord)|(?'last'$nameWord), ?(?'first'$nameWord)( \w\.|( $nameWord)+)?$"
function Get-AttendeeInfo {
process {
$matches = $null
$answer = $_.answers.answers_item
if(-not ($_.name -match $regex)) { $answer -match $regex | Out-Null }
@danielmoore
danielmoore / gist:1182831
Created August 31, 2011 04:36
double click mouse move in RX and WPF
var target = new Border{ Background = Brushes.SteelBlue, Width = 200, Height = 200 };
var win = new Window{ Content = target };
var mouseDown = Observable.FromEventPattern<MouseEventArgs>(target, "MouseLeftButtonDown");
var mouseMove = Observable.FromEventPattern<MouseEventArgs>(target, "MouseMove");
var mouseUp = Observable.FromEventPattern<MouseEventArgs>(target, "MouseLeftButtonUp");
// dragEvents is IObservable<IObservable<EventPattern<MouseMoveEvent>>>
// The first dimmension represents the sequence of discrete drag "sessions"
// The second dimmension represents the sequence of moves within that drag