Tuesday 18 December 2018

Quickly ssh into repeatly new Linux instances with same IP without host key check

WARNING: this is extremely dangerous on networks not completely TRUSTED

Host 10.10.* *.mycompany.org
  User myuser
  IdentityFile /home/myuser/.ssh/my_ssh_key
  StrictHostKeyChecking no
  UserKnownHostsFile=/dev/null

Monday 26 November 2018

Total n00b’s guide to Big O, Big Ω, & Big θ

Crazy brillant!

https://medium.com/@.RT/total-n00bs-guide-to-big-o-big-%CF%89-big-%CE%B8-aa259ae8a1c2

Total n00b’s guide to Big O, Big Ω, & Big θ

Tuesday 11 September 2018

tcpdump -nnXSs

Taken: https://www.askbjoernhansen.com/2007/07/12/how_to_dump_packets_with_tcpdump.html

I always forget the parameters for this and have to look them up in the man page, so enough of that:

 tcpdump -nnXSs 0 port 80


  • "-nn" makes it not lookup hostnames in DNS and service names (in /etc/services) for respectively faster and cleaner output. 
  • "-X" makes it print each packet in hex and ascii; that's really the useful bit for tracking headers and such 
  • "-S" print absolute rather than relative TCP sequence numbers - If I remember right this is so you can compare tcpdump outputs from multiple users doing this at once 
  • "-s 0" by default tcpdump will only capture the beginning of each packet, using 0 here will make it capture the full packets. We are debugging, right? 

Sunday 9 September 2018

<description>[\w\s\n&\.\-,;]*</description>

Monday 27 August 2018

perl cli regex

perl -pe 's/^(.+)\/([^\s]+)\-([v0-9.]+)\-*([Final|GA|M2|rc|beta|R5]*).jar$/$2\t$3\t$4/'

Saturday 23 June 2018

key git book pages to read


  • https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging
  • https://git-scm.com/book/en/v2/Git-Branching-Branching-Workflows

Sunday 10 June 2018

packer: virtualbox

Prep
  • Vagrant
    • vagrant init hashicorp/precise64
    • vagrant up
    • vagrant destroy -f
Generate
  • Packer
    • find ~/.vagrant.d/ -name '*ovf' -ls | grep hashi
    • create ex001.json
      • see below
      • fix "source_path" to ovf file to match your system
    • packer validate ex001.json
    • packer build ex001.json
    • vagrant box add my-box-001 packer_virtualbox-ovf_virtualbox.box --force
Test
  • mkdir test001
  • cd test001
  • vagrant init
    • in generated "Vagrantfile", change 1st line to 2nd line
      •   config.vm.box = "base"
      •   config.vm.box = "my-box-001"
  • vagrant up
  • vagrant ssh
    • cat /var/tmp/welcome.txt
      • should say, "welcome001"
  • vagrant destroy -f
Cleanup
  • vagrant box remove my-box-001 --force
  • vagrant box remove hashicorp/precise64 --force


ex001.json

{
  "builders": [{
      "type": "virtualbox-ovf",
      "source_path": "<path to your home dir>/.vagrant.d//boxes/hashicorp-VAGRANTSLASH-precise64/1.1.0/virtualbox/box.ovf",
      "ssh_username": "vagrant",
      "ssh_password": "vagrant",
      "shutdown_command": "echo 'packer' | sudo -S shutdown -P now"
    }],
    "provisioners": [
        {
            "type": "shell",
            "inline":[ "echo welcome001 > /var/tmp/welcome.txt" ]
        }
    ],
    "post-processors": ["vagrant"]
}


Monday 16 April 2018

end is nigh: serverless

"For a small company focused on rapid growth, the last thing we wanted to deal with was disk space and memory management, logging agents, security patches, operating system updates, and other traditional server management processes."

Thursday 12 April 2018

recursive

def recursive_countdown(x):
    print('Countdown: ' + str(x))
    if x == 1:
        return 1
    else:
        return recursive_countdown(x - 1)

recursive_countdown(5)


def recursive_fib(x):
    #print('Fib: ' + str(x))
    if x in [0, 1]:
        return x
    else:
        return (recursive_fib(x - 1) + recursive_fib(x -2 ))

# this algo can be easily improved if answers are indexed

print(recursive_fib(5))
print(recursive_fib(6))
print(recursive_fib(7))
print(recursive_fib(8))

Wednesday 11 April 2018

Python: sort by value then key

No idea yet how this works, or why.

>>> d = {'apple': 7, 'banana': 3, 'almond': 7, 'peach': 4, 'beetroot': 3}
>>> sorted(d.iteritems(), key=lambda(k, v): (-v, k))
[('almond', 7), ('apple', 7), ('peach', 4), ('banana', 3), ('beetroot', 3)]

Thursday 5 April 2018

Basic Ansible in 10 mins


  • "site.yml" file
    • playbook containing
      • "roles" that will be applied to individual host groups / "hosts"
      • how the hosts will be accessed
        • and by what user to run as
      • Puppet equivalent is "nodes.pp"
  • "hosts" file
    • use real/local DNS hostname to define which hosts are in which hostgroups
      • example: webserver1, webserver2, haproxy1, haproxy2, mongo1, mongo2
      • some variables like "port" can be added too
  • "group-vars" directory
    • key/value pairs to use when generating output from template files
    • files named identically to hostgroup names defined in "hosts" file
    • these are more in-line in Puppet, and less controllable/flexible
  • "roles" directory
    • Puppet equivalents are "modules"/"classes"
    • directories arbitrarily named to match "roles" in site.yml
    • e.g. "tomcat", "common", "mongod"
    • "templates" directory
      • files with variables that are resolved using "group-vars" key/values
      • moved on to target systems using task keyword "template"
      • same name is used in Puppet
    • "files"
      • raw files to be moved into place on the target filesystems
      • used by tasks with keyword "file"
      • same name used in Puppet
    • "handlers"
      • "main.yml"
      • control system services on target systems
        • "service" keyword
        • "state", e.g. "restarted"
        • in Puppet, these are not broken out from other "resources"
    • "tasks"
      • this is the core list of actions to perform on target systems
      • Puppet equivalents are "includes"/"classes", maybe "modules" as well
      • "main.yml"
        • collection of tasks
        • uses yml structure
          • "name" is arbitrary reference for developers
          • ansible keyword to perform some action on the system
            • ansible keywords: "file", "template", "command"
              • puppet equivalents are called "resources"
          • conditionals/dependencies: "when", "notify", "wait_for"


Keeping up with Hashicorp's Vault

To retrieve secrets, employees replace plaintext secrets with a call to Secrets Manager APIs, eliminating the need to hard-code secrets in source code or update configuration files and redeploy code when secrets are rotated.




Interview questions: 2020-12

Terraform provider vs provisioner Load balancing Network Load Balancer vs Application Load Balancer  Networking Layer 1 vs Layer 4 haproxy u...