Saturday, May 09, 2015

Python number game

__author__ = 'Baris Gomleksizoglu'

import random


def test_number(guess, real):
    if guess == real:
        return 4, 0

    plus = 0
    minus = 0
    for gi, gx in enumerate(guess):
        for ri, rx in enumerate(real):
            if gi == ri and gx == rx:
                plus += 1
            elif gx == rx:
                minus += 1

    return plus, minus

def validate_hint(strHint):
    if len(strHint) != 4 or strHint[0] != "+" or strHint[2]!="-":
        print("Hint should be exact 4 characters and should start with + and continue with -")
        print("Example: +2-1 or +1-0 or +0-0 or +0-1")
        return False

    return True

# Main program
# only add numbers like 1023, but not 1001
ALL_NUMS = [str(x)
            for x in range(1000, 9999)
            if len(set(str(x))) == len(list(str(x)))
        ]

print("Game start, I am holding a number between 1000 to 9999, try to guess!")
print("For each guess, I will give a hint, + numbers means the location is correct")
print("- numbers means it exists but location is not correct.")

computer_number = random.choice(ALL_NUMS)

while True:
    # Game loop
    user_number = input("Enter your guess> ")
    if user_number == "hint":
        print(computer_number)

    result = test_number(user_number, computer_number)

    if result == (4, 0):
        print("Well done, you found the number")
        break

    print("Hint is: +{} -{}".format(*result))

currentNums = ALL_NUMS[:]
counter = 0

print("Now I will guess your number")
print("Enter my hints in the format +n-m without spaces")
print("if the guess not exists, enter zero like +2-0")

while True:
    my_guess = random.choice(currentNums)
    hint = input("My guess is {}, please enter hint>".format(my_guess))

    if not validate_hint(hint):
        continue

    counter += 1
    if hint == "+4-0":
        print("I found it in {} tries".format(counter))
        break

    hintTuple = int(hint[1]), int(hint[3])

    # analyze hint and remove numbers
    new_list = []
    for n in currentNums:
        if test_number(n, my_guess) == hintTuple:
            new_list.append(n)

    if len(new_list) == 0:
        print("Hints are not correct, the number should be one of this values:")
        print(currentNums)
        counter -= 1
    else:
        currentNums = new_list

Thursday, March 26, 2015

#AWSomeDay notes - @Mechelen

Amazon ebs:
Blocks that acts like harddisk.
1gb to 16tb
Attached to ec2
Can be attached to one ec2, cannot share(or use samba)
99.999 availability
Os, db, critical apps typical usage
Typical use as harddrive, but not open to internet like S3

Glacier: long term storage for legal purpose, files can be retrieved in hours

Aws storage gateway:
Iscsi from premises to cloud storage

Aws import/export:
For already running applications
Phyiscally send data in harddisk, and it will be added to services
Also possible to get data in hd
Example is satellite mapping data like google maps

Amazon cloudfront:
is a cdn service not storage.
Dns name created, that maps to different ip adresses, depending on the lowest latency.
It finds the fastest way when you use the dns provided.
If cannot find in connected datacenter, it copies and caches there. Cached for 24 hours, configurable.
Can also cache dynamic content.
Price only on bandwith, cheaper than s3, ec2.
S3 becomes cheaper because cloudfront caches and uses only one connection to s3 in first request.
Ssl possible.
It is possible old caches data can stay 24 hours on cloudfront.
Purge cache with api is expensive, but cache headers can be used to limit cache timing.
"Incident response in the cloud" youtube video about dos attacts on cloudfront.

Ec2: it is a virtual machine
Os, cpu, memory, region/avalibality zone is enough to define.
You can buy pre installed image from marketplace.
About 900 available at the moment (like sap, adobe, ...)

Amazon route 53: load balancer
amazon redshift: datawarehouse database, big data.
dynamodb: nosql
amazon elasticache: memcache and redis

AWS Elastic beanstalk: deploy service with war file or zip file, automation of deployment.
docker is supported.

AWS Cloudformation:
executes the text based information of the inftrastructure, and executes that to create a clone for development, acceptance.
open/close the instances (it is best practice to shut down development machines, when not used)




Monday, January 19, 2015

Kudo3d Titan1 Assembly

Here are the steps required:

Note: Follow the steps in the build manual, and you can use this pictures to understand better!

Open all boxes except resin containers (in white boxes) as they are sensitive. Remove the front, left and right panels. I didn't show here but add the feets to the bottom.

Linear stage: This is the long metal on the top of the box. You need to make the T-nuts loose (T-nut are the metals in each side). insert the motor to the hole.

It should match the border of case.

Inside look


After attaching the screws to the T-nuts


Align the module in hole to be in middle

T-nuts aligned.

It is like 3 mm from each side, then tighten the screws.

Take metal structure and remove plastic, the plastic part will be faced to front.

A shiny surface under plastic.

Attach screws from left to right,

It will look like this.

Align the screws like this

Attach and tighten each slowly, meaning don't tight one strong, but go through all with small steps.

Add heat sink to board

Remove plastic holders

Align board. TIP: Before attaching board, you can now attach the fan electric.

Attach board, and tighten

Board.

We will use this pins.

Plug

Attach fan.

The fan should be aligned to panel.

The electric connection of fan (as advised you can attach before)

Projector with plastic cover. I removed them completely, but then realized it is advised to use, so attached back some of them.


We will use this ones to attach.

Place them to 3 holes

2 spacers to the bottom screws.

Attach cables.

Place and tighten projector, again slowly, small steps to each.

Align screws in middle.

Disconnect electric of fan, find a screwdriver like this.

Connect wire to D9.

Red flag is positive.

Connected cables.

Attach rs232 to usb

Cables from the hole in back

Another view:

Use plastic from packaging to bring them together.

I used also cable collector (from ikea).

And the length of cable collector.

Cable collector inside.

Build platform

Use your fingers first

Then tighten.

Not necessary but good.

Build platform logo facing front

Attached

Aligned

Cables done.

Completed box.

after the top cover.

I haven't installed the resin container yet, but it is straightforward.