示例#1
0
    def ec2_params(self):
        if not self.ec2_iam_arn or not self.activity_arn or not self.script_name:
            raise Exception('missing config in ' + type(self).__name__)

        script_url = common.url('aws/hhvm1/worker/dummy-task.sh' if self.
                                fake_ec2 else 'aws/userdata/' +
                                self.script_name)
        init_url = (common.url(self.init_script)
                    if self.init_script and not self.fake_ec2 else '')
        after_task_url = (common.url(self.after_task_script) if
                          self.after_task_script and not self.fake_ec2 else '')
        return {
            'ImageId':
            'ami-6e1a0117',  # ubuntu 16.04
            'MaxCount':
            1,
            'MinCount':
            1,
            'InstanceType':
            't2.micro',
            'SecurityGroups': ['hhvm-binary-package-builders'],
            'InstanceInitiatedShutdownBehavior':
            'terminate',
            'IamInstanceProfile': {
                'Arn': self.ec2_iam_arn
            },
            'KeyName':
            'hhvm-package-builders',
            'TagSpecifications': [{
                'ResourceType':
                'instance',
                'Tags': [
                    {
                        'Key': 'Name',
                        'Value': 'ww-0-' + type(self).__name__,
                    },
                    {
                        'Key': 'ActivityArn',
                        'Value': self.activity_arn,
                    },
                ],
            }],
            'UserData':
            f'''#!/bin/bash
        ACTIVITY_ARN="{self.activity_arn}"
        SCRIPT_URL="{script_url}"
        INIT_URL="{init_url}"
        AFTER_TASK_URL="{after_task_url}"
        {common.format_env(self.worker_env())}
        {common.fetch('aws/hhvm1/worker/worker.sh')}
      ''',
        }
示例#2
0
def start():
    mark("sensors")
    # Convert a 16-bit number to 0 - 3.3 (Pico runs at 3.3volt)
    CONVERSION_FACTOR = 3.3 / 65535

    # Define the ADC pin number for the thermistor
    temperature_sensor = machine.ADC(4)

    # read voltage from temp sensor and convert into volts (0 - 3.3V)
    reading = temperature_sensor.read_u16() * CONVERSION_FACTOR

    # convert that to the actual temperature in Celsius:
    # 0.706V is 27 degrees C, with a slope of -1.721mV per degree.
    temperature = 27 - (reading - 0.706) / 0.001721

    oled_page("Sensors", "{temperature}C".format(temperature=temperature))
    print("""
Want to know a fun fact?

It's about {temperature} degrees Celsius where you are.

I can tell the approximate temperature from a sensor built in to me. In fact,
reading sensors is something I'm awesome at.

You can learn more at:

    {url}

When you'd like to move on:

    >>> import music
    >>> music.start()
""".format(url=url("sensors"), temperature=temperature))
示例#3
0
def start():
    mark("morse")
    oled_page("Morse Code")

    print("""
We're going to be exploring Morse Code, a way of encoding information in
lights or sound. Turn off any music so you can listen carefully.

You'll probably find it helpful to do a minute of research and find a chart
of Morse Code on the internet.
    """)

    input("Press RETURN when ready ? > ")

    play("Hello")
    input("""
Hear that? That was 'Hello')

Press RETURN when ready > """)

    play(name)
    print("""
Hear that? That was '{name}'

Now: listen to what I'm saying.
""".format(name=name))

    test_listen()

    print("""
Well done!

Now you try sending a message!

A short press for a dot, a long press for a dash. Pause about a second between
letters, about three seconds between words. When you're done, just wait ---
after five seconds, I'll finish your recording and tell you what you said.
""")

    input("""Press RETURN when ready > """)
    print(record())

    test_record()

    print("""
Great job! Learn more: 

    {url}

When you're ready to go on:

    >>> import cryptogram
    >>> cryptogram.start()
""".format(url=url("morse")))
示例#4
0
    def inform(self):
        print("""
Great job!

You can learn more about Micropython at 

    {url}

When you're ready to move on, go to:

    >>> import connectfour
    >>> connectfour.start()
""".format(url=url("micropython")))
示例#5
0
def start():
    mark("cryptogram")
    oled_page("Cryptogram")
    print("""
An important message arrived just a moment ago, but I can't seem
to puzzle out what it means:


MXCLAAPKA PB UJPYX QB VQOM QB JOPUPKA UVX YFMX PK UVX SPOBU EDQYX.
UVXOXSFOX, PS RFL JOPUX UVX YFMX QB YDXZXODR QB EFBBPCDX, RFL QOX,
CR MXSPKPUPFK, KFU BWQOU XKFLAV UF MXCLA PU.

UVX WFBU XSSXYUPZX MXCLAAPKA UFFD PB BUPDD YQOXSLD UVFLAVU,
YFLEDXM JPUV ILMPYPFLBDR EDQYXM EOPKU BUQUXWXKUB.

-- COPQK NXOKPAVQK


A friendly secret agent told me that it's enciphered using a
"monoalphabetic substitution cipher" (each letter in the message
corresponds in a 1-to-1 relationship with another letter.)

These kind of codes, often called "cryptograms", can be a fun
puzzle to solve. You can find some ideas about how to approach
one from the notes from my Cryptography lecture or at:

  https://www.simonsingh.net/The_Black_Chamber/crackingsubstitution.html
  
When you've broken the code, you can answer a question about the
quotation, and I'll tell you where to find the final step.
""")
    
    while True:
        subject = input("In one word, what is the subject of this quote? > ")
        if subject.lower() == "debugging":
            break
        print("\nNope.\n")
        
    rainbow()
    print("""
Great job! 

Read about this: 

    {url}

Proceed to the next step with:

  >> import yay
  yay.start()
""".format(url=url("decipher")))
示例#6
0
def start():
    mark("music")
    oled_page("Music!")

    led.high()
    for c in TAKE_ON_ME:
        play_note(c, 0.2)

    speaker.duty_u16(0)

    print("""
A-ha! :-)

I can hum decently well, can't I?

You can learn more at {url}

When you'd like to move on:

    >>> import morse
    >>> morse.start()
""".format(url=url("pwm")))
示例#7
0
def start():
    mark("yay")
    oled_page("Yay!")
    rainbow()

    print("""
You did it! It was fun for me to lead you through this.

And here's a personal message from Joel for you:

--

{joel_msg}

--

You can learn more, as well as get the table of contents for everything, along
with permission to dig into that mysterious envelope, at:
    
    {url}

<3 Pico, Joel, and Fluffy
""".format(joel_msg=joel_msg, url=url("yay")))
示例#8
0
def image():
	if ri(0,1) == 0:
		return url()
	else:
		return gradient()
