Skip to content

Instantly share code, notes, and snippets.

View petergi's full-sized avatar
💭
Just Busy Living On The Side Of A Square

Peter Giannopoulos petergi

💭
Just Busy Living On The Side Of A Square
View GitHub Profile
@petergi
petergi / Unique Array Elements in Javascript.js
Last active December 27, 2023 22:15
Finds all unique values in an array
/**
* Returns an array containing the unique elements from the input array.
*
* @param {Array} arr - The input array.
* @return {Array} An array containing the unique elements from the input array.
*/
function uniqueElements(arr) {
const uniqueArr = []
const seen = new Set()
@petergi
petergi / Weighted Average in Javascript.js
Last active December 27, 2023 20:16
Calculates the weighted average of two or more numbers
/**
* Calculates the weighted average of an array of numbers.
*
* @param {number[]} nums - The array of numbers to be averaged.
* @param {number[]} weights - The array of weights corresponding to each number in `nums`.
* @return {number} The weighted average of the numbers.
*/
const weightedAverage = (nums, weights) => {
let sum = 0;
let weightSum = 0;
#!/usr/bin/env bash
LOG_FILE="appPrint.log"
. "Check ownership and permissions of a file.sh"
function log()
{
#!/usr/bin/env bash
# Check ownership and permissions of a file
function checkPermissions() {
file="$1"
expectedOwner="$2"
expectedPermissions="$3"
expectedUid=`id -u "$expectedOwner"`

Curl cheatsheet

Options

-o <file>    # --output: write to file
-u user:pass # --user: Authentication
-v           # --verbose
-vv          # Even more verbose
-s           # --silent

To find the length of a string use the # symbol

echo "${#MY_STRING}" 

Converting strings to Array

MY_ARR=($MY_STRING)
#!/usr/bin/env bash
# This is a bash script template in order to help you quick start any script.
# It contains some sensible defaults, you can learn more by visiting:
# https://google.github.io/styleguide/shell.xml
#
# This option will make the script exit when there is an error
set -o errexit
@petergi
petergi / Reading a file in the shell a single line at a time
Last active March 25, 2023 20:57
Simple examples of reading a file in the shell one line at a time.
cat file.txt | while read line || [[ -n $line ]];
do
printf '%s\n' "$line" # do something with $line here
done

Older Macs:

# Enable (Default)
sudo nvram BootAudio=%01

# Disable
sudo nvram BootAudio=%00

From 2016 models on:

Global

  • :help keyword - open help for keyword
  • :saveas file - save file as
  • :close - close current pane
  • K - open man page for word under the cursor

Exiting