Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View mckern's full-sized avatar

Ryan McKern mckern

View GitHub Profile
ryan@bender fun-with-arrays.RHRjym $ bash reading-files-as-arrays.sh example-lines.txt
this is the first example's length: 46
this is the first example's first item:
this
is
an
example
of
a
newline
@mckern
mckern / parser_from_scratch.rb
Created June 2, 2021 00:49
Parse each line of `key=value` pairs into an array of separate `key=value` pairs in Ruby
# frozen_string_literal: true
# Parse each line of key=value pairs into an array of separate key=value pairs.
# Some values will be in double quotes and contain white space,
# and some will not. All values with whitespace in them will be double quoted.
# No keys will be double quoted.
# annotated breakdown and explanation derived from
# https://stackoverflow.com/a/23613257, originally written by user
# https://stackoverflow.com/users/2195474/jbr in 2014
@mckern
mckern / the IRC clone company.txt
Last active June 2, 2021 01:00
Bad technical challenges
Hi Ryan,
We are excited to move you forward in the process! Please let us know if you have any questions.
<redacted>'s operations challenge is our primary means of understanding your troubleshooting and
programming abilities and the beginning of our understanding of the rest of your qualifications.
The challenge is divided into two parts.
For part one, we would like to assess your debugging and general Linux skills by asking you to install
the "apache2" package on a server that is misconfigured in many ways. It is your job to find, document,
and manually address these problems such that you are able to verify that the Apache web server is
accessible from the Internet. When you've verified the host is functional, please reply-all to this email
@mckern
mckern / README.md
Last active October 9, 2020 07:02
realpath.c by Adam Liss, public domain with minor modifications by Ryan McKern

realpath.c

Introduction

An extremely simple CLI to POSIX stdlib realpath()

Building & Installation

$ curl -O -L \
 https://gist.githubusercontent.com/mckern/3349ed18e7ff7e18b96e5a06942fbe11/raw/d8a330fe0fb7b6ad56b867d8b91f2c954536ef41/realpath.c
@mckern
mckern / stop reinventing realpath.md
Last active February 18, 2020 23:25
Your home-brew bathtub `realpath` hacks suck

A simple example:

ryan@C02X43Q9JG5K tmp.kU0KEN9U $ tree .
.
├── fakepaths
│   └── bin
│       └── shell.sh -> ../realpaths/bin/shell.sh
└── realpaths
    ├── bin
misfortune teller
short-stack developer
cargo cult leader
pastor of muppets
q.e.d. engineer
equine orthodontia
bovid depilatory
cultural insensitivity
rabbit hole excavator
omphaloskeptic

Challenge

Given a string which contains only lowercase letters, remove duplicate consecutive letters so that every letter appear once and only once.

Easy Solution

The right answer in Ruby is to use String#squeeze:

@mckern
mckern / percentage.sh
Created December 29, 2017 09:06
percentage.sh: quick and dirty command line percentage calculator
#!/usr/bin/env bash
# Copyright 2017 Ryan McKern <ryan@orangefort.com>
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
" Vim color file
" Converted from Textmate theme Slush & Poppies using Coloration v0.2.5 (http://github.com/sickill/coloration)
set background=dark
highlight clear
if exists("syntax_on")
syntax reset
endif
let g:colors_name = "Slush & Poppies 256"
hi Cursor guifg=NONE guibg=#000000 ctermbg=0 gui=NONE
hi Visual guifg=NONE guibg=#b0b0ff ctermbg=147 gui=NONE
#!/bin/bash
whitespace() {
local character="${1}"
local quantity="${2:-$LINES}"
for line in $(seq 1 ${quantity}); do
printf "%s\n" "${character}"
done
return $?