text:
Q: Deduction of vector form of Snell's law I was unable to find the deduction of the vector form of Snells's law.
$$n_1\sin\theta_1 = n_2\sin\theta_2$$
Here is the vector form, from the article A Theory of Multi-Layer Flat Refractve Geometry
The formula is referenced to the book: "A. S. Glassner. An Introduction to Ray Tracing. Morgan
Kaufmann, 1989." but I don't have it. Also, I could not find the detuction on the internet.

Anyone can show me how they got here?

A: Let's say $n$ only has $y$ component. Since $V_i$ and $n$ are linearly independent, $V_{i+1}$ can be written as their linear combination. Note that all $V_i$ and $n$ are unit vectors. (every time you see the name Pythagora take a look at the equation next to it, you will notice that at one point I assumed they are all unit vectors. I was not able to avoid doing that without messing the whole derivation up, so $V_i^TV_i$ in the original expression should just equal $1$. It puzzles me that it is not just dropped in the book, so if anyone sees how this can be done avoiding the unit vector assumption, I would like to know.)
You first write $V_{i+1,x}=a_{i+1}V_{i,x}$, from here $a_{i+1}$ has to be what is stated in the question.
Then you take (2), which is the mentioned linear combination, and only consider $V_{i+1,y}$. That is, $a_{i+1}V_{i,y}+b_{i+1}$. Since $n$ is a unit vector with only $y$ component, $V_{i,y}=V_i^Tn$. Also, $V_{i+1,y}=-\sqrt{1-V_{i+1,x}^2}$ by Pythagora. The minus is just sign convention, there should be a picture in a book somewhere that should clear it up.
We already expressed $V_{i+1,x}=a_{i+1}V_{i,x}$, so $V_{i+1,y}=-\sqrt{1-a_{i+1}^2V_{i,x}^2}=a_{i+1}V_i^Tn+b_{i+1}$.
Now $V_{i,x}^2=V_i^TV_i-(V_i^Tn)^2$, again by Pythagora. This leaves $-\sqrt{1-a_{i+1}^2(V_i^TV_i-(V_i^Tn)^2)}=a_{i+1}V_i^Tn+b_{i+1}$
$b_{i+1}=-a_{i+1}V_i^Tn-\sqrt{1-a_{i+1}^2(V_i^TV_i-(V_i^Tn)^2)}$
which gives the required expression after putting $a_{i+1}=\mu_i/\mu_{i+1}$


text:
Variety Plus Icon Read Next: Director Jafar Panahi Anxiously Awaits Iranian Court Ruling on His Release From Jail
Aug 19, 2016 9:12am PT
Johnny Depp and Amber Heard: A Timeline of Their Tempestuous Relationship
Lamarco McClendon, Maria Cavassuto, Lawrence Yee
Michael Buckner/Variety/REX/Shutterstock
After months of fighting, Amber Heard and Johnny Depp suddenly settled their divorce this week, with Heard donating all of the settlement money to charity.
Their relationship was a tabloid magazine's dream: Hollywood A-lister falls in love with up-and-coming ingenue on set. Later, as allegations of abuse emerged, coverage of their relationship took a noticeably darker turn, with lurid reports — and later video and photos — of violent outbursts and alleged physical abuse.
Here's a look back at Johnny and Amber's tempestuous relationship.
Depp and Heard met on the set of "The Rum Diary" with Depp playing a journalist obsessed with Heard's character — a woman engaged to another man.
Depp and Heard started dating after the actor split from his long-time partner, Vanessa Paradis.
People Magazine reported the couple was engaged.
Depp showed off his engagement ring during an interview with ET, stating, "It's exciting to wear a girl's ring … I don't know, you know. It just fit."
A text message conversation retrieved by ET on June 1, 2016, reportedly showed Depp's abusive behavior toward Heard in May of 2014.
Depp and Heard tied the knot at the actor's private island in the Bahamas.
Depp suffered an injury to his right hand while filming "Pirates of the Caribbean: Dead Men Tell No Tales" in Australia. Reports said the injury occurred during an argument between Depp and Heard where he punched a wall.
May-June 2015
The couple faced legal trouble after it was discovered Heard brought their Yorkshire Terriers into Australia illegally. The two dogs were not subjected to Australia's 10-day quarantine, which could have resulted in up to 10 years in prison for the owners.
During an interview on "Jimmy Kimmel Live," Depp addressed the dog controversy saying, "We were under the impression we had all the paperwork done for the dogs." When the conversation turned to Heard's possible arrest, Depp went on to say "If they did that, I'd just fly to Australia and assault that man, so that I could go to jail."
Heard attended Depp's Hollywood Vampires Rock show in Los Angeles. ET correspondent Denny Directo said she appeared in good spirits at the show.
In Marie Claire's December issue, Heard addressed rumors that she and Depp were having trouble saying, "I try not to react to the horrible misrepresentation of our lives, but it is strange, and hard."
Heard and Depp issued an awkward video apology for having violated Australia's bio-security codes by bringing in their dogs without declaring them. "Australia is a wonderful island with a treasure trove of unique plants, animals and people," Heard said. "Australia is free of many pests and diseases that are commonplace around the world."
The apology was then mocked by many celebrities, including Stephen Colbert. Depp also mocked the apology, where he apologized for NOT smuggling his dogs into England during a press tour for "Alice Through the Looking Glass."
According to court documents, Heard claimed that Depp showed up to her birthday party on April 22 "inebriated and high" and "violently shoved me to the floor" after grabbing her by the hair.
Heard attended the Met Gala without Depp.
Depp's mother, Betty Sue Palmer, died after battling a long illness, ET confirmed. Depp had had a very close relationship with his mother — her name was tattooed inside a heart on his upper left arm.
According to court documents, Tillet Wright, a mutual friend of the couple, called 911 at the request of Heard. According to Heard, the conversation began very normally but then Depp "began obsessing about something that was untrue and his demeanor changed dramatically."
"Johnny then grabbed the cell phone, wound up his arm like a baseball pitcher and threw the cell phone at me striking my cheek and eye with great force," Heard claimed. "He then forcably pulled back my hair as I attempted to stand from the sofa … Johnny continued screaming at me, pulling my hair, striking me and violently grabbing my face."
The LAPD told ET that a third party called 911, claiming a domestic violence issue. When the LAPD arrived at Heard and Depp's home, she told them the altercation was only verbal but did not mention Depp by name, according to LAPD.
Depp and Heard separate.
Heard officially files for divorce, citing "irreconcilable differences." Depp attended the premiere of "Alice Through the Looking Glass" alone and then flew to New York for a performance with The Hollywood Vampires the next evening.
The news of Depp and Heard's divorce, as well as Depp's mother's death becomes public. Depp also filed a response to the divorce. He asked that Heard pay her own attorney fees and the separation of assets, including earnings made after they separated.
Depp's reps issued the following statement:
"Given the brevity of this marriage and the most recent and tragic loss of his mother, Johnny will not respond to any of the salacious false stories, gossip, misinformation and lies about his personal life. Hopefully the dissolution of this short marriage will be resolved quickly."
Heard issued a restraining order against Depp. The judge granted her a temporary restraining order, which prohibited Depp from getting less than 100 feet close to Heard and disallowed any contact with her.
"I live in fear that Johnny will return to the residence unannounced to terrorize me, physically and emotionally," said Heard in the court documents. TMZ first broke the story.
Depp's daughter, Lily Rose Depp, came to her father's defense with an Instagram post of her and her father when she was a baby, where she called him "sweetest most loving person" and "everyone who knows him would say the same."
Depp's ex-wife also came to his defense. In a letter obtained by TMZ, Vanessa Paradis wrote: "In all the years I have known Johnny, he has never been physically abusive with me and this looks nothing like the man I live with for 14 wonderful years."
Depp's first wife, Lori Anne Allison, has similar things to say about Depp. She also allegedly told her friends that she didn't believe Heard's statements, according to TMZ.
Heard's lawyers, Samantha F. Spector and Joseph P. Koenig, released the following statement to media outlets countering the initial May 21 police report: "Johnny's team has forced Amber to give a statement to the LAPD to set the record straight as to the true facts, as she cannot continue to leave herself open to the vicious false and malicious allegations that have infected the media. Amber has suffered through years of physical and psychological abuse at the hands of Johnny."
"We took the high road," the statement continued. "Unfortunately, Johnny's team immediately went to the press and began viciously attacking Amber's character. Amber is simply a victim of domestic violence, and none of her actions are motivated by money."
People Magazine published images of Heard with a bruises on her eye and lip.
Heard filed a defamation suit against comedian Doug Stanhope, who accused her of blackmailing Depp.
A video — recorded by Heard — surfaced on TMZ showing Depp kicking and slamming cabinet doors in their kitchen. Heard was heard apologizing for an undisclosed matter while Depp poured a glass of wine. Depp eventually noticed she had been recording the exchange and grabbed for the recording device.
TMZ published photos of what was allegedly Johnny Depp's fingertip cut off. The site reported Depp "accidentally cut off his fingertip in a fit of rage" and dipped it in blue paint and wrote "Billy Bob" on the wall. "Billy Bob" refers to actor Billy Bob Thornton, which some outlets said Amber reportedly cheated on Johnny with.
Heard's lawyers dismissed her request for a restraining order. Depp and Heard also settled their divorce.
"Our relationship was intensely passionate and at times volatile, but always bound by love," Depp and Heard said in a joint statement.
Heard announced her entire $7 million divorce settlement was going to two charities: the ACLU (with a focus on stopping violence against women) and Children's Hospital Los Angeles.
Amber Heard,
Beyonce Announces 'Renaissance' Stadium Tour Dates
La Brea Season 2 Resumes With Stampeding Buffalo, a Murder Mystery and a Twisted Ankle (RECAP)

redpajama_set_name: RedPajamaCommonCrawl


text:
Tiny Tina's Wonderlands
26 Nov 2021 2:05 PM +00:00 UTC
Tiny Tina's Wonderlands: Voice Actors and Cast
By Marie Pritchard
We list all of the confirmed voice actors and their roles for Tiny Tina's Wonderlands!
Tiny Tina's Wonderlands is the action role-playing first-person shooter from developers Gearbox Software. The game brings back and puts Tiny Tina, an explosive-loving thirteen-year-old in charge. The Wonderlands are a realm that the teenager has created to impress their friends. We're going to show you all of the currently confirmed voice actors and their roles in the game.
Read More: Video Game Release Dates 2022
Voice Actors and Cast
Tiny Tina: Ashly Burch
Dragon Lord: Will Arnett
Frette: Wanda Sykes
Captain Valentine: Andy Samberg
Tiny Tina - Ashly Burch
Dragon Lord - Will Arnett
Frette - Wanda Sykes
Captain Valentine - Andy Samberg
Tiny Tina is voiced by none other than the long-term videogame voice actor for the character, Ashly Burch. The name may sound familiar because Burch voices Aloy in Horizon Zero Dawn and its sequel Horizon Forbidden West. Aside from this, Burch has an extensive career in voice work for videogames and we cannot wait to see her as the explosive-loving Tiny Tina again!
Dragon Lord, who seems like the baddie in the game, is voice by Will Arnett who has so many acting credits to his name it would take ages to list them. However, you may know him from his work as Gob in Arrested Development or as the voice of Batman from the Lego Movie and Lego Batman!
Frette is voiced by stand-up comic and actor Wanda Sykes. Sykes has numerous acting, writing and stand-up credits to her name. Her career in stand-up comedy is highly successful and may know her from her role in Monster-In-Law or as the voice of Granny in the Ice Age movies. As Sykes is known for being extremely funny and she is no stranger to voice-over roles, Frette is shaping up to be a great character.
Andy Samberg is the voice of Captain Valentine. If you recognise the name then it may be because Samberg rose to fame on Saturday Night Live and he is known for his role as Jake Peralta in Brooklyn Nine-Nine. Samberg has quite a few voice acting roles under his belt too, including voicing Johnny in the Hotel Transylvania Films.
These are all of the confirmed voice actors and their roles for the game. When more information is revealed about the game and cast, we will update this page.
Tiny Tina's Wonderlands has a voice cast that makes it look like an exciting game. We have put together a few guides that answer some important questions about the game. We have one guide that answers if it's coming to Nintendo Switch and another that answers if it's coming to Game Pass.
Tiny Tina's Wonderlands: Is It a Standalone Game?
Tiny Tina's Wonderlands: Is It Coming to Game Pass?


