Skip to content

Instantly share code, notes, and snippets.

View deviousasti's full-sized avatar
🏡
Working from home

Asti deviousasti

🏡
Working from home
View GitHub Profile
@deviousasti
deviousasti / GitConfigParser.fs
Created January 21, 2020 04:18
A simple .git/config parser
module ConfigParser
open System
open System.IO
type ConfigSection = { Name: string; Subsection: string; Values: Map<string,string> }
(*
Ref: https://git-scm.com/docs/git-config#_syntax
Sample:
@deviousasti
deviousasti / pb_union_decode.c
Last active January 24, 2020 18:58
Decoding a oneof case in nanopb
typedef struct pb_union_s
{
const uint32_t tag;
const pb_msgdesc_t* submsg_desc;
pb_istream_t stream;
} pb_union_t;
const pb_union_t getUnionType(uint8_t buffer[], size_t size)
{
pb_istream_t stream = pb_istream_from_buffer(buffer, size);
@deviousasti
deviousasti / Verify.psm1
Created January 28, 2020 08:23
Simple File Integrity Verifier in Powershell
function Create-Verification {
param([string] $Path = ".", [string] $Verify = "", [string] $Filter = "*.*")
$Output = "$($Path | Split-Path -Leaf).sha2"
$Table =
Get-ChildItem -Path $Path |
Where-Object { $_.Name -like $Filter -and $_.Name -ne $Output } | #Don't inculde the .sha2 file
Sort-Object -Property Name |
Get-FileHash -Algorithm SHA256 |
@deviousasti
deviousasti / SyncSubmodules.psm1
Last active November 10, 2020 15:36
Adds submodules looking at entries from .gitmodules
function Get-Submodules {
function lookup($key, $defaultValue = "") {
$value = git config --file $gitmodules --get "$key" 2>&1
if($LASTEXITCODE -ne 0) { $defaultValue } else { $value }
}
function all {
(git config --file $gitmodules --list) -split "\n"
}
@deviousasti
deviousasti / launch.json
Last active February 23, 2020 09:55
Rust Setup For VSCode
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(Windows) Launch",
"type": "cppvsdbg",
"request": "launch",
# Discussion at https://github.com/dotnet/sdk/issues/2295
function Uninstall-DotNetSdk {
param (
[parameter(Mandatory = $False)] [switch] $All,
[parameter(Mandatory = $False)] [switch] $WhatIf
)
pushd $env:SystemRoot\System32
Get-ChildItem HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall |
Get-ItemProperty |
@deviousasti
deviousasti / DotnetExceptionTask.xml
Last active April 3, 2020 20:44
This task is triggered when a .NET application faults with an exception
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<Triggers>
<EventTrigger>
<Enabled>true</Enabled>
<Subscription>&lt;QueryList&gt;&lt;Query Id="0" Path="Application"&gt;&lt;Select Path="Application"&gt;*[System[Provider[@Name='.NET Runtime'] and EventID=1026]]&lt;/Select&gt;&lt;/Query&gt;&lt;/QueryList&gt;</Subscription>
<ValueQueries>
<Value name="eventChannel">Event/System/Channel</Value>
<Value name="eventRecordID">Event/System/EventRecordID</Value>
<Value name="eventSeverity">Event/System/Level</Value>
@deviousasti
deviousasti / Html.fs
Created May 7, 2020 14:14
Html Imports Bundler
module HtmlAgilityPack.FSharp
open HtmlAgilityPack
let parent (node : HtmlNode) =
node.ParentNode
let element name (node : HtmlNode) =
node.Element name
@deviousasti
deviousasti / SunModel.cs
Created May 10, 2020 06:27
Model of time -> temperature over a year
static double SunModel(double td, double tm, double Tmin, double Tmax, double time_scale = 24)
{
//http://www.comsiru.uct.ac.za/sites/default/files/image_tool/images/333/Research/Downloads/Mono_8.pdf
return -Sin(2 * PI * (td + tm) / time_scale) * ((Tmax - Tmin) / 2) + ((Tmax + Tmin) / 2);
}
// Fisher–Yates shuffle
let shuffle deck =
let n = Array.length deck
let rnd = new Random()
let pick n = rnd.Next n
let swap i j =
let a,b = deck.[i], deck.[j]
Array.set deck j a
Array.set deck i b