Skip to content

Instantly share code, notes, and snippets.

function New-Prototype {
param($baseObject = (new-object object))
$prototype = [PSObject]::AsPSObject($baseObject)
$prototype.PSObject.TypeNames.Insert(0,"Prototype")
$prototype
}
filter New-Property {
param(
[string]$name,
@idavis
idavis / sample1.ps1
Created July 27, 2012 21:49
PowerShell like JavaScript
$foo = @{
Message = "This is a pre-recorded message"
}
$foo.say = {
param([string]$message)
$speaker = new-object -com SAPI.SpVoice
($speaker.Speak($message, 1)) | out-null
}
@idavis
idavis / SpinWhileExtension.cs
Created July 2, 2012 18:18
SpinWhile implemented with Rx
public static class SpinWhileExtension
{
public static IObservable<TSource> SpinWhile<TSource>(this IObservable<TSource> source, Func<bool> predicate)
{
return source.SpinWhile(predicate, TimeSpan.Zero, () => { }, () => { });
}
public static IObservable<TSource> SpinWhile<TSource>(this IObservable<TSource> source, Func<bool> predicate, TimeSpan sleep)
{
return source.SpinWhile(predicate, sleep, () => { }, () => { });
@idavis
idavis / gist:3012980
Created June 28, 2012 18:08
Trying to work with Samsung support when Kies was constantly crashing after an update.
Please wait for a Samsung Agent to respond.
You are now chatting with 'Suzanne'. There will be a brief survey at the end of our chat to share feedback on my performance today.
Your Issue ID for this chat is LTK5640844954X
Suzanne: Hi, thank you for contacting Samsung Technical Support. How may I help you today?
Visitor: I have a galaxy s2 SGH-T98
Suzanne: Please let me know how I may help you.
Visitor: I downloaded kies Kies_2.1.0.11112_41_7 from the device support site
Visitor: when I start the app. it instantly crashes every time with a MemoryAccessViolationException
Suzanne: Please let me know the issue, so that I can help you.
Visitor: I can pull out the stack track from Visual Studio if you like
@idavis
idavis / gist:2206574
Created March 26, 2012 17:14
Building fubumvc after a clone
C:\dev\fubumvc [master]> rake
rake aborted!
Run `git submodule update --init` to populate your buildsupport folder.
(See full trace by running task with --trace)
C:\dev\fubumvc [master +0 ~0 -1]> git submodule update --init
Submodule 'buildsupport' () registered for path 'buildsupport'
fatal: unable to connect to github.com:
github.com[0: 207.97.227.239]: errno=No error
@idavis
idavis / fubar.nuspec
Created March 6, 2012 02:02
Tools scripts do not work unless ANSI encoded
<?xml version="1.0"?>
<package xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<metadata xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<id>Issue1949</id>
<version>0.2.2</version>
<authors>Ian Davis</authors>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
<licenseUrl>https://raw.github.com/idavis/Toji/master/LICENSE.txt</licenseUrl>
<description>Toji is a bootstrapping project for setting up psake builds.</description>
<summary>Custom brewed psake goodness</summary>
@idavis
idavis / LateToTheParty.cs
Created February 15, 2012 18:46
True Late Binding
public class Foo {
public void Bar() {
if(IsBaz()) {
Console.WriteLine("CRAP");
} else {
Console.WriteLine("W00T");
}
}
public bool IsBaz() {
@idavis
idavis / .autotest
Created February 14, 2012 16:56
Config settings for continuous js testing
require 'autotest/growl'
require 'autotest/fsevent' if RUBY_PLATFORM =~ /darwin/
@idavis
idavis / UnitCircleSampler.cs
Created February 12, 2012 22:31
Generate Random Points Within a Unit Circle
public void Sample()
{
for ( int i = 0; i < 100; i++ )
{
Console.WriteLine(Locator.GetLocationNear());
}
}
using System;
@idavis
idavis / after.ps
Created November 28, 2011 17:55
Still needs work, but which is more readable
function Get-XADUserPasswordExpirationDate {
param ([Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true, HelpMessage="Identity of the Account")]
$accountIdentity)
$accountObj = Get-ADUser $accountIdentity -properties PasswordExpired, PasswordNeverExpires, PasswordLastSet
if ($accountObj.PasswordExpired) {
Write-Host ("Password of account: $($accountObj.Name) already expired!")
return
}