Sidey offer FREE no obligation quotes for residents throughout the whole of the UK.
If you're looking for a Canopy, Carport or Veranda, we simply can't be beaten on quality or price.
Sidey were first established in 1932 and is currently one of the largest UK, most experienced fenestration solution providers.
With over 80 years' experience we have a proven track record of installing high quality, long lasting fenestration products whilst achieving high customer service standards.


text:
set -u # Undefined variables are errors

main() {
    assert_cmds
    set_globals
    handle_command_line_args "$@"
}

set_globals() {
    # Environment sanity checks
    assert_nz "$HOME" "\$HOME is undefined"
    assert_nz "$0" "\$0 is undefined"

    # Some constants
    version=0.0.1
    metadata_version=1

    # Find the location of the distribution server
    default_dist_server="https://static.rust-lang.org"
    insecure_dist_server="http://static-rust-lang-org.s3-website-us-west-1.amazonaws.com"
    dist_server="${RUSTUP_DIST_SERVER-$default_dist_server}"
    gpg_available=false

    # Check to see if GNUPG version 2 is installed, falling back to using version 1 by default
    gpg_exe=gpg
    if command -v gpg2 > /dev/null 2>&1; then
        gpg_exe=gpg2
    fi

    if command -v "$gpg_exe" > /dev/null 2>&1; then
        gpg_available=true
    fi

    # The directory on the server containing the dist artifacts
    rust_dist_dir=dist

    default_channel="stable"

    # Set up the rustup data dir
    rustup_dir="${RUSTUP_HOME-$HOME/.rustup.sh}"
    assert_nz "$rustup_dir" "rustup_dir"

    # Install prefix can be set by the environment
    default_prefix="${RUSTUP_PREFIX-/usr/local}"
    default_save=false
    if [ -n "${RUSTUP_SAVE-}" ]; then
        default_save=true
    fi

    # Data locations
    version_file="$rustup_dir/rustup-version"
    temp_dir="$rustup_dir/tmp"
    dl_dir="$rustup_dir/dl"

    # Set up the GPG key
    official_rust_gpg_key="
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1

[encoded data, 5148 characters]
=5FXw
-----END PGP PUBLIC KEY BLOCK-----
"

    if [ -n "${RUSTUP_GPG_KEY-}" ]; then
        gpg_key=$(cat "$RUSTUP_GPG_KEY")
    else
        gpg_key="$official_rust_gpg_key"
    fi

    # This is just used by test.sh for testing sha256sum fallback to shasum
    sha256sum_cmd="${__RUSTUP_MOCK_SHA256SUM-sha256sum}"

    flag_verbose=false
    flag_yes=false

    if [ -n "${RUSTUP_VERBOSE-}" ]; then
        flag_verbose=true
    fi
}

# Ensuresthat ~/.rustup.sh exists and uses the correct format
initialize_metadata() {
    local _disable_sudo="$1"

    verbose_say "checking metadata version"

    if [ "$rustup_dir" = "$HOME" ]; then
        err "RUSTUP_HOME is the same as HOME. this cannot be correct. aborting"
    fi

    # This tries to guard against dumb values of RUSTUP_HOME like ~/ since
    # rustup will delete the entire directory.
    if [ -e "$rustup_dir" -a ! -e "$version_file" ]; then
        say "rustup home dir exists at $rustup_dir but version file $version_file does not."
        say "this may be old rustup metadata, in which case it can be deleted."
        err "this is very suspicous. aborting."
    fi

    # Oh, my. We used to encourage people running this script as root,
    # and that resulted in users' ~/.rustup.sh directories being owned by
    # root (running `sudo sh` doesn't change $HOME apparently). Now
    # that we're not running as root, we can't touch our ~/.rustup.sh
    # directory. Try to fix that.
    if [ -e "$version_file" ]; then
        local _can_write=true
        local _probe_file="$rustup_dir/write-probe"
        ignore touch "$_probe_file" 2> /dev/null
        if [ $? != 0 ]; then
            _can_write=false
        else
            ensure rm "$_probe_file"
        fi

        if [ "$_can_write" = false ]; then
            say "$rustup_dir is unwritable. it was likely created by a previous rustup run under sudo"
            if [ "$_disable_sudo" = false ]; then
                say "deleting it with sudo"
                run sudo rm -R "$rustup_dir"
                if [ $? != 0 ]; then
                    err "unable to delete unwritable $rustup_dir"
                fi
            else
                say_err "not deleting it because of --disable-sudo"
                err "delete $rustup_dir to continue. aborting"
            fi
        fi
    fi

    ensure mkdir -p "$rustup_dir"
    rustup_dir="$(abs_path "$rustup_dir")"
    assert_nz "$rustup_dir" "rustup_dir"

    if [ ! -e "$version_file" ]; then
        verbose_say "writing metadata version $metadata_version"
        echo "$metadata_version" > "$version_file"
        need_ok "failed to write metadata version"
    else
        local _current_version="$(ensure cat "$version_file")"
        assert_nz "$_current_version"
        verbose_say "got metadata version $_current_version"
        if [ "$_current_version" != "$metadata_version" ]; then
            # Wipe the out of date metadata.
            say "metadata is out of date. deleting."
            ensure rm -R "$rustup_dir"
            ensure mkdir -p "$rustup_dir"
            echo "$metadata_version" > "$version_file"
            need_ok "failed to write metadata version"
        fi
    fi
}

handle_command_line_args() {
    local _save="$default_save"
    local _date=""
    local _prefix="$default_prefix"
    local _uninstall=false
    local _channel=""
    local _help=false
    local _revision=""
    local _spec=""
    local _update_hash_file=""
    local _disable_ldconfig=false
    local _disable_sudo=false
    local _extra_targets=""
    local _add_target=""
    local _list_targets=false

    local _arg
    for _arg in "$@"; do
        case "${_arg%%=*}" in
            --save )
                _save=true
                ;;

            --uninstall )
                _uninstall=true
                ;;

            -h | --help )
                _help=true
                ;;

            --verbose)
                # verbose is a global flag
                flag_verbose=true
                ;;

            --disable-ldconfig)
                _disable_ldconfig=true
                ;;

            --disable-sudo)
                _disable_sudo=true
                ;;

            -y | --yes)
                # yes is a global flag
                flag_yes=true
                ;;

            --list-available-targets)
                _list_targets=true
                ;;

            --version)
                echo "rustup.sh $version"
                exit 0
                ;;

            --prefix)
                if is_value_arg "$_arg" "prefix"; then
                    _prefix="$(get_value_arg "$_arg")"
                fi
                ;;

            --channel)
                if is_value_arg "$_arg" "channel"; then
                  _channel="$(get_value_arg "$_arg")"
                fi
                ;;

            --date)
                if is_value_arg "$_arg" "date"; then
                  _date="$(get_value_arg "$_arg")"
                fi
                ;;

            --revision)
                if is_value_arg "$_arg" "revision"; then
                  _revision="$(get_value_arg "$_arg")"
                fi
                ;;

            --spec)
                if is_value_arg "$_arg" "spec"; then
                  _spec="$(get_value_arg "$_arg")"
                fi
                ;;

            --update-hash-file)
                if is_value_arg "$_arg" "update-hash-file"; then
                  # This option is used by multirust to short-circuit reinstalls
                  # when the channel has not been updated by examining a content
                  # hash in the update-hash-file
                  _update_hash_file="$(get_value_arg "$_arg")"
                fi
                ;;

            --with-target)
                if is_value_arg "$_arg" "with-target"; then
                  local _next_extra_target="$(get_value_arg "$_arg")"
                  _extra_targets="$_extra_targets $_next_extra_target"
                fi
                ;;

            --add-target)
                if is_value_arg "$_arg" "add-target"; then
                    _add_target="$(get_value_arg "$_arg")"
                fi
                ;;

            *)
                echo "Unknown argument '$_arg', displaying usage:"
                echo ${_arg%%=*}
                _help=true
                ;;

        esac

    done

    if [ "$_help" = true ]; then
        print_help
        exit 0
    fi

    # Try to run `any` command with `sudo` to check we have enough rights
    ensure maybe_sudo "$_disable_sudo" true

    # Make sure either rust256sum or shasum exists
    need_shasum_cmd

    # Check that the various toolchain-specifying flags don't conflict
    if [ -n "$_revision" ]; then
        if [ -n "$_channel" ]; then
            err "the --revision flag may not be combined with --channel"
        fi
        if [ -n "$_date" ]; then
            err "the --revision flag may not be combined with --date"
        fi
    fi

    if [ -n "$_spec" ]; then
        if [ -n "$_channel" ]; then
            err "the --spec flag may not be combined with --channel"
        fi
        if [ -n "$_revision" ]; then
            err "the --spec flag may not be combined with --revision"
        fi
    fi

    if [ -n "$_add_target" ]; then
        if [ -n "$_channel" ]; then
            err "the --add-target flag may not be combined with --channel"
        fi
        if [ -n "$_date" ]; then
            err "the --add-target flag may not be combined with --date"
        fi
        if [ -n "$_spec" ]; then
            err "the --add-target flag may not be combined with --spec"
        fi
        if [ -n "$_revision" ]; then
            err "the --add-target flag may not be combined with --revision"
        fi
    fi

    if [ "$_list_targets" = true ]; then
        if [ -n "$_channel" ]; then
            err "the --list-available-targets flag may not be combined with --channel"
        fi
        if [ -n "$_date" ]; then
            err "the --list-available-targets flag may not be combined with --date"
        fi
        if [ -n "$_spec" ]; then
            err "the --list-available-targets flag may not be combined with --spec"
        fi
        if [ -n "$_revision" ]; then
            err "the --list-available-targets flag may not be combined with --revision"
        fi
    fi

    if [ -z "$_channel" -a -z "$_revision" -a -z "$_spec" ]; then
        _channel="$default_channel"
    fi

    # Toolchain can be either a channel, channel + date, or an explicit version
    local _toolchain=""
    if [ -n "$_channel" ]; then
        validate_channel "$_channel"
        _toolchain="$_channel"
        if [ -n "$_date" ]; then
            validate_date "$_date"
            _toolchain="$_toolchain-$_date"
        fi
    elif [ -n "$_revision" ]; then
        _toolchain="$_revision"
    elif [ -n "$_spec" ]; then
        _toolchain="$_spec"
    fi
    assert_nz "$_toolchain" "toolchain"

    # --add-target is non-interactive
    if [ -n "$_add_target" ]; then
        flag_yes=true
    fi
    # --list-targets is non-interactive
    if [ -n "$_list_targets" ]; then
        flag_yes=true
    fi

    if [ "$flag_yes" = false ]; then
        # Running in interactive mode, check that a tty exists
        check_tty

        # Print the welcome / warning message and wait for confirmation
        print_welcome_message "$_prefix" "$_uninstall" "$_disable_sudo"

        get_tty_confirmation
    fi

    # All work is done in the ~/.rustup.sh dir, which will be deleted
    # afterward if the user doesn't pass --save. *If* ~/.rustup.sh
    # already exists and they *did not* pass --save, we'll pretend
    # they did anyway to avoid deleting their data.
    local _preserve_rustup_dir="$_save"
    if [ "$_save" = false -a -e "$version_file" ]; then
        verbose_say "rustup home exists but not asked to save. saving anyway"
        _preserve_rustup_dir=true
    fi

    # Make sure our data directory exists and is the right format
    initialize_metadata "$_disable_sudo"

    # OK, time to do the things
    local _succeeded=true
    if [ "$_list_targets" = true ]; then
        list_targets "$_prefix"
        if [ $? != 0 ]; then
            _succeeded=false
        fi
    elif [ -n "$_add_target" ]; then
        add_target_to_install "$_prefix" "$_add_target" "$_save" "$_disable_sudo"
        if [ $? != 0 ]; then
            _succeeded=false
        fi
    elif [ "$_uninstall" = false ]; then
        install_toolchain_from_dist "$_toolchain" "$_prefix" "$_save" "$_update_hash_file" \
                                    "$_disable_ldconfig" "$_disable_sudo" "$_extra_targets"
        if [ $? != 0 ]; then
            _succeeded=false
        fi
    else
        remove_toolchain "$_prefix" "$_disable_sudo"
        if [ $? != 0 ]; then
            _succeeded=false
        fi
    fi

    # Remove the temporary directory.
    # This will not happen if we hit certain hard errors earlier.
    if [ "$_preserve_rustup_dir" = false ]; then
        verbose_say "removing rustup home $rustup_dir"
        ensure rm -R "$rustup_dir"
    else
        verbose_say "leaving rustup home $rustup_dir"
    fi

    if [ "$_succeeded" = false ]; then
        exit 1
    fi
}

