- Issues with the following Linux/Bash one-liner:
- It is ugly
- It has trailing tabs (
\t
)
- Challenge:
- Come up with a more elegant and concise Linux one-liner.
- Rules:
- You must only use Linux and/or Bash and it must be able to be run from the Linux CLI as a one-liner.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import yaml | |
import json | |
""" | |
DESCRIPTION: The goal of this script is to find the outermost/top-level key in | |
the following YAML document, given only the sub-group/sub-key name. | |
EXAMPLE: Say you only know the sub-group "mars" or "pluto", and you want to | |
know which top-level key they belong to (i.e., "apps" and "services", | |
respectively). The find_category() function will do just that, albeit, very |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from random import randint | |
RANGE = 1000000 | |
def random_guess(RANGE): | |
wins = [] | |
for _ in range(0, RANGE): | |
guess = randint(0, 1) | |
outcome = randint(0, 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# description: Apache Tomcat init script | |
# processname: tomcat | |
# chkconfig: 234 20 80 | |
# | |
# | |
# Copyright (C) 2014 Miglen Evlogiev | |
# | |
# This program is free software: you can redistribute it and/or modify it under |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- mode: ruby -*- | |
# vi: set ft=ruby : | |
VAGRANTFILE_API_VERSION = "2" | |
$common_script = <<COMMON_SCRIPT | |
# Set verbose | |
set -v | |
# Set exit on error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"AWSTemplateFormatVersion" : "2010-09-09", | |
"Description" : "AWS CloudFormation Sample Template LAMP_Single_Instance: Create a LAMP stack using a single EC2 instance and a local MySQL database for storage. This template demonstrates using the AWS CloudFormation bootstrap scripts to install the packages and files necessary to deploy the Apache web server, PHP and MySQL at instance launch time. **WARNING** This template creates an Amazon EC2 instance. You will be billed for the AWS resources used if you create a stack from this template.", | |
"Parameters" : { | |
"KeyName": { | |
"Description" : "Name of an existing EC2 KeyPair to enable SSH access to the instance", | |
"Type": "AWS::EC2::KeyPair::KeyName", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Steganography trick: | |
$ cat foo.zip >> bar.gif # "hides" 'foo.zip' inside 'bar.gif' | |
$ qiv bar.gif # views just fine (note: you can use any image viewer you like here) | |
$ unzip bar.gif # extracts 'foo.zip' | |
# Example: | |
$ echo "HELLO WORLD" > file.txt | |
$ zip -r foo.zip file.txt | |
$ cat foo.zip >> bar.gif | |
$ hexdump -C bar.gif |tail -12 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Rename: | |
# FROM: "Introduction___Networking_tutorial_(1_of_13)-qHzZUmP1vvON.mp4" | |
# TO: "nettut-01_of_13_-_Introduction-qHzZUmP1vvON.mp4" | |
for f in *.mp4; do \ | |
[[ $f =~ ^(.*)___Networking_tutorial_\(([0-9]+)_of_13\)-(.*)$ ]] | |
mv "$f" "nettut-$(printf "%02d" ${BASH_REMATCH[2]})_of_13_-_${BASH_REMATCH[1]}-${BASH_REMATCH[3]}" | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_trove() | |
{ | |
local cur=${COMP_WORDS[COMP_CWORD]} | |
COMPREPLY=( $(compgen -W "--configuration --marker database-list metadata-show secgroup-delete-rule cluster-delete user-revoke-access root-show --users database-delete --limit datastore-show configuration-detach backup-list user-grant-access help configuration-list delete --region --replica_of metadata-update create show -h cluster-show user-create --include-clustered configuration-create restart configuration-default metadata-list --backup --detach-replica-source user-update-attributes --new_password metadata-edit configuration-parameter-show backup-show --new_host flavor-show datastore-list configuration-instances --databases list --description root-enable secgroup-list-rules configuration-patch metadata-create resize-flavor --help cluster-list --remove_configuration --collate user-list datastore-version-list --instance cluster-instances cluster-create database-create secgroup-add-rule --datastore configuration-update configuration-parameter-list secgro |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Wide-open CORS config for nginx | |
# | |
location / { | |
if ($request_method = 'OPTIONS') { | |
add_header 'Access-Control-Allow-Origin' '*'; | |
# |
NewerOlder