Character encoding is annoying but necessary. Here's code for standardized byte order marks (BOM)
Just a quick starter project in C-style C++ with SDL2, OpenGL 3, and Dear ImGui. This came about from deciding to make a sudoku game for my wife, getting all the necessary libraries setup with CMake was a pain so this serves as a starting point for next time.
This code generates a function that will load the assembly into the current PowerShell session. Yes it's a dumb idea but when your team lead tells you "we can't copy a dll file to every server your script needs to run on.", this is what happens.
After something being wayyyy easier than I thought it was going to be, I’m ready to claim that PowerShell is better when not used on Windows. I submit the following 1-liner as evidence.
There are times where you'd like to create a dummy file for testing, if you're on Windows you may be familiar with the 'fsutil file createnew' command. This allows you to create a zero filled file of a predefined size, fantastic. It's a small, but powerful, command that is included with every Windows install but let's assume you need a PowerShell native method for creating a zero filled file, what might that look like?
This is a simple PowerShell function that performs an http GET against a sepcified URL, validates a few things about the x509 certificate and returns an object indicating whether the cert is valid and will expires soon. Here's the code.
The following is simply a copy of the README.md from my latest project found here, I hope you find it useful.
The following code will attempt to find a Domain Controller that is site-local to the current computer. The only dependencies are PowerShell v3 and the ActiveDirectory module.
I recently needed a good way of picking from a list of volumes, free space and directory count where factors. I would almost expect that computing standard deviation and variance for a set of numbers would be built in to System.Math but in their absence, this is what I've come up with.
Here's the Excel Dupes function from a previous post with some extra features to identify the desired column and a simple GUI. I'm am currently working on code to get this deployed as an Excel add-in invoked by a ribbon button and will post a follow-up when that's complete. In the mean time, this is the code and can be wired to buttons from inside the VBA developer tools.
This is not comprehensive or flexible, it's a quick hack that saved me some time. It loops over the first cell of each row and highlights sets that are duplicate values (tip, do an extended sort on the first column before executing). Here you go.
I reccently found the need to rip the audio from a video file (good for some conference talks), the issue is this, FFMPEG doesn't always have the codec you need. Thankfully I've purchased the Fluendo codec pack for gstreamer, the do stuff with video/audio backend. The following command sets up the gstreamer pipeline for processing the audio all the way from decoding the video to reencoding into an ogg vorbis file. The gst-launch man page has plenty of details on setting up the pipeline, there is tons of power here and I've found better performance on my system than with FFMPEG for audio and video transcoding.
If you're writing a data heavy utility in PowerShell and it's gonna stick around for a while, you've probably run into memory problems. Hope is hidden right under the PowerShell covers, the .Net CLR.
Hot code loading is a feature of languages that allows a developer to load new code into a running system without stopping the process. This has some clear benefits on servers, security and feature patches can be added without a risk of downtime. Yes, building your application in a way that you can fail over to a secondary system but that never seemed kosher to me as a patching strategy unless you're working at scale and already account for high availablity. I've implemented some long runner server software in PowerShell and using some of the features it's gleaned from Unix scripting you can hot load new code into them on the fly.
While dipping my toes into F# some time ago, I ran into a compile-time error that I couldn't explain or find a solution for...
I've been using Hyper-V for development work lately and it's been fine, just like any other hypervisor. However, there is one nagging issue, numlock gets disabled when jumping between guests. What the heck? I haven't experienced this behavior with KVM, VirtualBox or VMWare and it's really not worth figuring out the cause when PowerShell can keep your numlock enabled.
When you're asked to generate a quick report from a bunch of data that's stored in CSV files you think, "Hey that's what spreadsheets are good at.", or if it's a lot of CSV files, "That's what PowerShell is good at." I only offer this as a caution, while it can do it, sometimes it still shouldn't be done. The PowerShell ISE get's a little dodgy when it's using more than 4 GB of data.
Have you ever needed to grep to a ton of logs that reference AD objects, fetch those objects from AD and build a report? No?... Well let's just say you have. That can get pretty slow and round tripping to your local friendly domain controller can get out of hand. There are some easy ways to avoid making unnessessary queries, here's one of them.
The other day I was making some wooden supports for my son's toy train set, snapped a few pictures when I thought, "It would be great if I could upload this to my website". This site uses Mezzanine CMS, it's written on top of the Django framework and has a nifty file uploader written in Flash, my iPhone can't use Flash. This sounds like a fun problem to solve for myself, if nothing else it will be a learning experience.
https://help.disqus.com/customer/portal/articles/542119
If you're a .Net developer and an Open Source enthusiast, these past couple of weeks have been really exciting for you. .Net CLR and core libraries have been relicensed under the MIT license, and they've announced a forthcoming .Net CoreRT that will be truly cross platform...
From time to time you may want to deligate control of an AD security group to an unprivileged user. Business people like this because it allows them to be in control of resources they consume, IT people like this because we don't have to handle support tickets to add people to a group. Ok, we can all agree that this may be a good idea; now lets say you want to automate this process. PowerShell has great AD integration and if that doesn't work it's just LDAP right? Well kind of, I'll show you what I mean by that.
On the MWA Podcast when asked about a Unisaw (power saw) his response was, "Real men use alcohol powered tools."
When writing a Powershell script that will be running for an extended period of time, you should be aware of how to scope your variables to be garbage collection friendly. PowerShell itself is written on the .Net framework butits GC is a bit different.
So as a follow up to my previous post about enumerating DFS namespaces with C#, here's a PowerShell wrapper around that function. It's implemented as a PowerShell advanced function with some Get-Help documentation. I hope you find it useful. (If you don't see any code below, try refreshing, Github can be hit or miss)
At work, word has gotten out that I like to program, so being a system administrator I write a lot of PowerShell. I've used/shoehorned it into projects where it didn't really belong and have experienced some strange behavior from the PowerShell ISE that I thought I'd share before you fall into the same rabbit hole.
I've been writing some software to manage DFS links from .Net and historically I've parsed the output of dfsutil.exe to get my information but this can be unreliable, so what to do? Win32 to the rescue with .Net native interop. This has been a painful process since I do not know C and have limited experience with the Win32 api so I hope this can help people. The code will return a List<struct> representing the information I want out of the DFS query...
{ "Why would any self respecting Linux enthusiast use .Net for anything? The short answer can be summed up in one word": "Mono." }
Steve Ballmer reccently stepped down from the board at Microsoft and a few tech sites reported this as being unexpected. It seems mainstream media is suffering from short-term memory loss; no one can remember what happened more than 2 years ago, 2 months is about the limit. Too much has happened over the past few years to view current headlines in an appropriate context so I thought I'd help remind people what Balmer was up to at MS.
I hate pretty much all diagramming tools. Visio is too expensive, Dia uses an ancient version of GTK+ and crashes when exporting, Calligra Flow crashes a lot and doesn't work on anything but KDE, LibreOffice Draw is pretty much the only one that isn't completely terrible but the canvas size is fixed and it defaults back to the selector tool after every operation. However, this whole HTML5 thing is finally starting to pay off.
So when I say the language doesn't matter, that doesn't mean programming languages don't have certain advantages but until you really understand a few languages, advantages don't matter. Understanding a system well enough to solve 90+ percent of your computing problems is more important. With most modern languages you can implement just about anything...
One of the things that really confused me when I was first learning to program is the notion of an object. Put simply, objects are an organizational tool. They are for all intents and purposes unnessesary, but they make things much easier for us as human beings to reason about what the computer is doing; it allows us to think of a physical form even though it really breaks down to ephemeral bits on silicon.
This is where I've decided to put things I don't want to forget. After using everyone elses services for keeping notes and not being satisfied with the lack of cross platform support from any of them (the Chrome web-app for Evernote doesn't count as a Linux client), I've decided to buck up and run my own server.
I'm a system administrator by trade but I've always had an interest in programming and want to get into the software business. After a few years of more coding than admin work, there are a few things I wish someone had told me.