is_value_arg() {
    local _arg="$1"
    local _name="$2"

    echo "$_arg" | grep -q -- "--$_name="
    return $?
}

get_value_arg() {
    local _arg="$1"

    echo "$_arg" | cut -f2 -d=
}

validate_channel() {
    local _channel="$1"

    case "$_channel" in
        stable | beta | nightly )
            ;;
        * )
            err "channel must be either 'stable', 'beta', or 'nightly'"
            ;;
    esac
}

validate_date() {
    local _date="$1"

    case "$_date" in
        [0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] )
            ;;
        * )
            err "date must be in YYYY-MM-DD format"
            ;;
    esac
}

print_welcome_message() {
    local _prefix="$1"
    local _uninstall="$2"
    local _disable_sudo="$3"

    cat <<EOF

Welcome to Rust.
EOF

    if [ "$_disable_sudo" = false ]; then
        if [ "$(id -u)" = 0 ]; then
            cat <<EOF

WARNING: This script appears to be running as root. While it will work
correctly, it is no longer necessary for rustup.sh to run as root.
EOF
        fi
    fi

    if [ "$_uninstall" = false ]; then
        cat <<EOF

This script will download the Rust compiler and its package manager, Cargo, and
install them to $_prefix. You may install elsewhere by running this script
with the --prefix=<path> option.
EOF
    else
        cat <<EOF

This script will uninstall the existing Rust installation at $_prefix.
EOF
    fi

    if [ "$_disable_sudo" = false ]; then
        cat <<EOF

The installer will run under 'sudo' and may ask you for your password. If you do
not want the script to run 'sudo' then pass it the --disable-sudo flag.
EOF
    fi

    if [ "$_uninstall" = false ]; then
        cat <<EOF

You may uninstall later by running $_prefix/lib/rustlib/uninstall.sh,
or by running this script again with the --uninstall flag.
EOF
    fi

    echo
}

# Updating toolchains

# Returns 0 on success, 1 on error
install_toolchain_from_dist() {
    local _toolchain="$1"
    local _prefix="$2"
    local _save="$3"
    local _update_hash_file="$4"
    local _disable_ldconfig="$5"
    local _disable_sudo="$6"
    local _extra_targets="$7"

    # FIXME: Right now installing rust over top of multirust will
    # result in a broken multirust installation.
    # This hack tries to avoid that by detecting if multirust is installed,
    # but I'd rather fix this by having the installers understand negative
    # dependencies.
    local _potential_multirust_bin="$_prefix/bin/multirust"
    if [ -e "$_potential_multirust_bin" ]; then
        say_err "multirust appears to be installed at the destination, $_potential_multirust_bin"
        say_err "installing rust over multirust will result in breakage."
        local _potential_uninstaller="$_prefix/lib/rustlib/uninstall.sh"
        if [ -e "$_potential_uninstaller" ]; then
            say_err "consider uninstalling multirust first by running $_potential_uninstaller"
        fi
        err "aborting"
    fi

    if [ "$gpg_available" = true ]; then
        # disabling https avoids rust#21293
        say "gpg available. signatures will be verified"
    else
        say "gpg not available. signatures will not be verified"
    fi

    get_architecture || return 1
    local _arch="$RETVAL"
    assert_nz "$_arch" "arch"

    # Inspect any existing installation for additional stds that must be upgraded
    # and add them to the list
    merge_existing_extra_targets "$_extra_targets" "$_arch" "$_prefix" || return 1
    _extra_targets="$RETVAL"

    # We're going to fill in this variables by interrogating the channel
    # metadata. There are two revisions of the channel metadata, v1 was
    # a very simple list of binaries; v2 has richer information about
    # the available packages.

    # The URL of the main installer
    local _remote_rust_installer
    # A space-separated list of other things to install
    local _extra_remote_installers

    local _manifest_to_stash=""

    # First, try to download a v2 manifest, before falling back to v1 codepaths.
    download_rust_manifest_v2 "$_toolchain"
    if [ $? = 0 ]; then
        local _manifest="$RETVAL"
        assert_nz "$_manifest" "manifest"

        # We'll save the manifest in the install folder for future modifications
        _manifest_to_stash="$_manifest"

        validate_manifest_v2 "$_manifest"
        if [ $? != 0 ]; then
            say_err "failed to validate channel manifest for '$_toolchain'"
            return 1
        fi

        determine_remote_rust_installer_location_v2 "$_manifest"
        if [ $? != 0 ]; then
            say_err "unable to find installer url in manifest"
            return 1
        fi
        _remote_rust_installer="$RETVAL"

        if [ "$_extra_targets" != "" ]; then
            # The user has asked for additional standard libraries.
            # Figure out where they are.
            determine_remote_std_locations_v2 "$_manifest" "$_extra_targets" || return 1
            _extra_remote_installers="$RETVAL"
        else
            _extra_remote_installers=""
        fi
    else
        verbose_say "unable to find v2 manifest. trying v1"

        if [ "$_extra_targets" != "" ]; then
            say_err "v1 manifests don't support --with-target"
            return 1
        else
            _extra_remote_installers=""
        fi

        determine_remote_rust_installer_location "$_toolchain" || return 1
        _remote_rust_installer="$RETVAL"
    fi

    assert_nz "$_remote_rust_installer" "remote rust installer"
    verbose_say "remote rust installer location: $_remote_rust_installer"

    say "downloading toolchain for '$_toolchain'"

    # Download and install rust package
    download_and_check "$_remote_rust_installer" false "$_update_hash_file"
    # Hey! I need to check $? twice here, so it has to be
    # assigned to a named variable, otherwise the second
    # check against $? will not be what I expect.
    local _retval=$?
    if [ "$_retval" = 20 ]; then
        say "'$_toolchain' is already up to date"
        # Successful short-circuit using the update-hash
        return 0
    fi
    if [ "$_retval" != 0 ]; then
        return 1
    fi
    local _rust_installer_file="$RETVAL"
    local _rust_installer_cache="$RETVAL_CACHE"
    local _rust_update_hash="$RETVAL_UPDATE_HASH"
    assert_nz "$_rust_installer_file" "rust_installer_file"
    assert_nz "$_rust_installer_cache" "rust_installer_cache"
    assert_nz "$_rust_update_hash" "rust_update_hash"

    say "installing toolchain for '$_toolchain'"

    install_toolchain "$_rust_installer_file" "$_prefix" \
                      "$_disable_ldconfig" "$_disable_sudo" "$_rust_installer_cache" "$_save"
    if [ $? != 0 ]; then
        say_err "failed to install toolchain"
        return 1
    fi

    # Download and install extra packages
    # NB: Splitting $_extra_remote_installers on space by not quoting
    local _extra_remote_installer
    for _extra_remote_installer in $_extra_remote_installers; do
        install_extra_component "$_prefix" "$_extra_remote_installer" "$_disable_sudo" "$_save"
    done

    # Write the update hash of the rust toolchain to file so that,
    # when invoked by multirust, the toolchain won't be reinstalled.
    if [ -n "$_update_hash_file" ]; then
        echo "$_rust_update_hash" > "$_update_hash_file"
        if [ $? != 0 ]; then
            say_err "failed to write update hash to file"
            return 1
        fi
    fi

    # Install the manifest for future updates
    if [ "$_manifest_to_stash" != "" ]; then
        # Fix for rust-lang/rust#32154. Somehow rustup.sh managed
        # until today to exist without escaping ~ in prefix. Probably
        # because it's only ultimately used by the install script,
        # which is called via sh. This command here though will fail
        # if prefix contains ~ so run it through `sh` to escape it.
        local _prefix="$(sh -c "printf '%s' $_prefix")"
        local _manifest_stash="$_prefix/lib/rustlib/channel-manifest.toml"
        ensure printf "%s" "$_manifest_to_stash" | \
            ensure maybe_sudo "$_disable_sudo" sh -c "cat > \"$_manifest_stash\""
    fi
}

merge_existing_extra_targets() {
    local _extra_targets="$1"
    local _primary_arch="$2"
    local _prefix="$3"

    local _components_file="$_prefix/lib/rustlib/components"

    if [ ! -e "$_components_file" ]; then
       RETVAL="$_extra_targets"
       return 0
    fi

    local _component
    while read _component in; do
        case "$_component" in
            rust-std-*)
                # Extract the triple
                local _arch="$(ensure printf "%s" "$_component" | ensure sed "s/rust-std-//")"
                assert_nz "$_arch", "arch"
                # See if we've already got it
                ignore printf "%s" "$_extra_targets" | grep -q "$_arch"
                if [ $? = 0 ]; then
                    verbose_say "already installing extra std component: $_arch"
                else
                    # See if it's the primary target
                    ignore printf "%s" "$_primary_arch" | grep -q "$_arch"
                    if [ $? = 0 ]; then
                        verbose_say "already installing extra std component: $_arch"
                    else
                        verbose_say "found extra std component: $_arch"
                        _extra_targets="$_extra_targets $_arch"
                    fi
                fi
                ;;
            *)
                ;;
        esac
    done < "$_components_file"

    RETVAL="$_extra_targets"
    return 0
}

install_toolchain() {
    local _installer_file="$1"
    local _prefix="$2"
    local _disable_ldconfig="$3"
    local _disable_sudo="$4"
    local _installer_cache="$5"
    local _save="$6"

    # Create a temp directory to put the downloaded toolchain
    make_temp_dir
    local _workdir="$RETVAL"
    assert_nz "$_workdir" "workdir"
    verbose_say "install work dir: $_workdir"

    local _failing=false
    install_toolchain_with_workdir "$_installer_file" "$_prefix" \
                                   "$_disable_ldconfig" "$_disable_sudo" "$_workdir"
    if [ $? != 0 ]; then
        _failing=true
    fi
    local _retval=$?

    run rm -R "$_workdir"
    if [ $? != 0 ]; then
        say_err "couldn't delete workdir"
        _failing=true
    fi

    # Throw away the cache if not --save
    if [ "$_save" = false ]; then
        verbose_say "discarding cache '$_installer_cache'"
        run rm -R "$_installer_cache"
        if [ $? != 0 ]; then
            say_err "couldn't delete cache dir"
            _failing=true
        fi
    fi

    if [ "$_failing" = true ]; then
        return 1
    fi
}

