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 / Comment lines containing "DEBUG" statements in a C program using Neovim.txt
Created May 2, 2024 18:14
Comment lines containing "DEBUG" statements in a C program
" using :normal
g/^\\s\*DEBUG/exe "norm! I/\* \\<Esc>A \*/\\<Esc>"
" using :substituting
g/^\\s\*DEBUG/s!.\*!/\* & \*/!
@petergi
petergi / Double space a file in Neovim.txt
Created May 2, 2024 18:12
Double space the file (^ is start of line which matches each line)
:g/^/pu =\\"\\n\\"
" Alternative (:put inserts nothing from the blackhole register)
:g/^/pu \_
@petergi
petergi / Delete all blank lines in Neovim.txt
Created May 2, 2024 18:10
Delete all blank lines (^ is start of line; \s* is zero or more whitespace characters; $ is end of line)
:g/^\\s\*$/d
@petergi
petergi / Delete all lines that do not match a pattern in Neovim.txt
Created May 2, 2024 18:08
The commands shown are equivalent (v is "inverse").
:g!/pattern/d
:v/pattern/d
@petergi
petergi / Delete all lines matching a pattern in Neovim.txt
Created May 2, 2024 18:07
Delete all lines matching a pattern in Neovim
:g/pattern/d
@petergi
petergi / Display context (5 lines) for all occurrences of a pattern in Neovim.txt
Created May 2, 2024 18:05
Display context (5 lines) for all occurrences of a pattern
" Display context (5 lines) for all occurrences of a pattern.
:g/pattern/z#.5
" Same, but with some beautification.
:g/pattern/z#.5|echo "=========="
@petergi
petergi / Heap Sort in JavaScript.js
Last active January 8, 2024 01:49
The algorithm has an average time complexity of O(n log n), where n is the size of the input array.
/**
* Sorts an array using the heapsort algorithm.
* Heapsort is a comparison-based sorting algorithm.
* Heapsort is an improved selection sort consisting of the use of a
* heap data structure instead of a linear-time search to find the maximum or minimum element.
*
* @param {Array} arr - The array to be sorted.
* @return {Array} - The sorted array.
*/
function heapsort(arr) {
@petergi
petergi / FizzBuzz in Java.java
Created January 8, 2024 01:31
By preallocating the ArrayList with the initial capacity of n, we avoid resizing the list during the loop, which improves performance. Instead of using multiple conditional statements, used StringBuilder to build the result string. Additionally, used sb.length() == 0 to check if the StringBuilder is empty, instead of using multiple else if state…
/**
* Generates a list of strings based on the given integer input.
*
* @param n the maximum integer value to generate strings for
* @return a list of strings containing the generated values
*/
public List<String> fizzBuzz(int n) {
List<String> res = new ArrayList<>(n)
for (int i = 1; i <= n; i++) {
StringBuilder sb = new StringBuilder()
@petergi
petergi / Javascript big O cheatsheet.md
Last active December 29, 2023 06:37
Learn everything you need to know about Big-O notation with this handy cheatsheet.
title tags excerpt dateModified
JS Big-O Cheat Sheet
algorithm
Learn everything you need to know about Big-O notation with this handy cheatsheet.
2023-01-08 05:00:00 -0400

Definition

let asciiValue: String = "1234567890ABCDEFGHIJ"
func asciiToHex(_ asciiValue: String) -> String {
let chars: [String.Element] = Array(asciiValue)
var hex: String = ""
for char: String.Element in chars {
hex += String(char.asciiValue!, radix: 16)
}
return hex
}