Skip to content

Instantly share code, notes, and snippets.

View Jaykul's full-sized avatar
😀
Learning

Joel Bennett Jaykul

😀
Learning
View GitHub Profile
@Jaykul
Jaykul / appserver\static\autodiscover.js
Created November 13, 2014 03:38
Simple Simple Tricks
require.config({
paths: {
"app": "../app"
}
});
require(['splunkjs/mvc/simplexml/ready!'], function(){
require(['splunkjs/ready!'], function(){
// The splunkjs/ready loader script will automatically instantiate all elements
// declared in the dashboard's HTML.
@Jaykul
Jaykul / Search Updates.ps1
Created November 15, 2014 00:34
Remote Windows Updates
param(
[string[]]$ComputerName = ".",
[Parameter(Mandatory)]
[Management.Automation.Credential()]
[PSCredential]$Credential
)
$sessions = New-PSSession -ComputerName:$ComputerName -Credential:$Credential
@Jaykul
Jaykul / Test-Debug.ps1
Created November 30, 2014 01:48
The cost of Write-Debug when you're not debugging
function Test-DebugPreference {
[CmdletBinding()]
param($count = 1e5)
$Counter = 0
for($i = 0; $i -lt $count; $i++) {
if($DebugPreference -gt "SilentlyContinue") {
$Counter += 1
Write-Debug "The Counter is $Counter"
}
@Jaykul
Jaykul / fileinfo.ps1
Created March 18, 2015 21:10
PIpelineExample
function filesystem {
param(
[Parameter(ParameterSetName="Dirs",ValueFromPipeline)]
[System.IO.DirectoryInfo]$Directory,
[Parameter(ParameterSetName="Files",ValueFromPipeline)]
[System.IO.FileInfo]$File
)
process {
switch ($PSCmdlet.ParameterSetName) {
@Jaykul
Jaykul / Test-Error.ps1
Last active August 29, 2015 14:20
Exceptions and Errors
&{
[CmdletBinding()]param()
&{[CmdletBinding()]param() Write-Error "Demo Error 1" } -EA 0 -EV e;
$PSCmdlet.WriteError($e[0]);
1/0
&{[CmdletBinding()]param() Write-Error "Demo Error 2" } -EA 0 -EV e;
$PSCmdlet.ThrowTerminatingError($e[0])
@Jaykul
Jaykul / Some.ps1
Created May 6, 2015 00:22
Exceptions and Errors
[324]: try {
· try{
· throw [System.Management.Automation.ParameterBindingException]::new( "whatever",
· [System.Management.Automation.ItemNotFoundException]::new("File Not Found"))
· } catch{ throw $_}
· } catch [System.Management.Automation.ParameterBindingException] { "PBE" }
· catch [System.Management.Automation.ItemNotFoundException] { "INFE" }
PBE
[325]:
@Jaykul
Jaykul / testPalindrome
Created August 2, 2012 01:24
Test-Palindrome
def testPalindrome(p):
p = str(p)
return not any([True for i in range(0,len(p)/2) if p[i] <> p[-i-1]])
@Jaykul
Jaykul / Demo.ps1
Last active November 24, 2015 00:49
PowerShell 5 Classes (v 10586)
PS> mkdir ClassContainer
Directory: C:\Users\Joel\Documents\WindowsPowerShell\TestData\modules
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 11/23/2015 7:41 PM ClassContainer
@Jaykul
Jaykul / Response.xml
Created January 8, 2014 20:54
The problem with ...
<?xml version="1.0" encoding="utf-8"?>
<feed xml:base="http://bd-xd7-01/Citrix/Monitor/OData/v1/Data/" xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<id>http://bd-xd7-01/Citrix/Monitor/OData/v1/Data/Sessions</id>
<title type="text">Sessions</title>
<updated>2014-01-08T20:19:50Z</updated>
<link rel="self" title="Sessions" href="Sessions" />
<entry>
<id>http://bd-xd7-01/Citrix/Monitor/OData/v1/Data/Sessions(guid'5a84b30a-9190-4013-b458-81d64633c996')</id>
<category term="Citrix.Monitor.Repository.Session" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
<link rel="edit" title="Session" href="Sessions(guid'5a84b30a-9190-4013-b458-81d64633c996')" />
@Jaykul
Jaykul / Catalog.cs
Last active January 22, 2016 21:01
The wonderful world of CliXml output
// You can output any simple .Net Object that you like
using System;
using System.Collections.Generic;
using System.Management.Automation;
namespace PoshCode
{
// A data object we're going to output
public class Vehicle
{