Skip to content

Instantly share code, notes, and snippets.

View irwinwilliams's full-sized avatar

Irwin irwinwilliams

View GitHub Profile
@irwinwilliams
irwinwilliams / extract-data.js
Created March 31, 2023 03:32
GPT3-prompt to use jquery to extract html data
/*
jQuery to select all the values of the last column of 17 rows of an html table, where there are 8 columns. The values are actually anchor tags, which contain img tags. Extract the src attribute from those tags.
In the resulting JavaScript, also import jQuery via dynamically adding it to the page within the javascript, not via a script tag
*/
// Dynamically add jQuery to the page
let script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://code.jquery.com/jquery-3.6.0.min.js';
document.head.appendChild(script);
@irwinwilliams
irwinwilliams / BMPtoNV12.cs
Created May 27, 2021 16:55
A simple C# method that _attempts_ to convert a BMP formatted byte array to NV12
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;
/// <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 October 29, 2019 19:15 — forked from colinMac/ImgToBase64.ps1
Powershell script to convert an image to base64 data uri format and store in a text file
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"
import logging
import gkeepapi
import jsonpickle
import os
import azure.functions as func
class KeepNote(object):
label = ""
text = ""
category = ""
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 April 22, 2019 09:55
Simple listener to confirm a networking question I had on StackOverflow
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 April 7, 2019 12:12
A class full of SMPP fields
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 December 2, 2018 22:44
An example of toggling VM state using Azure's Fluent SDK
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 December 2, 2018 22:36
Function - Webhook to enqueue a message
[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