Skip to content

Instantly share code, notes, and snippets.

View BrianHicks's full-sized avatar

Brian Hicks BrianHicks

View GitHub Profile

Think Python

Chapters 4-6

Chapter 4

Case study: Turtle

4.2 (Flowers)

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

So Python has many "magic" methods, marked by double underscores surrounding the name. (for this reason, they're also sometimes called "dunder" methods.) Rake Ketter's guide on the subject is the best you'll find, it's very clear. We're just going to address __init__ here.

So __init__ is basically a method that gets called when you create a new "instance" of a class. Let's examine this with dogs...

# So first we're going to create a new "Dog" object. A dog knows it's name and how to bark.

class Dog(object):
    def __init__(self, name, woof): # __init__ takes a couple variables, and `self`...
        self.name = name            # and assigns them as properties of "self".
root@mesos-master-dev:~/marathon# docker attach $(docker run -d -p 8080:8080 mesosphere/marathon --master zk://192.168.1.104:2181/mesos --zk_hosts 192.168.1.104:2181 --hostname 192.168.1.104:2181)
Nov 22, 2013 2:28:55 PM mesosphere.marathon.MarathonModule provideCandidate
INFO: Registering in Zookeeper with hostname:192.168.1.104:2181
2013-11-22 14:28:55,184:12(0x7fb30aa83700):ZOO_INFO@log_env@658: Client environment:zookeeper.version=zookeeper C client 3.3.4
2013-11-22 14:28:55,184:12(0x7fb30aa83700):ZOO_INFO@log_env@662: Client environment:host.name=6985af9a3528
2013-11-22 14:28:55,184:12(0x7fb30aa83700):ZOO_INFO@log_env@669: Client environment:os.name=Linux
2013-11-22 14:28:55,184:12(0x7fb30aa83700):ZOO_INFO@log_env@670: Client environment:os.arch=3.8.0-29-generic
2013-11-22 14:28:55,184:12(0x7fb30aa83700):ZOO_INFO@log_env@671: Client environment:os.version=#42~precise1-Ubuntu SMP Wed Aug 14 16:19:23 UTC 2013
2013-11-22 14:28:55,185:12(0x7fb30aa83700):ZOO_INFO@log_env@679: Client environment:user.name=(nul
POST analytics-2013.11.06/_search
{
"query": {"match_all": {}},
"facets": {
"tags": {
"terms": {
"field": "params.tag",
"size": 10
}
}
  • US: 3,719,000 sq. miles ÷ 319,000,000 people = 0.011 mile/person
  • Japan: 145,833 sq. miles ÷ 126,000,000 people = 0.001 mile/person

So:

  • US: 85.7 people/sq. mile
  • Japan: 864 people/sq. mile

Figures from Wolfram Alpha

@BrianHicks
BrianHicks / ssg.md
Last active December 24, 2015 22:28
SSG concept

Static Site Generation as Discrete Stages

So imagine you have the following file structure:

.
├── _plugins
├── _posts
│   ├── 2013-01-01-test-post.md
│   └── 2013-10-02-blah.md
{% set root = salt["pillar.get"]("git-remote:location", "/opt/git-remote") %}
git:
pkg.installed:
- pkgs:
- git-core
git-remote-directory:
file.directory:
- name: {{ root }}
- user: root
git-remote:
root: /opt/git-remote
repos:
- name: salt-repo
hooks:
post-receive: |
#!/bin/bash
echo "-------- pulling to /srv/salt --------"
test -d /srv/salt || mkdir -p /srv/salt
# create the repo
salty-repo:
file.directory:
- name: /opt/git-remote/salty
- require:
- file: git-remote-directory
cmd.run:
- name: "git init /opt/git-remote/salty --bare"
- unless: "test -e /opt/git-remote/salty/HEAD"