Skip to content

Instantly share code, notes, and snippets.

@sean-m
sean-m / ensure-package-installed.el
Last active August 29, 2015 13:55
function for installing emacs packages, copied from here: https://bigmac.caelum.uberspace.de/paste/ensure-package-installed.html
(defun ensure-package-installed (&rest packages)
"Assure every package is installed, ask for installation if it’s not.
Return a list of installed packages or nil for every package not installed."
(mapcar
(lambda (package)
(package-installed-p 'evil)
(if (package-installed-p package)
package
(if (y-or-n-p (format "Package %s is missing. Install it? " package))
(package-install package)
@sean-m
sean-m / set-visual-svn-permission.ps1
Last active April 28, 2019 20:51
PowerShell code for adding AD groups to a VisualSVN repository using the WMI provider. This allows you to manage the repository access with Active Directory groups in ADUC, a huge deal inside large enterprises. I implemented this as part of a new repository creation script that setups up the AD groups, this was the only part with enough difficul…
<#
SVN Access Level Enum Values
----------------------------
No Access = 0
Read Only = 1
Read Write = 2
#>
@sean-m
sean-m / log-reader-config.ps1
Created May 13, 2014 19:25
Read Windows event logs with Get-WinEvent cmd-let and serialize to json for shipping with logstash-forwarder. Much lighter weight than using logstash with the eventlog codec. Runtime memory usage is ~30Mb vs ~320Mb. Note: must be run with elevated privileges to read Security event logs.
<#
Configuration for log-reader.ps1
This file is only read if log-reader.ps1 is invoked without arguments
from the command-line. This file will configure any tunable variabes
in log-reader.ps1. Thus far, the only setting is which logs to track.
#>
[string[]]$logname = $("Application", "System", "Security")
@sean-m
sean-m / Add-ModAce.ps1
Created August 6, 2014 23:51
Function for adding access control entries to an ACL object. These entries deny access to modify a directory but gives liberal access to its contents. Good for Windows file shares.
## Takes and ACL and SID, returns an ACL with the correct entries for modify permissions added.
function Add-ModAce {
param (
[Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelinebyPropertyName=$true)]
[System.Security.AccessControl.FileSystemSecurity]$ACL,
[Parameter(Position=1, Mandatory=$true, ValueFromPipeline=$false, ValueFromPipelinebyPropertyName=$true)]
[System.Security.Principal.IdentityReference]$SID
)
# Rule applies to parent container, does not propagate
@sean-m
sean-m / get_pw.cs
Created August 27, 2014 17:14
C# console app password entry logic. Not secured.
/*
* Allow user to enter password
*/
Console.Write ("Please enter your password (12 - 256 chars)\nand press (Enter|Return): ");
bool entered = false;
ConsoleKeyInfo pwIn;
string pw;
StringBuilder sb = new StringBuilder ();
do {
pwIn = Console.ReadKey ();
@sean-m
sean-m / GetDfsLinks.cs
Created September 24, 2014 08:36
C# native interop function which calls NetDfsEnum and returns a list of structs representing the DFS links. You get the name and a string[] of the link's targets for each DFS link in the namespace. I check and only return the links which are in a valid state.
@sean-m
sean-m / Get-DfsLinks.ps1
Last active August 29, 2015 14:08
PowerShell wrapper around NetDfsEnum to get a list of links in a DFS namespace. Works with .Net 3 for people who can't use the Dfsn cmdlets for some reason.
@sean-m
sean-m / Set-GroupManager.ps1
Last active July 11, 2024 17:27
Function takes the DN of a group and DN of user as input, sets the group manager as the prescribed user and checks that pesky "can modify group membership" box.
<#
.Synopsis
Takes Group DNs and User DNs and sets the user(s) as managers of the group(s).
.DESCRIPTION
Only changes needed for the group's configuration to match the request are
made, that is if the group already has the same managers in the specified
positions (managedBy vs msExchCoManagedByLink) then nothing is modified.
If no property changes are needed but the rights aren't set correctly,
the necessary ACL rules are applied and extraneous rules are removed.
@sean-m
sean-m / ps-anon.ps1
Created June 20, 2015 03:22
Pseudo anonymous functions in PowerShell for live code loading/patching.
$cd = $(Split-Path -parent $MyInvocation.MyCommand.Definition)
cd $cd
<#
Code that doesn't change goes in this file which just
loads functions and executes them. The function loading
logic could even exist in another while which is dot-included.
#>
@sean-m
sean-m / join-spreadsheet.cs
Last active November 29, 2016 18:56
Simple command line utility for merging spreadsheets and addings some formatting. There are bugs and some exceptions are not handled gracefully, in my case it does what I need so here's some scissors, start running. Needs Excel 2010+ and .Net 3.5.
using System;
using System.IO;
using System.Linq;
using Microsoft.Office.Interop.Excel;
/* Simple command line utility for merging spreadsheets and
* addings some formatting. There are bugs and some exceptions
* are not handled gracefully, in my case it does what I need
* so here it is.
* -Sean McArdle