install_toolchain_with_workdir() {
    local _installer="$1"
    local _prefix="$2"
    local _disable_ldconfig="$3"
    local _disable_sudo="$4"
    local _workdir="$5"

    local _installer_dir="$_workdir/$(basename "$_installer" | sed s/.tar.gz$//)"

    # Extract the toolchain
    say "extracting installer"
    run tar xzf "$_installer" -C "$_workdir"
    if [ $? != 0 ]; then
        verbose_say "failed to extract installer"
        return 1
    fi

    # Install the toolchain
    local _toolchain_dir="$_prefix"
    verbose_say "installing toolchain to '$_toolchain_dir'"

    if [ "$_disable_ldconfig" = false ]; then
        maybe_sudo "$_disable_sudo" sh "$_installer_dir/install.sh" --prefix="$_toolchain_dir"
    else
        maybe_sudo "$_disable_sudo" sh "$_installer_dir/install.sh" --prefix="$_toolchain_dir" --disable-ldconfig
    fi
    if [ $? != 0 ]; then
        verbose_say "failed to install toolchain"
        return 1
    fi

}

remove_toolchain() {
    local _prefix="$1"
    local _disable_sudo="$2"
    local _uninstall_script="$_prefix/lib/rustlib/uninstall.sh"

    if [ -e "$_uninstall_script" ]; then
        verbose_say "uninstalling from '$_uninstall_script'"
        maybe_sudo "$_disable_sudo" sh "$_uninstall_script"
        if [ $? != 0 ]; then
            say_err "failed to remove toolchain"
            return 1;
        fi
        say "toolchain '$_toolchain' uninstalled"
    else
        say "no toolchain installed at '$_prefix'"
    fi
}

add_target_to_install() {
    local _prefix="$1"
    local _target="$2"
    local _save="$3"
    local _disable_sudo="$4"

    local _manifest_file="$_prefix/lib/rustlib/channel-manifest.toml"

    if [ ! -e "$_manifest_file" ]; then
        say_err "no channel manifest at '$_manifest_file'"
        return 1
    fi

    local _manifest="$(cat "$_manifest_file")"

    determine_remote_std_locations_v2 "$_manifest" "$_target" || return 1
    local _url="$RETVAL"

    # NB: No quotes around $url - it's a space-separated list with one element. Removing
    # the quotes to get rid of an extra space
    install_extra_component "$_prefix" $_url "$_disable_sudo" "$_save"
}

list_targets() {
    local _prefix="$1"

    local _manifest_file="$_prefix/lib/rustlib/channel-manifest.toml"

    if [ ! -e "$_manifest_file" ]; then
        say_err "no channel manifest at '$_manifest_file'"
        return 1
    fi

    local _manifest="$(cat "$_manifest_file")"

    toml_find_package_triples  "$_manifest" rust-std
    if [ $? != 0 ]; then
        say_err "error searching manifest for targets"
        return 1
    fi
    local _all_stds="$RETVAL"

    # NB: Not quoting to split on space
    local _std
    for _std in $_all_stds; do
        printf "%s\n" "$_std"
    done
}

install_extra_component() {
    local _prefix="$1"
    local _url="$2"
    local _disable_sudo="$3"
    local _save="$4"

    say "downloading extra component from $_url"
    download_and_check "$_url" false ""
    # Don't need to check for the second success value since
    # we didn't pass an update hash file to download_and_check
    if [ $? != 0 ]; then
        return 1
    fi
    local _extra_installer_file="$RETVAL"
    local _extra_installer_cache="$RETVAL_CACHE"
    assert_nz "$_extra_installer_file" "extra_installer_file"
    assert_nz "$_extra_installer_cache" "extra_installer_cache"

    say "installing extra component from $_extra_installer_file"

    install_toolchain "$_extra_installer_file" "$_prefix" \
                      "$_disable_ldconfig" "$_disable_sudo" "$_extra_installer_cache" "$_save"
    if [ $? != 0 ]; then
        say_err "failed to install component"
        return 1
    fi
}

# Manifest v2 interface

# Returns 0 on success.
# Returns the manifest as a string in RETVAL
download_rust_manifest_v2() {
    local _toolchain="$1"

    verbose_say "dist_server: $dist_server"

    case "$_toolchain" in
        nightly | beta | stable )
            local _remote_rust_manifest="$dist_server/$rust_dist_dir/channel-rust-$_toolchain.toml"
            ;;

        nightly-* | beta-* | stable-* )
            extract_channel_and_date_from_toolchain "$_toolchain" || return 1
            local _channel="$RETVAL_CHANNEL"
            local _date="$RETVAL_DATE"
            assert_nz "$_channel" "channel"
            assert_nz "$_date" "date"
            local _remote_rust_manifest="$dist_server/$rust_dist_dir/$_date/channel-rust-$_channel.toml"
            ;;

        *)
            verbose_say "interpreting toolchain spec as explicit version"
            local _remote_rust_manifest="$dist_server/$rust_dist_dir/channel-rust-$_toolchain.toml"
            ;;

    esac

    download_manifest "$_toolchain" "rust" "$_remote_rust_manifest" || return 1
    local _manifest_file="$RETVAL"
    local _manifest_cache="$RETVAL_CACHE"

    local _manifest="$(cat "$_manifest_file")"

    if [ $? != 0 ]; then
        say_err "unable to load manifest from disk"
        run rm -R "$_manifest_cache"
        return 1
    fi

    run rm -R "$_manifest_cache" || return 1
    RETVAL="$_manifest"
    return 0
}

validate_manifest_v2() {
    local _manifest="$1"

    toml_find_manifest_version "$_manifest"
    if [ $? != 0 ]; then
        say_err "unable to find manifest version"
        return 1
    fi
    local _manifest_version="$RETVAL"
    assert_nz "$_manifest_version" "manifest_version"

    case "$_manifest_version" in
        2 )
            ;;
        * )
            say_err "channel manifest has unknown version: $_manifest_version"
            return 1
            ;;
    esac
}

determine_remote_rust_installer_location_v2() {
    local _manifest="$1"

    get_architecture || return 1
    local _arch="$RETVAL"
    assert_nz "$_arch" "arch"

    toml_find_package_url "$_manifest" rust "$_arch"
    if [ $? != 0 ]; then
        say_err "unable to find rust package url in manifest"
        return 1
    fi
    local _url="$RETVAL"
    RETVAL="$_url"
}

determine_remote_std_locations_v2() {
    local _manifest="$1"
    local _targets="$2"

    # A space-separated list of URLs of std installers
    local _urls=""

    # Replace commas with spaces
    _targets="$(printf "%s" "$_targets" | sed "s/,/ /g")"

    local _target
    # NB: Purposefully not quoting $_targets to split on space
    for _target in $_targets; do
        toml_find_package_url "$_manifest" rust-std "$_target"
        if [ $? != 0 ]; then
            say_err "unable to find package url for std, for $_target"
            return 1
        fi
        _urls="$_urls $RETVAL"
    done

    RETVAL="$_urls"
}

# Manifest v2 toml parsing

toml_find_package_url() {
    local _manifest="$1"
    local _package="$2"
    local _arch="$3"

    verbose_say "looking for pkg.$_package.target.$_arch in manifest"

    make_temp_dir
    local _workdir="$RETVAL"
    assert_nz "$_workdir" "workdir"

    # Put the manifest in a temp file so it can be read back in
    # Note the \n. This is needed for `read` to read the last line.
    # I was surprised.
    local _tmpfile="$_workdir/manifest"
    ensure printf "%s\n" "$_manifest" > "$_tmpfile"

    local _found_package=false
    local _found_url=false
    local _url=""
    local _line
    while read _line; do
        case "$_line" in
            # First look for the package header
            *"[pkg.$_package.target.$_arch]"*)
                verbose_say "found $_package.$_arch section in manifest"
                if [ "$_found_package" = true ]; then err "found package twice"; fi
                _found_package=true
                ;;

             # Then find the url
             *url*=*)
                if [ "$_found_package" = true -a "$_found_url" = false ]; then
                    _url="$(ensure printf "%s" "$_line" | ensure sed 's/.*url.*\"\(.*\)\".*/\1/')"
                    assert_nz "$_url" "url is empty!"
                    verbose_say "url: $_url"
                    _found_url=true
                fi
                ;;
        esac
    done < "$_tmpfile"

    ensure rm -R "$_workdir"

    if [ "$_url" = "" ]; then
        return 1
    fi

    RETVAL="$_url"
}

toml_find_package_triples() {
    local _manifest="$1"
    local _package="$2"

    make_temp_dir
    local _workdir="$RETVAL"
    assert_nz "$_workdir" "workdir"

    local _tmpfile="$_workdir/manifest"
    ensure printf "%s\n" "$_manifest" > "$_tmpfile"

    local _triples=""
    local _line
    while read _line; do
        case "$_line" in
            *"[pkg.$_package.target".*"]"*)
                verbose_say "found $_package in manifest"
                local _triple="$(ensure printf "%s" "$_line" | ensure sed "s/.*pkg\.$_package\.target\.\(.*\)]/\1/")"
                verbose_say "triple: $_triple"
                _triples="$_triples $_triple"
            ;;
        esac
    done < "$_tmpfile"

    ensure rm -R "$_workdir"

    RETVAL="$_triples"
}

toml_find_manifest_version() {
    local _manifest="$1"

    make_temp_dir
    local _workdir="$RETVAL"
    assert_nz "$_workdir" "workdir"

    local _tmpfile="$_workdir/manifest"
    ensure printf "%s\n" "$_manifest" > "$_tmpfile"

    local _manifest_version=""
    local _line
    while read _line; do
        case "$_line" in
             *manifest-version*=*)
                _manifest_version="$(ensure printf "%s" "$_line" | ensure sed 's/.*manifest-version.*\"\(.*\)\".*/\1/')"
                assert_nz "$_manifest_version" "manifest_version is empty!"
                verbose_say "manifest-version: $_manifest_version"
                ;;
        esac
    done < "$_tmpfile"

    ensure rm -R "$_workdir"

    if [ "$_manifest_version" = "" ]; then
        return 1
    fi

    RETVAL="$_manifest_version"
}

# Manifest v1 interface

determine_remote_rust_installer_location() {
    local _toolchain="$1"

    verbose_say "determining remote rust installer for '$_toolchain'"

    case "$_toolchain" in
        nightly | beta | stable | nightly-* | beta-* | stable-* )
            download_rust_manifest "$_toolchain" || return 1
            local _manifest_file="$RETVAL"
            assert_nz "$_manifest_file" "manifest file"
            local _manifest_cache="$RETVAL_CACHE"
            assert_nz "$_manifest_cache" "manifest cache"
            get_remote_installer_location_from_manifest "$_toolchain" "$_manifest_file" rust "$rust_dist_dir" || return 1
            RETVAL="$RETVAL"
            verbose_say "deleting cache dir $_manifest_cache"
            run rm -R "$_manifest_cache" || return 1
            ;;

        * )
            verbose_say "interpreting toolchain spec as explicit version"
            get_architecture || return 1
            local _arch="$RETVAL"
            assert_nz "$_arch" "arch"

            local _file_name="rust-$_toolchain-$_arch.tar.gz"
            RETVAL="$dist_server/$rust_dist_dir/$_file_name"
            ;;
    esac
}

