Skip to content

Instantly share code, notes, and snippets.

@rjmholt
rjmholt / clone_repos.py
Last active January 3, 2017 04:51
Clones all the repos of a GitHub user, using the GitHub API
#!/usr/bin/python3
import urllib.request
import json
import subprocess
"""
Small python script to download all of someone's github repos
"""
GITHUB_USERNAME=''
public interface IN<in U> {}
public interface IC<X> : IN<IN<IC<IC<X>>>> {}
class Program
{
static void Main()
{
IC<double> bar = null;
IN<IC<string>> foo = bar;
}
public class Undecidable
{
class T {}
class N<Z> {}
class C<X> extends N<N<? super C<C<X>>>>
{
private N<? super C<T>> cast(C<T> c)
{
{-# LANGUAGE
MultiParamTypeClasses,
FunctionalDependencies,
FlexibleInstances,
TypeFamilies #-}
class Mul' a b where
type MulT a b
mul' :: a -> b -> MulT a b
@rjmholt
rjmholt / Restore-PwshVsix.ps1
Last active December 26, 2023 10:09
PowerShell script to build the PowerShell VSCode extension
# Copyright (c) Microsoft. All rights reserved.
# Licensed under the MIT license.
# Requires PowerShell, git and VSCode
param(
[switch]$NoPackage,
[switch]$LaunchVSCode
)
@rjmholt
rjmholt / PssaRunspacePoolCreate.cs
Created June 5, 2018 16:29
Better PSScriptAnalyzer runspace pool creation
private static RunspacePool CreatePssaRunspacePool()
{
// Use public but unfriendly APIs to import a PSScriptAnalyzer module with the needed minimum version
var pssaModuleSpec = new ModuleSpecification(new Hashtable()
{
{ "ModuleName", PSSA_MODULE_NAME },
{ "ModuleVersion", s_pssaMinimumVersion }
});
@rjmholt
rjmholt / AclStuff.ps1
Last active July 17, 2018 22:46
Script for ACL-ing things to the current user in PowerShell
param(
[ValidateNotNullOrEmpty()]
[string]$KeyFileName,
[ValidateNotNullOrEmpty()]
[string]$KeyFileDir = $null
)
# Test if the given Windows Identity is the Built-in Administrator
function Test-IsAdministrator
{
@rjmholt
rjmholt / AuthenticationValidator.cs
Last active July 17, 2018 22:47
C# snippet for doing HMAC-based authentication
using System;
using System.Collections.Generic;
using System.IO;
using System.Security.Cryptography;
using System.Text;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol
{
@rjmholt
rjmholt / PsesHelpers.ps1
Created September 17, 2018 19:53
Helper functions deleted from a PSES PR that might come in handy later
function Enable-WritingToPath {
param([string]$Path)
# This is not a problem on Windows
if (-not ($IsMacOS -or $IsLinux)) {
return
}
Write-Verbose "Setting permissions on path: $Path"
@rjmholt
rjmholt / Get-PSEncoding.ps1
Created February 21, 2019 07:36
PowerShell BOM-less encoding
$badBytes = [byte[]]@(0xC3, 0x80)
$utf8Str = [System.Text.Encoding]::UTF8.GetString($badBytes)
$bytes = [System.Text.Encoding]::ASCII.GetBytes('Write-Output "') + [byte[]]@(0xC3, 0x80) + [byte[]]@(0x22)
$path = Join-Path ([System.IO.Path]::GetTempPath()) 'encodingtest.ps1'
try
{