示例#9
0
    def play(self):
        """Play game until someone wins."""

        while True:
            self.print_board()
            self.display_board()
            winner = self.is_game_won()
            if winner or self.is_filled():
                break

            if self.turn == _PLAYER:
                col = self.human_turn()
            else:
                col = self.ai_turn()

            row = self.get_row_for_col(col)
            self.board[7 * row + col] = self.turn
            self.last_play_rc = row, col

            if self.debug:
                print("position scores:", "player=",
                      score_position(self.board, _PLAYER), "ai=",
                      score_position(self.board, _AI))

            self.turn = _AI if self.turn == _PLAYER else _PLAYER

        if winner == 0:
            msg = "Tie!"
        elif winner == 1:
            msg = "You win!"
        else:
            msg = "I win!"

        oled.text(msg, 64, 30)
        oled.show()
        print("\n" + msg + "\n")

        if winner == 0 or winner == 1:
            if self.plies == 3:
                print("""
(Of course, you did set me to easy mode, which I feel compelled to mention.)
""")
            print("""

There are some interesting things to learn about ConnectFour:

    {url}

To move ahead:

    >>> import sensors
    >>> sensors.start()

""".format(url=url("connectfour")))

        else:
            print("""
Wow. You were beat by a $4 computer--using only one of my processors (!!).
To get the code to move ahead, you'll need to at least tie me.

To play again, make a new instance of the ConnectFour class. You can choose
different options than the defaults:

 connectfour.ConnectFour(plies, start_player, serial_input, debug)
  - plies [5]: moves to look ahead (3-6, where 3 is easy and 6 is slow and hard
  - start_player [0]: 0 for random, 1 for you, 2 for me
  - serial_input [False]: Enter moves w/keyboard in terminal instead of knob
  - debug [False]: Show information about current AI evaluation scores

For example:

    >>> g = ConnectFour(plies=4, start_player=1)
    >>> g.play()

""")
示例#10
0
def start():
    mark("welcome")
    oled_page("Hi " + name + "!", "The cursor at", "the bottom right",
              "means 'press the'", "black button'")
    wait()

    oled_page("I'm Pico!", "I'm so happy to", "meet you! Joel",
              "thinks you're", "awesome.")
    wait()

    oled_page("Getting Hints", "If you get stuck", "and need a hint",
              "use Slack", "#secret-pico")
    wait()

    oled_page("Let's begin!", "Let's move this", "convo to your",
              "laptop, ok?")
    wait()

    oled_page("Type in Shell:", "screen", "  /dev/tty.usb*", "",
              "& press RETURN")
    wait()

    oled_page("Connect to me!", "", "I'll be waiting", "for you there :)")
    wait(msg="Press black button")

    oled_page("Serial output")

    print("""
Hi again! It's me, Pico!

I'm a gift wrapped in a puzzle wrapped in an educational
experience. Joel made me just for you and your cohort-mates.

I've got lots to show you, plus a reward at the end. But
first, like any good hero, you have to overcome some challenges.
Don't give up too easily! Part of a challenge is figuring it out.
But, remember, if you get stuck, you ask in #pico-secret.
""")

    input("Press RETURN > ")

    print("""
Along the way, I have some learning material for you. For
example, you should read:

    {url}
""".format(url=url('pico')))

    input("Press RETURN when ready > ")

    print("""
I can be programmed in lots of languages but, of course,
Joel programmed me in Python. It's actually a version of Python
called MicroPython, meant to be run on tiny machines like me.
It has almost all of the normal language features, plus some
of the standard library. We'll be using it throughout.

You'll start each section by importing a Python module,
and then running it's `start()` function. You can always
revisit and earlier section by importing it. Of course, you
won't know all the future sections, so you can't jump ahead :).

Let's begin! I'm going to return you to my Python shell.
When you're ready, you should type:

    >>> import begin
    >>> begin.start()
    
See you there!
""")