Skip to content

Instantly share code, notes, and snippets.

@RyanHirsch
RyanHirsch / linux-academy-creds.js
Created May 8, 2019 13:06
Extract and Log credentials to make connecting to lab boxes easier.
function loadJquery(version = "3.4.1") {
var jqry = document.createElement('script');
jqry.src = `https://cdnjs.cloudflare.com/ajax/libs/jquery/${version}/jquery.js`;
document.getElementsByTagName('head')[0].appendChild(jqry);
return jQuery.noConflict();
}
function getCredentials($) {
const $credential = $("h3:contains(Credentials)").parent()
const $servers = $credential.find(".credential-topic-label").map(function getParent() {
@RyanHirsch
RyanHirsch / db.sh
Created April 24, 2019 13:35
docker-compose postgres initialization
#!/usr/bin/env bash
# Expected to be in a scripts directory
set -e
DATABASE_NAME="your-database"
SCRIPTS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
PROJECT_DIR="$( cd "${SCRIPTS_DIR}" && cd .. && pwd )"
echo "==== Start database and running all migration and seed scripts ===="
cd "${PROJECT_DIR}"
@RyanHirsch
RyanHirsch / chunk.js
Created March 19, 2019 23:12
Lots of Chunking Options
// --- Directions
// Given an array and chunk size, divide the array into many subarrays
// where each subarray is of length size
// --- Examples
// chunk([1, 2, 3, 4], 2) --> [[ 1, 2], [3, 4]]
// chunk([1, 2, 3, 4, 5], 2) --> [[ 1, 2], [3, 4], [5]]
// chunk([1, 2, 3, 4, 5, 6, 7, 8], 3) --> [[ 1, 2, 3], [4, 5, 6], [7, 8]]
// chunk([1, 2, 3, 4, 5], 4) --> [[ 1, 2, 3, 4], [5]]
// chunk([1, 2, 3, 4, 5], 10) --> [[ 1, 2, 3, 4, 5]]
@RyanHirsch
RyanHirsch / quicksort.ts
Last active March 14, 2019 13:13
quicksort
const arr = [ 100, 1,3,4,6,0,8,11, 2,30,5];
function sort<T>(items: T[]) {
const copy = [...items];
quickSort(copy);
return copy;
}
function quickSort<T>(items: T[], start: number = 0, end:number = items.length) {
const length = end - start;
@RyanHirsch
RyanHirsch / tries-contacts.ts
Created February 24, 2019 15:22
An attempt to implement what is described and illustrated based on the first 2 minutes of https://www.youtube.com/watch?v=vlYZb68kAY0&index=8&list=PLI1t_8YX-Apv-UiRlnZwqqrRT8D1RhriX&t=164s no clue if it is right
const splitAt = (index: number) => (x: string) => [x.slice(0, index), x.slice(index)];
const splitFirst = splitAt(1);
class ContactNode {
contactsCount: number = 0;
data: { [letter:string]: ContactNode } = {}
add(contact: string) {
this.contactsCount++;
@RyanHirsch
RyanHirsch / README.md
Created August 7, 2018 16:32
Learn Functional Programming with Elixir - Chapter 3 Pattern Matching Tic-Tac-Toe

Create a function that returns Tic-Tac-Toe game winners. You can represent the board with a tuple of nine elements, where each group of three items is a row. The return of the function should be a tuple. When we have a winner, the first element should be the atom :winner, and the second should be the player. When we have no winner, the tuple should contain one item that is the atom :no_winner. It should work like this:

@RyanHirsch
RyanHirsch / .babelrc
Last active April 11, 2018 11:53
.NET Core + React starter away from TypeScript
{
"presets": [
"@babel/preset-react",
[
"@babel/preset-env",
{
"targets": { "browsers": "last 2 versions" },
"loose": true,
"modules": false
}
@RyanHirsch
RyanHirsch / keybindings.json
Created April 3, 2017 23:49
Visual Studio Code Settings
[
{
"key": "ctrl+`",
"command": "workbench.action.terminal.focus",
"when": "!terminalFocus"
},
{
"key": "ctrl+`",
"command": "workbench.action.focusActiveEditorGroup",
"when": "terminalFocus"
@RyanHirsch
RyanHirsch / README.md
Created March 17, 2017 10:35
Automagic nginx configuration and let's encrypt certificates
@RyanHirsch
RyanHirsch / docker-gc.sh
Created March 9, 2017 00:48
Clean up old docker containers
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -v /etc:/etc spotify/docker-gc