This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# return code is either 0 (success) or 1 (fail), so you can use it straight-up in logical statements | |
coinflip() { return $(($RANDOM%2)); } | |
coinflip && echo "heads" || echo "tails" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Wrote this on a whim. Consider it performance-art shell scripting. | |
# To really do this, set FFS=true, otherwise, only the paths to the files that would have been destroyed are printed. | |
# I take no responsibility for the use of this. Even writing it was scary, and I didn't test the whole thing (YET). | |
# You have been warned. | |
coinflip() { return $(($RANDOM%2)); } | |
thanos_logic() { while read -r line; do coinflip && echo "$line"; done; } | |
thanos_infinity_gauntlet_completed() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# helper function | |
needs () { | |
local bin=$1; | |
shift; | |
command -v $bin > /dev/null 2>&1 || { | |
echo "I require $bin but it's not installed or in PATH; $*" 1>&2; | |
return 1 | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Script: ShowListeners.ps1 | |
# Author: MotoX80 and Evgenij Smirnov on MS forums | |
# pmarreck note: If you get a security block, you may need to run the following first: | |
# Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope Process | |
# (or use CurrentUser for the -Scope if you want it to apply outside the current session, less secure though) | |
# For more, see: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.security/set-executionpolicy?view=powershell-7.2 | |
$rpt = @() | |
$services = Get-CimInstance -Class Win32_Service -Filter 'State="Running"' | Select Name, ProcessID | |
$Listeners = Get-NetTCPConnection | Where-Object {$_.State -eq "Listen"} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for tab in $(grep -l -o '[a-z0-9-]*proto' $(brew --cellar)/*/*/INSTALL_RECEIPT.json) | |
do | |
formula=$(basename $(dirname $(dirname $tab))) | |
brew remove --ignore-dependencies $formula | |
brew install $formula | |
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
while [[ `brew list | wc -l` -ne 0 ]]; do | |
#Iterate over each installed package | |
for EACH in `brew list`; do | |
#Uninstall each package | |
brew uninstall --ignore-dependencies $EACH --force | |
done | |
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# get a random-character password | |
# First argument is password length | |
# Can override the default character set by passing in PWCHARSET=<charset> as env | |
randompass() { | |
# globbing & history expansion here is a pain, so we store its state, temp turn it off & restore it later | |
local maybeglob="$(shopt -po noglob histexpand)" | |
set -o noglob # turn off globbing | |
set +o histexpand # turn off history expansion |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Increases do | |
def count_increases(string) when is_binary(string) do | |
string | |
|> String.split("\n") | |
|> Enum.map(fn x -> Integer.parse(x) end) | |
|> Increases.count_increases | |
end | |
def count_increases(list) when is_list(list), do: count_increases(list, 0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
capture () { | |
local out_var out err_var err ret_var ret debugflag | |
debugflag= | |
if [ "$1" = "--debug" ]; then | |
debugflag=1 | |
shift | |
fi | |
if [ "$#" -lt 4 ]; then | |
echo "Usage: capture [--debug] <stdoutvar> <stderrvar> <returncodevar> command [arg ...]" | |
return 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# So I did a little experiment in my language of choice to prove this is completely expected, | |
# I will walk you through it. | |
# My comments start with a #. | |
Interactive Elixir (1.10.3) - press Ctrl+C to exit (type h() ENTER for help) | |
iex(1)> set_of_all_possible_numbers = 100..999 | |
100..999 | |
iex(2)> list_of_all_possible_numbers = Enum.to_list(set_of_all_possible_numbers) | |
[100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, | |
116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, |