# Returns 0 on success.
# Returns the manifest file in RETVAL and its cache dir in RETVAL_CACHE.
download_rust_manifest() {
    local _toolchain="$1"

    case "$_toolchain" in
        nightly | beta | stable )
            local _remote_rust_manifest="$dist_server/$rust_dist_dir/channel-rust-$_toolchain"
            ;;

        nightly-* | beta-* | stable-* )
            extract_channel_and_date_from_toolchain "$_toolchain" || return 1
            local _channel="$RETVAL_CHANNEL"
            local _date="$RETVAL_DATE"
            assert_nz "$_channel" "channel"
            assert_nz "$_date" "date"
            local _remote_rust_manifest="$dist_server/$rust_dist_dir/$_date/channel-rust-$_channel"
            ;;

        *)
            err "unrecognized toolchain spec: $_toolchain"
            ;;

    esac

    download_manifest "$_toolchain" "rust" "$_remote_rust_manifest" || return 1
    RETVAL="$RETVAL"
    RETVAL_CACHE="$RETVAL_CACHE"
}

download_manifest()  {
    local _toolchain="$1"
    local _name="$2"
    local _remote_manifest="$3"

    verbose_say "remote $_name manifest: $_remote_manifest"

    say "downloading manifest for '$_toolchain'"
    # It's not possible for $? = 20 here, because the update_hash_file
    # param is empty
    download_and_check "$_remote_manifest" true "" || return 1
    RETVAL="$RETVAL"
    RETVAL_CACHE="$RETVAL_CACHE"
}

get_remote_installer_location_from_manifest() {
    local _toolchain="$1"
    local _manifest_file="$2"
    local _package_name="$3"
    local _dist_dir="$4"

    if [ ! -e "$_manifest_file" ]; then
        err "manifest file '$_manifest_file' does not exist"
    fi

    get_architecture
    local _arch="$RETVAL"
    assert_nz "$_arch" "arch"

    local _line
    while read _line; do
        # This regex checks for the version in addition to the package name because there
        # are package names that are substrings of other packages, 'rust-docs' vs. 'rust'.
        echo "$_line" | egrep "^$_package_name-(nightly|beta|alpha|[0-9]).*$_arch\.tar\.gz" > /dev/null
        if [ $? = 0 ]; then
            case "$_toolchain" in
                nightly | beta | stable )
                    RETVAL="$dist_server/$_dist_dir/$_line"
                    ;;

                nightly-* | beta-* | stable-* )
                    extract_channel_and_date_from_toolchain "$_toolchain" || return 1
                    local _channel="$RETVAL_CHANNEL"
                    local _date="$RETVAL_DATE"
                    assert_nz "$_channel" "channel"
                    assert_nz "$_date" "date"
                    RETVAL="$dist_server/$_dist_dir/$_date/$_line"
                    ;;

                *)
                    err "unrecognized toolchain spec: $_toolchain"
                    ;;
            esac
            return
        fi
    done < "$_manifest_file"

    err "couldn't find remote installer for '$_arch' in manifest"
}

extract_channel_and_date_from_toolchain() {
    local _toolchain="$1"

    case "$_toolchain" in
        nightly-20[0-9][0-9]-[0-9][0-9]-[0-9][0-9] | \
        beta-20[0-9][0-9]-[0-9][0-9]-[0-9][0-9] | \
        stable-20[0-9][0-9]-[0-9][0-9]-[0-9][0-9] )
            local _channel="$(ensure echo "$_toolchain" | ensure cut -d- -f1)"
            assert_nz "$_channel" "channel"
            local _date="$(ensure echo "$_toolchain" | ensure cut -d- -f2,3,4)"
            assert_nz "$_date" "date"
            RETVAL_CHANNEL="$_channel"
            RETVAL_DATE="$_date"
            ;;

        *)
            err "unrecognized toolchain spec: $_toolchain"
            ;;

    esac
}

# Tools

# FIXME: Temp names based on pid need to worry about pid recycling
make_temp_name() {
    local _pid="$$"
    assert_nz "$_pid" "pid"

    local _tmp_number="${NEXT_TMP_NUMBER-0}"
    local _tmp_name="tmp-$_pid-$_tmp_number"
    NEXT_TMP_NUMBER=$((_tmp_number + 1))
    need_ok "failed to create temp number"
    assert_nz "$NEXT_TMP_NUMBER" "NEXT_TMP_NUMBER"
    RETVAL="$_tmp_name"
}

make_temp_dir() {
    ensure mkdir -p "$temp_dir"

    ensure make_temp_name
    local _tmp_name="$temp_dir/$RETVAL"
    ensure mkdir -p "$_tmp_name"
    RETVAL="$_tmp_name"
}

# Returns 0 on success, like sha256sum
check_sums() {
    local _sumfile="$1"

    # Hackily edit the sha256 file to workaround a bug in the bots' generation of sums
    make_temp_dir
    local _workdir="$RETVAL"
    assert_nz "$_workdir" "workdir"

    sed s/tmp\\/dist\\/.*\\/final\\/// "$_sumfile" > "$_workdir/tmpsums"
    need_ok "failed to generate temporary checksums"

    local _sumfile_dirname="$(dirname "$_sumfile")"
    assert_nz "$_sumfile_dirname" "sumfile_dirname"
    if command -v "$sha256sum_cmd" > /dev/null 2>&1; then
        (run cd "$_sumfile_dirname" && run "$sha256sum_cmd" -c "$_workdir/tmpsums" > /dev/null)
    elif command -v shasum > /dev/null 2>&1; then
        (run cd "$_sumfile_dirname" && run shasum -c -a 256 "$_workdir/tmpsums" > /dev/null)
    else
        err "need either sha256sum or shasum"
    fi
    local _sum_retval=$?

    run rm -R "$_workdir" || return 1

    return $_sum_retval
}

# Outputs 40-char sum to stdout
create_sum() {
    local _input="$1"

    local _sum="none"
    if command -v "$sha256sum_cmd" > /dev/null 2>&1; then
        _sum="$(run "$sha256sum_cmd" "$_input" | run head -c 40)"
    elif command -v shasum > /dev/null 2>&1; then
        _sum="$(run shasum -a 256 "$_input" | run head -c 40)"
    else
        err "need either sha256sum or shasum"
    fi
    local _sum_retval=$?
    assert_nz "$_sum" "sum"

    ensure printf "$_sum"
    return  $_sum_retval
}

need_shasum_cmd() {
    if ! command -v "$sha256sum_cmd" > /dev/null 2>&1; then
        if ! command -v shasum > /dev/null 2>&1; then
            err "need either sha256sum or shasum"
        else
            verbose_say "sha256sum not available. falling back to shasum"
        fi
    fi
}

get_architecture() {

    verbose_say "detecting architecture"

    local _ostype="$(uname -s)"
    local _cputype="$(uname -m)"

    verbose_say "uname -s reports: $_ostype"
    verbose_say "uname -m reports: $_cputype"

    if [ "$_ostype" = Darwin -a "$_cputype" = i386 ]; then
        # Darwin `uname -s` lies
        if sysctl hw.optional.x86_64 | grep -q ': 1'; then
            local _cputype=x86_64
        fi
    fi

    case "$_ostype" in

        Linux)
            local _ostype=unknown-linux-gnu
            ;;

        FreeBSD)
            local _ostype=unknown-freebsd
            ;;

        DragonFly)
            local _ostype=unknown-dragonfly
            ;;

        Darwin)
            local _ostype=apple-darwin
            ;;

        MINGW* | MSYS* | CYGWIN*)
            local _ostype=pc-windows-gnu
            ;;

        *)
            err "unrecognized OS type: $_ostype"
            ;;

    esac

    case "$_cputype" in

        i386 | i486 | i686 | i786 | x86)
            local _cputype=i686
            ;;

        xscale | arm)
            local _cputype=arm
            ;;

        armv6l)
            local _cputype=arm
            local _ostype="${_ostype}eabihf"
            ;;

        armv7l)
            local _cputype=armv7
            local _ostype="${_ostype}eabihf"
            ;;

        x86_64 | x86-64 | x64 | amd64)
            local _cputype=x86_64
            ;;

        *)
            err "unknown CPU type: $_cputype"

    esac

    # Detect 64-bit linux with 32-bit userland
    if [ $_ostype = unknown-linux-gnu -a $_cputype = x86_64 ]; then
        # $SHELL does not exist in standard 'sh', so probably only exists
        # if configure is running in an interactive bash shell. /usr/bin/env
        # exists *everywhere*.
        local _bin_to_probe="${SHELL-bogus_shell}"
        if [ ! -e "$_bin_to_probe" -a -e "/usr/bin/env" ]; then
            _bin_to_probe="/usr/bin/env"
        fi
        # $SHELL may be not a binary
        if [ -e "$_bin_to_probe" ]; then
            file -L "$_bin_to_probe" | grep -q "text"
            if [ $? = 0 ]; then
                _bin_to_probe="/usr/bin/env"
            fi
        fi
        if [ -e "$_bin_to_probe" ]; then
            file -L "$_bin_to_probe" | grep -q "x86[_-]64"
            if [ $? != 0 ]; then
                local _cputype=i686
            fi
        fi
    fi

    local _arch="$_cputype-$_ostype"
    verbose_say "architecture is $_arch"

    RETVAL="$_arch"
}

check_sig() {
    local _sig_file="$1"
    local _quiet="$2"

    if ! command -v "$gpg_exe" > /dev/null 2>&1; then
        return
    fi

    make_temp_dir
    local _workdir="$RETVAL"
    assert_nz "$_workdir" "workdir"
    verbose_say "sig work dir: $_workdir"

    echo "$gpg_key" > "$_workdir/key.asc"
    need_ok "failed to serialize gpg key"

    # Convert the armored key to .gpg format so it works with --keyring
    verbose_say "converting armored key to gpg"
    run "$gpg_exe" --no-permission-warning --dearmor "$_workdir/key.asc"
    if [ $? != 0 ]; then
        ignore rm -R "$_workdir"
        return 1
    fi

    verbose_say "verifying signature '$_sig_file'"
    local _output="$("$gpg_exe" --no-permission-warning --keyring "$_workdir/key.asc.gpg" --verify "$_sig_file" 2>&1)"
    if [ $? != 0 ]; then
        ignore echo "$_output"
        say_err "signature verification failed"
        ignore rm -R "$_workdir"
        return 1
    fi

    if [ "$_quiet" = false -o "$flag_verbose" = true ]; then
        ensure echo "$_output"
    fi

    run rm -R "$_workdir" || return 1
}

