Skip to content

Instantly share code, notes, and snippets.

View Announcement's full-sized avatar

Jacob Francis Powers Announcement

View GitHub Profile
function prompt {
$private:Token = "→"
Write-Host -NoNewline $Token
" "
}
Import-Module PSReadLine
Import-Module PSFzf
Set-PsFzfOption -PSReadlineChordProvider 'Ctrl+t' -PSReadlineChordReverseHistory 'Ctrl+r'
$commandOverride = [ScriptBlock]{ param($Location) Write-Host $Location }
Set-PsFzfOption -AltCCommand $commandOverride
Set-PSReadLineKeyHandler -Key Tab -ScriptBlock { Invoke-FzfTabCompletion }
$host.ui.RawUI.WindowTitle = "PowerShell $($PSVersionTable.PSVersion)"
# deno completions powershell | Out-String | Invoke-Expression
# caddy completion powershell | Out-String | Invoke-Expression
@Announcement
Announcement / mars.ps1
Created November 1, 2023 00:17
What's taking up all my space? Sorts biggest folders, and files inside the folders, with a low-pass filter.
Get-ChildItem -Recurse -Depth 2 | Where-Object -Property Length -GT 1MB | % { [pscustomobject]@{Length=$_.Length;Folder=$(Resolve-Path -Path $_.Directory -Relative).Replace('.\','');Name=$_.Name} } | Group-Object Folder | % {[pscustomobject]@{Name=$_.Name;Size=$_.Group | Measure-Object -Property Length -Sum | Select-Object -ExpandProperty Sum;Files=$_.Group|Sort-Object -Property Length}} | Sort-Object Size | % { $Folder=$_;$_.Files | % { [pscustomobject]@{Length=$_.Length;Folder=$Folder.Name;Name=$_.Name} } } | Format-Table @{n='Length';e={Format-FileSize $_.Length};align='right'},Name -GroupBy Folder
/**
* Generate integers ranging from the lower limit to the upper limit as an iterator.
*
* @param m? - Optional, Integer lower limit of generator. Defaults to 0.
* @param M - Required, Integer upper limit of generator.
*/
function δ (minimum: number, maximum: number): IterableIterator<number>;
function δ (Δ: number): IterableIterator<number>;
function * δ (h: number, k?: number?): IterableIterator<number>
{
// run this in the 'browser'
function * getPersonsResults () {
for (const result of document.querySelector('#results-list').querySelectorAll('.result')) {
const nameContainer = result.querySelector('.name-container');
const primaryName = nameContainer.querySelector('h3').textContent.trim();
const aliases = [...nameContainer.querySelectorAll('.aliases .alias')].map(it => it.textContent.trim())
const locations = [...result.querySelectorAll('.locations-container .person-location')].map(location => location.textContent.trim());
const relatives = [...result.querySelectorAll('.relatives-container .person-relative')].map(location => location.textContent.trim());
const age = result.querySelector('.age-container h2').textContent.trim();
@Announcement
Announcement / gp.js
Created February 29, 2020 13:11
algorithm judgement/advice
function* createObjectThrough0 (object) {
const entries = Object.entries(object);
const objects0 = [];
const objects1 = [];
for (let currentEntryIndex = 0,
maximumEntryIndex = entries.length;
currentEntryIndex < maximumEntryIndex;
currentEntryIndex++)
@Announcement
Announcement / gaussian_elimination.js
Created February 11, 2020 17:41
why is `M` not defined on line 59?
function * count() {
const maximum =
(arguments.length === 1 && typeof arguments[0] === "number") ? arguments[0] :
(arguments.length === 1 && typeof arguments[0] === "object" && arguments[0].hasOwnProperty("maximum")) ? arguments[0].maximum :
(arguments.length === 1 && typeof arguments[0] === "object" && arguments[0].hasOwnProperty("max")) ? arguments[0].max :
(arguments.length === 2 || arguments.length === 3) ? arguments[1] : 0;
const minimum =
(arguments.length === 1 && typeof arguments[0] === "number") ? 0 :
(arguments.length === 1 && typeof arguments[0] === "object" && arguments[0].hasOwnProperty("minimum")) ? arguments[0].minimum :
@Announcement
Announcement / count.js
Created February 11, 2020 17:23
what's the correct way to document this function?
function * count() {
const maximum =
(arguments.length === 1 && typeof arguments[0] === "number") ? arguments[0] :
(arguments.length === 1 && typeof arguments[0] === "object" && arguments[0].hasOwnProperty("maximum")) ? arguments[0].maximum :
(arguments.length === 1 && typeof arguments[0] === "object" && arguments[0].hasOwnProperty("max")) ? arguments[0].max :
(arguments.length === 2 || arguments.length === 3) ? arguments[1] : 0;
const minimum =
(arguments.length === 1 && typeof arguments[0] === "number") ? 0 :
(arguments.length === 1 && typeof arguments[0] === "object" && arguments[0].hasOwnProperty("minimum")) ? arguments[0].minimum :
@Announcement
Announcement / count.js
Created February 11, 2020 17:22
what's the correct way to document this function?
function * count() {
const maximum =
(arguments.length === 1 && typeof arguments[0] === "number") ? arguments[0] :
(arguments.length === 1 && typeof arguments[0] === "object" && arguments[0].hasOwnProperty("maximum")) ? arguments[0].maximum :
(arguments.length === 1 && typeof arguments[0] === "object" && arguments[0].hasOwnProperty("max")) ? arguments[0].max :
(arguments.length === 2 || arguments.length === 3) ? arguments[1] : 0;
const minimum =
(arguments.length === 1 && typeof arguments[0] === "number") ? 0 :
(arguments.length === 1 && typeof arguments[0] === "object" && arguments[0].hasOwnProperty("minimum")) ? arguments[0].minimum :
@Announcement
Announcement / _createReducer.js
Created January 17, 2020 18:46
unexpected token @ row: 2, column: 78
// @flow
function _createReducer<T, K>(handler: { [$PropertyType<K, 'type'>]: ({ action, state }: { action: K, state: T }) => T }): (state: T, action: K) => T {
if (handler.hasOwnProperty(action.type))
return handler[action.type]({
action,
state
});
return state;
}