Skip to content

Instantly share code, notes, and snippets.

Avatar

Irwin irwinwilliams

View GitHub Profile
@irwinwilliams
irwinwilliams / BMPtoNV12.cs
Created May 27, 2021
A simple C# method that _attempts_ to convert a BMP formatted byte array to NV12
View BMPtoNV12.cs
public void BMPtoNV12(byte[] yuv420sp, byte[] argb, int width, int height)
{
int frameSize = width * height;
int yIndex = 0;
int uvIndex = frameSize;
uint a;
int R, G, B, Y, U, V;
View TransformNv12ToBmpFaster.cs
/// <summary>
/// Transform NV12 to bmp image so we can view how is it looks like. Note it's not NV12 to RBG conversion.
/// </summary>
/// <param name="data">NV12 sample data.</param>
/// <param name="width">Image width.</param>
/// <param name="height">Image height.</param>
/// <param name="logger">Log instance.</param>
/// <returns>The <see cref="Bitmap"/>.</returns>
public static Bitmap TransformNv12ToBmpFaster(byte[] data, int width, int height, IGraphLogger logger)
{
@irwinwilliams
irwinwilliams / ImgToBase64.ps1
Created Oct 29, 2019 — forked from colinMac/ImgToBase64.ps1
Powershell script to convert an image to base64 data uri format and store in a text file
View ImgToBase64.ps1
function ImageToBase64 {
Param([String]$path)
[bool]$valid = ($path -ne "")
if ($valid) {
[String[]]$elements = $path.split(".")
[int]$max = $elements.Count - 1
[String]$ext = $elements[$max]
[String]$uri = "data:image/$($ext);base64,"
$elements[$max] = "txt"
View KeepIt.py
import logging
import gkeepapi
import jsonpickle
import os
import azure.functions as func
class KeepNote(object):
label = ""
text = ""
category = ""
View TwitterFavoritesReader.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
@irwinwilliams
irwinwilliams / Program.cs
Created Apr 22, 2019
Simple listener to confirm a networking question I had on StackOverflow
View Program.cs
using System;
using System.Net;
using System.Net.Sockets;
using System.Threading.Tasks;
namespace ListenOnAny
{
class Program
{
static void Main(string[] args)
@irwinwilliams
irwinwilliams / SMPPMessage.cs
Created Apr 7, 2019
A class full of SMPP fields
View SMPPMessage.cs
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;
using System.Text;
namespace TSharkConsumer
{
[System.Runtime.Serialization.DataContractAttribute(Name = "SMPPMessage",
Namespace = "http://schemas.datacontract.org/2004/07/teleios.messaging.smpp.Models")]
@irwinwilliams
irwinwilliams / VMManagement.cs
Created Dec 2, 2018
An example of toggling VM state using Azure's Fluent SDK
View VMManagement.cs
public Tuple<string,string> SetState(string state)
{
var vmName = VirtualMachineName;
var client = AzureClientId;
var key = AzureClientKey;
var tenant = AzureTenantId;
var creds = new AzureCredentialsFactory()
.FromServicePrincipal(client, key, tenant, AzureEnvironment.AzureGlobalCloud);
var subscriptionId = AzureSubscriptionId;
var azure = Microsoft.Azure.Management.Fluent.Azure.Authenticate(creds).WithSubscription(subscriptionId);
@irwinwilliams
irwinwilliams / Function.cs
Created Dec 2, 2018
Function - Webhook to enqueue a message
View Function.cs
[FunctionName("GoogleActions")]
public static IActionResult Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
[Queue("changevmstate")] out string state,
ILogger log)
{
state = null;
try
@irwinwilliams
irwinwilliams / create-azure-resource-group-with-contributors.ps1
Created Nov 9, 2017
Create azure resource group and assign contributors
View create-azure-resource-group-with-contributors.ps1
#Clear-Host
$classlist - ".\class-list.tsv" #contains a tab-delimited list of object ids, resource group names and locations
$tenant = "guid"
$app_id = "guid"
$app_key = ConvertTo-SecureString "key" -AsPlainText -Force
$cred = New-Object -TypeName pscredential -ArgumentList $app_id, $app_key
Login-AzureRmAccount -Credential $cred -ServicePrincipal -TenantId $tenant
Get-Content $classlist | ForEach-Object {
$tokens = $_ -split "\t"