# Downloads a remote file, its checksum, and signature and verifies them.
# Returns 0 on success. Returns the path to the downloaded file in RETVAL,
# and the path to it's directory in the cache in RETVAL_CACHE.
#
# The caller can decide to remove it from the cache by deleting RETVAL_CACHE.
#
# A return code of *20* indicates a successful short circuit from the
# update hash.
download_and_check() {
    local _remote_name="$1"
    local _quiet="$2"
    local _update_hash_file="$3"

    local _remote_basename="$(basename "$_remote_name")"

    make_temp_dir
    local _workdir="$RETVAL"
    assert_nz "$_workdir" "workdir"
    verbose_say "download work dir: $_workdir"

    download_checksum_for "$_remote_name" "$_workdir/$_remote_basename"
    if [ $? != 0 ]; then
        ignore rm -R "$_workdir"
        return 1
    fi

    # This is the unique name of the cache, based on the content hash
    local _cache_name="$(create_sum "$_workdir/$_remote_basename.sha256" | head -c 20)"
    need_ok "failed to name cache name from checksum"
    assert_nz "$_cache_name" "cache_name"

    # If the user already has this rev then don't redownload it
    if [ -n "$_update_hash_file" ]; then
        # NB: May fail if file does not exist
        local _update_hash="$(cat "$_update_hash_file" 2> /dev/null)"

        verbose_say "provided update hash: $_update_hash"
        verbose_say "new update hash: $_cache_name"

        if [ "$_cache_name" = "$_update_hash" ]; then
            run rm -R "$_workdir" || return 1
            # NB: Return code 20 is successful here!
            return 20
        fi
    fi

    # Create a cache directory under dl_dir for this download, based off the content hash
    local _cache_dir="$dl_dir/$_cache_name"
    verbose_say "cache dir: $_cache_dir"
    run mkdir -p "$_cache_dir"
    if [ $? != 0 ]; then
        say_err "failed to create download directory"
        ignore rm -R "$_workdir"
        return 1
    fi

    # Move the checksum into the cache. -f because the file may
    # already exist from previous download.
    verbose_say "moving '$_workdir/$_remote_basename.sha256' to '$_cache_dir/$_remote_basename.sha256'"
    run mv -f "$_workdir/$_remote_basename.sha256" "$_cache_dir/$_remote_basename.sha256"
    if [ $? != 0 ]; then
        say_err "failed to move checksum into download cache"
        ignore rm -R "$_workdir"
        ignore rm -R "$_cache_dir"
        return 1
    fi

    # Done with the workdir
    run rm -R "$_workdir"
    if [ $? != 0 ]; then
        say_err "couldn't delete workdir '$_workdir'"
        ignore rm -R "$_cache_dir"
        return 1
    fi

    download_file_and_sig "$_remote_name" "$_cache_dir" "$_quiet"
    if [ $? != 0 ]; then
        # Leave the cache dir to resume the download later
        return 1
    fi
    check_file_and_sig "$_cache_dir/$_remote_basename" "$_quiet"
    if [ $? != 0 ]; then
        # Whatever's in the cache doesn't add up. Delete it.
        ignore rm -R "$_cache_dir"
        return 1
    fi

    RETVAL="$_cache_dir/$_remote_basename"
    RETVAL_CACHE="$_cache_dir"
    RETVAL_UPDATE_HASH="$_cache_name"
}

download_checksum_for() {
    local _remote_name="$1"
    local _local_name="$2"

    local _remote_sums="$_remote_name.sha256"
    local _local_sums="$_local_name.sha256"

    local _remote_basename="$(basename "$_remote_name")"
    local _remote_sums_basename="$_remote_basename.sha256"
    assert_nz "$_remote_basename" "remote basename"

    make_temp_dir
    local _workdir="$RETVAL"
    assert_nz "$_workdir" "workdir"
    verbose_say "download work dir: $_workdir"

    verbose_say "downloading '$_remote_sums' to '$_workdir'"
    (run cd "$_workdir" && run curl -s -f -O "$_remote_sums")
    if [ $? != 0 ]; then
        say_err "couldn't download checksum file '$_remote_sums'"
        ignore rm -R "$_workdir"
        return 1
    fi

    verbose_say "moving '$_workdir/$_remote_sums_basename' to '$_local_sums'"
    run mv -f "$_workdir/$_remote_sums_basename" "$_local_sums"
    if [ $? != 0 ]; then
        say_err "couldn't move '$_workdir/$_remote_sums_basename' to '$_local_sums'"
        ignore rm -R "$_workdir"
        return 1
    fi

    run rm -R "$_workdir"
    if [ $? != 0 ]; then
        say_err "couldn't delete workdir '$_workdir'"
        return 1
    fi
}

download_file_and_sig() {
    local _remote_name="$1"
    local _local_dirname="$2"
    local _quiet="$3"

    local _remote_basename="$(basename "$_remote_name")"
    assert_nz "$_remote_basename" "remote basename"

    local _local_name="$_local_dirname/$_remote_basename"

    local _remote_sig="$_remote_name.asc"
    local _local_sig="$_local_name.asc"

    # curl -C does not seem to work when the file already exists at 100%,
    # so just delete it and redownload.
    if [ -e "$_local_sig" ]; then
        run rm "$_local_sig"
        if [ $? != 0 ]; then
            say_err "failed to delete existing local signature for '$_remote_name'"
            return 1
        fi
    fi

    verbose_say "downloading '$_remote_sig' to '$_local_sig'"
    (run cd "$_local_dirname" && run curl -s -C - -f -O "$_remote_sig")
    if [ $? != 0 ]; then
        say_err "couldn't download signature file '$_remote_sig'"
        return 1
    fi

    # Again, because curl -C doesn't like a complete file, short circuit
    # curl by checking the sum.
    local _local_sums_file="$_local_dirname/$_remote_basename.sha256"
    # Throwing away error text since this error is expected.
    check_sums "$_local_sums_file" > /dev/null 2>&1
    if [ $? = 0 ]; then
        verbose_say "checksum good. download already complete"
        return 0
    fi

    verbose_say "downloading '$_remote_name' to '$_local_name'"
    # Invoke curl in a way that will resume if necessary
    if [ "$_quiet" = false ]; then
        (run cd "$_local_dirname" && run curl -# -C - -f -O "$_remote_name")
    else
        (run cd "$_local_dirname" && run curl -s -C - -f -O "$_remote_name")
    fi
    if [ $? != 0 ]; then
        say_err "couldn't download '$_remote_name'"
        return 1
    fi
}

check_file_and_sig() {
    local _local_name="$1"
    local _quiet="$2"

    local _local_sums="$_local_name.sha256"
    local _local_sig="$_local_name.asc"

    verbose_say "verifying checksums for '$_local_name'"
    check_sums "$_local_sums"
    if [ $? != 0 ]; then
        say_err "checksum failed for '$_local_name'"
        return 1
    fi

    check_sig "$_local_sig" "$_quiet"
    if [ $? != 0 ]; then
        say_err "signature failed for '$_local_name'"
        return 1
    fi
}

# Verifies that the terminal can be opened or exits
check_tty() {
    # FIXME: This isn't sufficient since it just checks that tty
    # exists, not that it can be read
    if [ ! -e /dev/tty ]; then
        err "running in interactive mode (without -y), but cannot open /dev/tty"
    fi
}

# Waits for a y/n response and exits if n
get_tty_confirmation() {
    local _yn=""
    read -p "Continue? (y/N) " _yn < /dev/tty
    need_ok "failed to read from /dev/tty"

    echo

    if [ "$_yn" != "y" -a "$_yn" != "Y" -a "$_yn" != "yes" ]; then
        say "cancelling"
        exit 0
    fi
}

maybe_sudo() {
    local _disable_sudo="$1"

    shift

    get_architecture || return 1
    local _arch="$RETVAL"
    assert_nz "$_arch" "arch"

    local _is_windows=false
    case "$_arch" in
        *windows*)
            _is_windows=true
            ;;
    esac

    if [ "$_disable_sudo" = false -a "$_is_windows" = false ]; then
        run sudo "$@"
    else
        run "$@"
    fi
}

# Help

print_help() {
echo '
Usage: rustup.sh [--verbose]

Options:

     --channel=(stable|beta|nightly)   Install from channel (default stable)
     --date=<YYYY-MM-DD>               Install from archives
     --revision=<version-number>       Install a specific release
     --spec=<toolchain-spec>           Install from toolchain spec
     --prefix=<path>                   Install to a specific location (default /usr/local)
     --uninstall                       Uninstall instead of install
     --with-target=<triple>            Also install the standard library for the given target
     --add-target=<triple>             Updates an existing installation with a new target
     --list-available-targets          Lists targets available to an existing installation
     --disable-ldconfig                Do not run ldconfig on Linux
     --disable-sudo                    Do not run installer under sudo
     --save                            Save downloads for future reuse
     --yes, -y                         Disable the interactive mode
     --help, -h                        Display usage information
'
}

# Standard utilities

say() {
    echo "rustup: $1"
}

say_err() {
    say "$1" >&2
}

verbose_say() {
    if [ "$flag_verbose" = true ]; then
        say "$1"
    fi
}

err() {
    say "$1" >&2
    exit 1
}

need_cmd() {
    if ! command -v "$1" > /dev/null 2>&1
    then err "need '$1' (command not found)"
    fi
}

need_ok() {
    if [ $? != 0 ]; then err "$1"; fi
}

assert_nz() {
    if [ -z "$1" ]; then err "assert_nz $2"; fi
}

# Run a command that should never fail. If the command fails execution
# will immediately terminate with an error showing the failing
# command.
ensure() {
    "$@"
    need_ok "command failed: $*"
}

# This is just for indicating that commands' results are being
# intentionally ignored. Usually, because it's being executed
# as part of error handling.
ignore() {
    run "$@"
}

# Runs a command and prints it to stderr if it fails.
run() {
    "$@"
    local _retval=$?
    if [ $_retval != 0 ]; then
        say_err "command failed: $*"
    fi
    return $_retval
}

# Prints the absolute path of a directory to stdout
abs_path() {
    local _path="$1"
    # Unset CDPATH because it causes havok: it makes the destination unpredictable
    # and triggers 'cd' to print the path to stdout. Route `cd`'s output to /dev/null
    # for good measure.
    (unset CDPATH && cd "$_path" > /dev/null && pwd)
}

assert_cmds() {
    need_cmd dirname
    need_cmd basename
    need_cmd mkdir
    need_cmd cat
    need_cmd curl
    need_cmd mktemp
    need_cmd rm
    need_cmd egrep
    need_cmd grep
    need_cmd file
    need_cmd uname
    need_cmd tar
    need_cmd sed
    need_cmd sh
    need_cmd mv
    need_cmd awk
    need_cmd cut
    need_cmd sort
    need_cmd date
    need_cmd head
    need_cmd printf
    need_cmd touch
    need_cmd id
}

main "$@"

# vim: set noet ts=8 sts=4 sw=4:

redpajama_set_name: RedPajamaGithub


Aliens in underpants are back. This time, the aliens are on a mission to save the world. A huge meteorite is heading towards Earth and the aliens' supply of underpants is under threat. If the aliens are going to save the planet and protect their beloved underpants, they're going to have to act fast. Can they do it? Can they save the day?
From the creators of the bestselling Aliens in Underpants comes this new adventure featuring some unlikely heroes…in underpants. The book finds the aliens in the position of needing to save the world (and all the underpants) from a giant meteor. With quick thinking, they gather all the pants they can – including a pair of polka dotted bloomers – which they stitch together. The result is an enormous pair of pants that the aliens stretch across the planet to bounce the meteor back into space.
Written in rhyme, the prose seems to bounce along making this a great read-aloud book for preschoolers.
Ben Cort's illustrations are wonderful; full of colour, life and detail. The aliens come in all sorts of sizes, shapes and colours; as well as being featured in some rather garish underwear. There are plenty of small details providing lots to see on each page: graffiti on the spaceships; hiding aliens; and underpants appearing as flags, balloons and on bumper stickers.
Aliens in Underpants Save the World is light-hearted; a bit silly; and, above all, a really fun story.
Claire Freedman has written many children's books including Aliens Love Underpants, Squabble and Squawk and Follow That Bear If You Dare! She lives in Essex with her family. Ben Cort has illustrated for many picture books including Aliens Love Underpants, The Shark in the Dark and Muddle Jungle. He lives in Bedfordshire with his family.


