Skip to content

Instantly share code, notes, and snippets.

View jkumara's full-sized avatar

Juhani Kumara jkumara

View GitHub Profile
@jkumara
jkumara / move0.js
Created August 31, 2023 08:46
Move all zeros of the array to the end while maintaining the relative order of all non-zeros.
/**
* Given an array of integers, move all zeros of the array to the end while
* maintaining the relative order of all non-zeros.
*
* Example:
*
* $ move0([1,3,0,111,57,0,5,0,9])
* $ [1,3,111,57,5,9,0,0,0]
*/
@jkumara
jkumara / firework.js
Last active January 31, 2022 17:49
Sorting an array without immediately repeating any element
/**
* Fireworks on New Year's Eve were great. This year, however, the fireworks
* company wants to avoid firing the same colour rocket twice in a row. Given an
* array of fireworks, return a valid firing order. If there is an impossible
* scenario, you can decide how to handle it.
*
* Example(s):
*
* firework(['green', 'green', 'pink', 'pink', 'orange'])
* ['green', 'pink', 'green', 'pink', 'orange']
@jkumara
jkumara / withinRange.js
Last active August 26, 2021 10:25
IPv4 range check
/**
* Given an IPv4 address and a netmask in CIDR notation, return a boolean specifying whether the address is with the provided range.
*
* EXAMPLE(s)
* ---
* $ withinRange("10.0.3.33", "10.0.0.0/16")
* $ true
*
* $ withinRange("10.0.3.33", "10.0.1.0/24")
* $ false
@jkumara
jkumara / clean-scumbag.zsh
Created August 7, 2019 11:10
Minimal ZSH theme based on clean, with git prompt ripped off from mortalscumbag
#!/usr/bin/env zsh
# Minimal theme based on clean, with git prompt ripped off from mortalscumbag
if [ $UID -eq 0 ]; then NCOLOR="red"; else NCOLOR="white"; fi
function my_git_prompt() {
tester=$(git rev-parse --git-dir 2> /dev/null) || return
INDEX=$(git status --porcelain 2> /dev/null)