Posts

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))

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)]

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"
   …

Keeping up with Hashicorp's Vault

Image
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.




Multiple SSH Keys settings for different github accounts

Say you have two keys. Add these two keys as following to ssh agent running on your local machine: $ ssh-add ~/.ssh/id_rsa_hacker $ ssh-add ~/.ssh/id_rsa_exchan You can check your saved keys $ ssh-add -l Sample ssh config settings, uses aliases in first line of blocks Host github-hacker HostName github.com User git IdentityFile ~/.ssh/id_rsa_hacker Host github-exchan HostName github.com User git IdentityFile ~/.ssh/id_rsa_exchan then use normal flow to push your code git clone git@github.com:hacker/myrepo.git set remote host from the default (github.com) to match alias in the ssh config git remote set-url origin git@github-hacker:hacker/myrepo.git you can see the change in .git/config file if you look carefully
git add . git commit -m "your comments" git push

Docker training on Mac, 001

Take these steps, and, afterwards, try to understand how and why they worked, including flags/options "passed into" the command.
install Docker for Macverify installdocker --versionrun basic container testdocker run hello-worldinstall iTerm2open a terminal window and split horizontally, then closeopen a terminal window and split vertically, then closerun webserveropen a terminal window and split horizontalin bottom pane, run: watch -d -n7 docker ps -aas you take steps below, watch what changes occur in this windowin top window, run:docker run -d -p 8080:80 --name mywebserver001 nginxopen this in your web browserhttp://localhost:8080shut it downdocker stop mywebserver001docker rm mywebserver001