I like to try and be organised, although I may be the most disorganised person on the planet at times. I love buying pretty diaries and journals, but after the first few days they lie unused and end up at the back of a drawer somewhere. When I discovered the Posh Coloring Planner I knew this wouldn't be one that falls foul of my laziness!
This book is a beautifully illustrated calendar/diary with loads of colouring included! It's in a 16-month weekly format with a new colouring page every 7 days, and has multiple styles of design to suit all colourists. As you can see in the slideshow below, the book starts off with monthly grids for you to see all 2015/2016 appointments at a glance, and then moves onto a double-page spread made up of diary and colouring page- I've included some images of the types of illustrations that there are. At the rear of the book you'll find spaces for addresses and phone numbers, emergency contacts, notes and planning pages for 2017.
The book is lovely to look at with a colourful glossy paisley cover and rounded corners, measuring 9x7 inches for handy portability. It has 54 colouring pages of several natural themes, including florals, geometrics, and swirls. Linework on the illustrations varies from wispy and fine to chunky and broad, and the paper is fairly thick and smooth. I'd advise using only pencils or water-based markers though so you don't ruin the diary page on the reverse.
Overall I think this is a first-class effort at combining colouring and daily planning, and has been wonderfully executed in both a fun and practical way. A few small Americanisms like the C for cellphone number and some odd emergency contact choices are the only things that give away the source of this book, but this is insignificant. I haven't yet started colouring as I want to wait until January and do it properly, but I can highly recommend this planner at face value, and for the price (currently £11.86).


text:
Snape Kills Dumbledore
Potter spoiler bookstore crash
by thegaypope
Full Snape kills Dumbledore scene straight from the upcoming Half-Blood Prince movie!
a-ha Helps Snape Kill Dumbledore
Marty McFly Bookstore Crash
Tom Hanks Finds New Harry Potter Book (Refresh)
Harry Potter and the Breakfast of Champions (Refresh)
Came here expecting for some humor? Well, Uncyclopedia has an article about Snape kills Dumbledore.
The Snape Kills Dumbledore fad began sometime in mid-July of 2005. Around then, the 6th Harry Potter book (Harry Potter and the Half-Blood Prince) was being released and it was mentioned that one of the main characters would not survive. When it was revealed it was Dumbledore, it quickly spread across the internet. A video then emerged of a person crashing Harry Potter release parties outside of several bookstores [1]. The famed dialogue (near the end of the clip) was as follows:
Driver: "Hey! Snape kills Dumbledore!"
Person waiting outside: NOOOOOOOOOO You Bitch! YOU BITCH!!"
The fad quickly exploded and showed no signs of stopping. The dialogue was used for various other sites. Interestingly, there were various varieties of the fad.
1 Page 606 Variety
2 The spoiler altered in various Media
3 One More Time
Page 606 Variety
The page 606 fad involved altering the page where the spoiler was mentioned (page 606 of HBP). Various other fads would be shown in the form of the writing seen on page 606. The music of choice was "Tarzan Boy" from the "Gay Fuel" fad. The song is available on Volume 1 of the YTMND Soundtrack.
The spoiler altered in various Media
The spoiler "Snape kills Dumbledore" was also depicted using various TV clips, video game FMVs, movie clips. For example, the site "Full Snape kills Dumbledore scene straight from the upcoming Half-Blood Prince movie!" showed a photoshopped version of the infamous spoiler scene from Final Fantasy VII with the faces of Snape and Dumbledore photoshopped on the characters.
See main article: Deathly Hallows Spoilers
In 2007, as the release of the 7th Harry Potter book approached "Harry Potter and the Deathly Hallows", the spoilers returned. This time, they were leaked on the internet (and YTMND) a few days before the release on July 21st.
Spoiler YTMNDs (by keyword)
Retrieved from "http://wiki.ytmnd.com/index.php?title=Snape_Kills_Dumbledore&oldid=45320"


If you're trying to live a "good" life then the Police Force is just for you!
You can get new friends, save citizens from trouble, arrest notorious criminals, become a hero and so on... It's not easy to become an officer tho'. You have to prove yourself to the Chief and the higher ranks that you can do whatever it takes to become an officer. You will have to learn the basic radio codes and how to handle big situations. There will be situations where you must risk your life. As you progress through the ranks you will earn more respect, gang members will fear you and you earn more fame for yourself.
After a time in the Force, you will have the feeling to get yourself a little better results, which will result in getting promoted. You can't just get infront of the Chief and say that you want a promotion. You must work hard and prove yourself that you want a promotion. It will take some time but, it will be worth it. It's not always necessary to be on duty. You can use the radio and say that you will go off-duty with your partner. You can go to a bar, donut shop and other shops like that to get yourselves something to eat or try going to a bowling alley, video game arcade, and so on..
The Special Weapons and Tactics aka "S.W.AT" are one of the most elite units in the Police Force. They're called in riots, bomb situations, hostage situations, bank robberies and situations like that. Most of the Police Officer join the S.W.A.T Unit in order to get themselves more fame in the Police Force. The S.W.A.T Commander holds trainings in the Department every week where most of the S.W.A.T Members participate in it.
The Detective Division is known for their hard work of solving serious cases which will require people with good logical skill. They have different departments where you can solve different cases. Sometimes detectives go undercover to get more information about a gang which is a dangerous job.
Community Resources Against Street Hoodlums or known mostly as "C.R.A.S.H" are the second elite division in the Force. They're like normal officers but the difference is that they have more skilled Police Officers in their unit, solving way bigger crimes than any regular officers. Some of their members are known to be corrupt.
There is another way of getting fame in the Police Force which is a risky one. There are officers who are known as "corrupt cops." They're abusing their powers in order to get better results in their work.
You can become corrupt aswell, but you have to be careful. If you're caught then you will be in deep trouble! You can try to get a corrupt officer fired but, it has a risk aswell. If the corrupt officer finds out you're trying to get him busted he will threaten you and might eventually end your life.


text:
Robert McFarlane
Bud McFarlane
13th National Security Advisor
October 17, 1983 – December 4, 1985
William Clark
John Poindexter
Deputy National Security Advisor
April 4, 1982 – October 17, 1983
James Nance
Counselor of the Department of State
February 28, 1981 – April 4, 1982
Rozanne L. Ridgway
James L. Buckley
Robert Carl McFarlane
(1937-07-12) July 12, 1937 (age 81)
Washington, D.C., U.S.
Jonda Riley
United States Naval Academy (BS)
Geneva Graduate Institute (MA)
National Defense University
Navy Distinguished Service Medal
Bronze Star (with valor)
Navy Commendation Medal (with valor)
Secretary's Distinguished Service Award
Navy Distinguished Public Service Award
Robert Carl "Bud" McFarlane (born July 12, 1937) is an American Marine Corps officer. He served as National Security Advisor to President of the United States Ronald Reagan from 1983 through 1985.[1]
McFarlane was involved in, and pleaded guilty to charges for actions related to, the Iran-Contra affair, but received a pardon from President George H. W. Bush.
↑ Smith, R. "McFarlane Calls SDI Pitch Misleading", Washington Post (1988-09-15): "Robert C. McFarlane, a key architect of President Reagan's 'Star Wars' plan to develop sophisticated defenses against Soviet ballistic missiles, said he has concluded 'There is no current basis for confidence that a survivable defensive shield is within reach' and that Reagan's announcement of it was misleading and simplistic."
Official Web Site of the Partnership for a Secure America
Official Web Site of the Committee on the Present Danger
Institute of World Politics
This short article about a person from the United States can be made longer. You can help Wikipedia by adding to it.
National Security Advisors of the United States
Cutler • Anderson • Jackson • Cutler • Gray • Bundy • Rostow • Kissinger • Scowcroft • Brzezinski • Allen • Clark • McFarlane • Poindexter • Carlucci • Powell • Scowcroft • Lake • Berger • Rice • Hadley • Jones • Donilon • Rice • Flynn • McMaster • Bolton
Retrieved from "https://simple.wikipedia.org/w/index.php?title=Robert_McFarlane&oldid=5795585"
United States National Security Advisors
American political writers
Writers from Washington, D.C.
Politicians from Washington, D.C.
American people stubs
This page was last changed on 19 September 2017, at 00:05.


