Skip to content

Instantly share code, notes, and snippets.

View fearthecowboy's full-sized avatar
🏠
Happily Working from home

Garrett Serack fearthecowboy

🏠
Happily Working from home
View GitHub Profile
###
### Save this file as "install-software.ps1"
###
# check for elevated powershell
write-host -nonewline -fore cyan "Info: Verifying user is elevated:"
If (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
write-host -fore Red "NO"
return write-error "You must run this script elevated."
}
@fearthecowboy
fearthecowboy / Install-Stack.ps1
Created October 13, 2016 01:01
Install software stack.
###
### Save this file as "install-software.ps1"
###
# check for elevated powershell
write-host -nonewline -fore cyan "Info: Verifying user is elevated:"
If (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
write-host -fore Red "NO"
return write-error "You must run this script elevated."
}
@fearthecowboy
fearthecowboy / Install-dotnet.sh
Created July 11, 2016 17:42
Installing dotnet cli tools on BashOnWindows (WSL)
# do some upgrades
sudo apt-get install libstdc++6
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade
# install dotnet RTM and Preview 2 bits
sudo apt-get install curl libunwind8 gettext
curl -sSL -o dotnet.tar.gz https://go.microsoft.com/fwlink/?LinkID=809130
using System.IO;
using System.Net;
using System.Security.Cryptography.X509Certificates;
using VCSJones.FiddlerCertGen;
namespace MkCert
{
internal class Program
{
private static void Main(string[] args)
@fearthecowboy
fearthecowboy / GenerateSelfSignedCertificate.cs
Created January 5, 2016 23:05
uses GenerateSelfSignedCertificate to generate an SSL cert
public unsafe X509Certificate2 GenerateSelfSignedCertificate(PrivateKey privateKey, X500DistinguishedName dn, HashAlgorithm signatureAlgorithm, string[] dnsNames, IPAddress[] ipAddresses = null, DateTime? notBefore = null, DateTime? notAfter = null)
{
fixed (byte* dnPtr = dn.RawData)
{
var blob = new NATIVE_CRYPTOAPI_BLOB
{
cbData = (uint)dn.RawData.Length,
pbData = dnPtr
};
var signatureAlgorithmIdentifier = new CRYPT_ALGORITHM_IDENTIFIER
@fearthecowboy
fearthecowboy / Program.cs
Created January 5, 2016 18:00
Multi-platform DLLImport
using System;
using System.Runtime.InteropServices;
namespace MySample
{
internal class NativeMethods
{
// declare a delegate that fits
public delegate int MessageBoxFn(IntPtr hWnd, string text, string caption, int options);
## warning: this is not a generic script, it's tailored to what I'm doing
## but I thought I'd post it for fits and giggles.
##
## This script loads the project.json file and then looks in the nuget feeds
## to find updated versions of the packages that for each dependency.
##
## It tries to keep the packages to ones before RC2 (there are breaking changes
## in my code base that I can't move to RC2 yet)
##
## If there isn't an RC1-final, it looks for the highest RC1 build, then -beta8
namespace Pinvoke.Kernel32.Flags {
using System;
[Flags]
public enum MoveFile {
[Reference("MOVEFILE_REPLACE_EXISTING")]
ReplaceExisting = 1,
CopyAllowed = 2,
DelayUntilReboot = 4,
@fearthecowboy
fearthecowboy / BufferedMessagePackEncoder.d.ts
Created August 28, 2015 16:55
Internal module confusion...
/// <reference path="../node/node.d.ts" />
// bug: shouldn't I be able to reference stream.Writable?
// adding the import line here makes it so that the consumer can't see this class.
// import * as stream from "stream"
declare class BufferedMessagePackEncoder {
private tail;
private encoder;
private stream;
@fearthecowboy
fearthecowboy / FixTwitterBG.js
Created July 21, 2015 15:54
Greasemonkey script to fix my background on Twitter
// ==UserScript==
// @name Set background back to what it should be
// @namespace http://fearthecowboy.com
// @description Changes twitter's new image-less background to something I can stand
// @include https://twitter.com/*
// @grant none
// @version 1.0
// ==/UserScript==
function addGlobalStyle(css) {