text:
The Myth of Democratic Pacifism
by Thomas Schwartz, Kiron K. Skinner
Would a democracy wage war against another democracy? A "no" answer is now unassailable dogma in the halls of aca-deme. It is dogma too in the corridors of power, where it drives the Clinton Doctrine of peace and security through a crusade for democracy. "The best strategy to ensure our security and to build a durable peace," the president has said, "is to support the advance of democracy elsewhere. Democracies don't attack each other."
The idea, "democratic pacifism," is not new. Its academic champions venerate a two-hundred-year-old essay, "Perpetual Peace," by the philosopher Immanuel Kant. Enthusiasm grew in the 1980s, in part from some brilliant Kant-revival pieces by geopolitical theorist Michael Doyle, more from the worldwide outbreak of democracy.
Criticism of democratic pacifism is not new either. In Federalist 6, Alexander Hamilton attacked "the paradox of perpetual peace" as wrong and dangerous—wrong because it is naive about popular passions, dangerous because quack nostrums steal attention from real remedies. In a "republic," Kant thought, a majority would refuse to bear the cost of aggressive war. Hamilton saw, on the contrary, that majorities can be as belligerent as monarchs, clamoring for war not forced by foes.
Majorities did just that in 1812 and 1848. In the latter case, President Polk, who wanted to fight Mexico, had to resist popular pressure to fight Britain, too, over the U.S.-Canada boundary. In 1898 President McKinley gave in to popular pressure for war with Spain. In 1917 President Wilson easily ignited mass belligerency after campaigning against war the year before.
Another Kantian argument is that democratic decision making faces procedural hurdles and the need to enlist popular support, delaying decisions on both sides when democracies are in conflict and leaving time for peaceful resolution. But sometimes popular support is there already, sometimes the problem facing leaders is not to enlist it but to resist it, and often enough they have manufactured it with remarkable alacrity. Besides, democracies today have semimobilized standing forces with executive authority to use them.
A newer argument, the current favorite, is that states project internal norms outward: Because the democratic norm is that of peaceful conflict resolution, democrats follow it in conflicts with foreign democrats. But since when are norms projected outward? Hockey teams have "norms" for peacefully settling internal conflicts, but externally they compete as ruthlessly as possible. So do corporations and armies. How are states different? All durable states enjoy internal peace, but the democratic ones foster competition for power. Isn't that the democratic "norm"?
Alexander Hamilton was not naive about popular passions. He knew that majorities could be as belligerent as monarchs.
What do the facts show? Assuming lax enough tests of democracy, exceptions to democratic pacifism abound. With limited suffrage but the mother of parliaments, Britain fought the United States in 1776 and 1812 and revolutionary France in its comparatively democratic years of 1793 and 1795. In 1848 the United States fought Mexico, not a perfect democracy but a good one for the times: Mexico's elected Congress chose and deposed President Santa Anna and ratified the terms of peace. In the American Civil War, North and South shared a democratic history of fourscore and several years. One side had slaves, but so had the other, and if they were not democracies there were none.
After the Civil War, the hardest cases for democratic pacifism were the Boer and Spanish-American Wars and especially World War I. Woodrow Wilson proclaimed a war for democracy against "Prussian dictatorship," but that was propaganda. Germany had civil rights, an elected parliament, competing parties, universal male suffrage, and an unparalleled system of social democracy. Although appointed by the kaiser, ministries typically fell when their programs lost parliamentary votes. The kaiser was commander in chief, but so was the king of the Belgians, and so today is the king of Spain, lauded for using that power to defend democracy.
On the other side, Britain and France ruled most of their subjects with bullets, not ballots. Britain still had a potent House of Lords, and, unlike Germany, the United States disenfranchised a large minority of adult male citizens: Their color was wrong. Our point is not that Germany was a perfect democracy or the United States no democracy at all, only that democratic pacifists who microscopically examine Germany for nondemocratic bacteria do not subject the Allies to similar scrutiny: Either World War I was between democracies or there were none.
We can exclude those and other cases (the U.S.-French Naval War in 1797, Roman Republic versus France in 1849, Franco-Prussian War in 1870, War of the Pacific in 1879, Israel versus Lebanon in 1948 and 1967, United States versus Guatemala in 1954, Ecuador versus Peru in 1981 and 1995, Armenia versus Azerbaijian in 1992, recent Balkan wars, and so on) with tougher tests of democracy, including constitutional longevity. That pretty much shrinks the democratic category to the Cold War democracies, to those states that have continuously enjoyed high-class democratic regimes since soon after World War II. Indeed there have been no wars between them.
But mutual democracy is not the best explanation. Pick two states and a year at random and most likely they did not fight then. More important, most of the Cold War democracies formed a North Atlantic cluster riven by no deep disputes but menaced by the Soviet Empire, which did nothing to lure any away. That made them do two things: aim their weapons eastward and pool their forces in a security organization—one strong enough to enforce peace between them if need be. Of the high-class democracies outside NATO, some (Sweden, Finland, Austria, Switzerland) were neutrally clamped between NATO and the Soviet Empire, others (Costa Rica, India, Japan, Australia, New Zealand) lay far from sister democracies, and the remaining few (maybe Ireland, San Marino) were tabbies nestled next to tigers.
In their heroic defense of democratic pacifism, political scientists Zeev Maoz and Bruce Russett use statistical methods to argue that these explanations are not enough: Mutual democracy still has some effect on mutual peace when one controls for "alliance" and other factors. But alliances are a dime a dozen. No mere alliance, NATO was an armed and integrated organization. To control for "alliance" and find that NATO and our other factors do not fully explain peace between the Cold War democracies is like controlling for "passage of laws" and finding that the Social Security Act does not fully explain why retirees mysteriously received checks after 1935 but not before.
Adopt a tough enough test of democracy and democratic pacifism applies to naught but the Cold War democracies. Relax the test just a bit and the doctrine becomes false. But those democracies were either so far apart, so effectively neutralized in the vice jaws of NATO and the Soviet Empire, or so integrally organized against a common foe that the fifty-year peace between them—virtually the whole case for democratic pacifism—has better explanations than the magic of mutual democracy. Yes, "magic." For no one has plausibly said how mutual democracy blocks war.
Democratic pacifism is not the first doctrine to come into vogue among intellectuals, though logic and history point away. Its initial appeal is understandable: If true, it reconciles principle and prudence, gratifying the soft of heart and hard of head in one fell swoop. But true it is not.
Why, then, has it survived scrutiny by scholars and statesmen who should know better? The answer we think is the dual use Americans make of the word democracy. It has a descriptive use, marking off states that prize liberty and have popular elections to choose and change governments. But it is also a term of praise, used to distinguish good guys (like us) from bad guys (like them). Since aggressors cannot be democracies ("good guy" use), democracies (descriptive use) cannot be aggressors, can they?
Democracies don't fight democracies? How then does one explain the First World War?
That brings us back to Woodrow Wilson and Alexander Hamilton. The one invested prodigiously in war propaganda that incidentally but indelibly imprinted "democracy" in the American geopolitical lexicon as the highest term of praise. The other found preposterous the idea that there is something peculiarly pacific about popular majorities. Grievous exceptions may be rare—but war is rare.
Democracy is still a good thing, but like most good things it does not ensure peace between states that have it. Like most good things, therefore, it is a dangerous thing to rely on for that purpose. Praise democracy—but preserve the ammunition.
Adapted from the Wall Street Journal, January 7, 1999. Reprinted with permission of the Wall Street Journal. © 1999 Dow Jones & Company, Inc. All rights reserved.
Available from the Hoover Press is the Hoover Essay in Public Policy The Democratic Advantage: The Institutional Sources of State Power in International Competition, by Kenneth A. Schultz and Barry R. Weingast.
Thomas Schwartz
Kiron K. Skinner
More from Military
On Grand Strategy And China
by Williamson Murray


Integrate WebEDI with QuickBooks Enterprise | DataTrans Solutions, Inc.
Turn to DataTrans to create a QuickBooks integrated solution. Quickbooks is a commonly used accounting system. EDI suppliers needed a solution that would decrease manual data entry and time to export/ import purchase orders and invoices from their EDI portal to QuickBooks and vice versa. DataTrans integration is tailored to QuickBooks users by establishing a direct link between DataTrans WebEDI and QuickBooks system.
This integration allows for purchase orders and invoices to flow from WebEDI to QuickBooks and QuickBooks to WebEDI. As seen above, 850 Purchase Orders will integrate as QuickBooks Sales Orders and QuickBooks Pending Sales will integrate as 810 Invoices in WebEDI.
The DataTrans logo will appear next to the purchase order or invoice indicating it has been successfully integrated to and from QuickBooks. In QuickBooks you will find the 850 and 810 documents under the Reports tab. For Enterprise users the documents will be shown as Sales Order and Pending Sale.
DataTrans WebEDI QuickBooks Integrator was created to streamline the supply chain process while working from two different programs. This seamless integration fine tunes your current business processes freeing up more resources. Work smarter not harder.


text:
"Future Generations" to tackle global issues at meeting today
Town Carnival returns...for the last time?
Well done all!
"Greater clarity" in the relationship between Home Affairs and Law Enforcement.
Hospital staff housing to aid recruitment
A group of four sixth form students will lead public debate today on a number of global issues affecting people living in Guernsey.
Adam Sparkes, Tom Rylatt, Pieter Durman and Cameron Ashplant have organised a public forum, to be held at St James, which will initially look at issues around sustainability. They are already planning future events focusing on different issues.
The idea came about after the Youth Forum, with Sixth Form Centre pupil Pieter saying Deputy Lindsay de Sausmarez helped spark the idea for a youth led seminar. Deputy de Sausmarez has been very supportive and helped the boys and others support an amendment calling on the States of Guernsey to consider environmental impacts in future decisions. That was approved by the States during 2017.
Pieter told Express today's event has not been organised by, and isn't being led by, politicians though: "Lindsay has been engaged and it was the conversation there that kind of started this, but if anything, we've been having to update her because things move quickly and it's very much the young people leading it. There's been lots of people being supportive, and some of us are members of the Youth Forum, but it has just been an independent group of young people really just pushing for it ourselves with the support of...well Guernsey's got loads of great people so everyone's been really supportive and have given something."
While the four young men are fronting the Future Generations brand, there will be a number of other people helping out as stewards, providing entertainment and those who have done design and printing work.
The speakers this afternoon will vary between young people and experienced business leaders. Adam, the head boy of Elizabeth College, said he helped to organise the finance panel, which will make up part of the debate towards the end of the day, as the audience considers how sustainability and economy go hand in hand:
"We've got a partner from Carey Olsen, a person from the LSE here in Guernsey and potentially someone from Guernsey Electricity. They'll be looking at the ideas of the day and how we can implement those, especially given Guernsey's main economic sector is dominated by finance.
"I think looking at how we can diversify that to incorporate a more green financial approach to things is important."
Adam said they hope this event will "plant the seeds of change in as many of the decision makers as possible" and they want it to develop into something "great and green" for Guernsey's future.
Sixth Form Centre student Cameron continued, telling Express that there are alternatives and Guernsey needs to embrace them now:
"We really want to try and engage our audience; the island, to enter the debate about the environment. But we also need to try and make them aware that it's not just about the environment, and that everything is interconnected with politics, economics, society and the environment.
"I read a book by Kate Raworth called 'Doughnut Economics' which suggests a model called the Doughnut and it talks about how we can find a safe and just place for society. So I'm going to be introducing that model to the island and to attendees to the conference and hopefully encourage them to be innovative and to try and get involved in the debate and encourage communication between the public and States members and decision makers to try and encourage people to get involved the environmental debate on the day."
Sixth Form Centre student Tom said the four have been trying to encourage a number of people to attend today's conference through social media and also through visiting the island's secondary schools. He said it is important young people do get involved:
"We feel that if we equip young people with the facts right now and the solutions, and the solutions to the current problems, we believe we can expedite the process of making change to Guernsey's climate legislative agenda which leads to a healthier and better future environment for everyone to enjoy and for future generations to enjoy.
The event at St James starts at 13:00. It is free to attend and open to everyone of all ages.


text:
Q: UINavigationBar back button does not appear I have a navigationBar, with a UIImage on it's title, like this:
self.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"top_logo.png"]];

When i select a row, the "back" button does not appear. Why?
I have the exact same code on other's viewControllers, and it appears.
I don't understand why...
Thanks,
RL

A: The back button won't appear unless you've set self.navigationItem.title or 'self.title' in the previous view controller on the stack (parent VC) or explicitly created a UIBarButtonItem and set it to self.navigationItem.backBarButtonItem in the previous view controller on the stack (parent VC).

A: did you push the new view through the navigation stack?
like:
[self.navigationController pushViewController:viewControllerToPush animated:YES];

redpajama_set_name: RedPajamaStackExchange


text:
Lawyer: Writer jailed for life over poems praising the Arab Spring
The Emir of Qatar Sheikh Hamad bin Khalifa al-Thani speaks during a visit to the Islamic University in Gaza City on Oct. 23.Wissam Nassar / Pool via Reuters, file
DOHA, Qatar — A court in Qatar sentenced a poet to life in prison on Thursday for incitement to overthrow the government and criticizing the ruling emir, his lawyer said.
In his poetry, Muhammad Ibn al-Dheeb al-Ajami praised the Arab Spring revolts that have toppled dictators in four Arab countries since early last year and criticized Qatari Emir Sheikh Hamad bin Khalifa al-Thani.
Qatar has backed uprisings elsewhere in the Arab world.
'Miscarriage of justice'
Ajami, 36, who was not present in court, has been jailed in solitary confinement for almost a year. He has not seen his family during that time, according to his lawyer Nagib al-Naimi.
"This is a tremendous miscarriage of justice," Naimi told Reuters after the verdict, adding that he would appeal.
Ajami faced charges of "inciting the overthrow of the ruling regime", which carries the death penalty. Qatar's penal code provides sentences of five years in prison for criticising the country's ruler.
Qatar, a close U.S. ally and major oil and gas producer in the Gulf with a large American military base, has escaped the unrest engulfing other parts of the Arab world.
Doha finances and hosts the pan-Arab satellite TV network al-Jazeera, which has assiduously covered the Arab revolts, though it gave scant coverage to an uprising last year in neighboring Bahrain - ruled by a related Gulf Arab monarchy.
Self-censorship
The Qatari government has backed the armed revolt in Syria, a successful NATO-backed armed uprising in Libya, and street protests that ousted rulers in Egypt, Tunisia and Yemen.
But freedom of expression is tightly controlled in the small Gulf state, with self-censorship prevalent among national newspapers and other media outlets. Qatar has no organized political opposition.
In October, Human Rights Watch criticized what it said was a double standard on freedom of expression in Qatar and urged the emir not to approve a draft media law penalising criticism of the Gulf emirate and its neighbors.
More world stories from NBC News:
Tobacco industry uses trade pacts to try to snuff out anti-smoking laws
Syrians risk lives in battle to protect nation's ancient sites
An ocean away in UK, time is running out to claim $100 million lottery prize
ANALYSIS: Egypt learns the art of politics amid protests
Arafat's exhumation: Palestinians' desire for truth might be dashed again
Chinese paper falls for Onion 'sexiest man alive' spoof
ANALYSIS: Israeli defense chief quits politics — but for how long?
Scientists rush to save manta rays, the 'pandas of the ocean'
Follow World News from NBCNews.com on Twitter and Facebook