2016-06-16 - CS Dojo poll

posted Jun 16, 2016, 8:15 AM by Samuel Konstantinovich   [ updated Jun 16, 2016, 8:15 AM ]

The CS Dojo wants feedback. If you ever went to the dojo please thank them by filling this out:

Final Project Cleanup + Exit Survey

posted Jun 13, 2016, 5:05 AM by Samuel Konstantinovich   [ updated Jun 13, 2016, 5:13 AM ]

You have 15 minutes to make sure that the correct version is posted, and linked in your HTML file.
You should
Make sure your site links to the right version internally (not accidentally going to an old site on some of your links)
Update your changelog.txt
Update your finalproject.html
Put some posts / comments up for me to see using different accounts.
If you have an admin account that has special features, email the account info to me, and state that you did so in your finalproject.html.

Final Project Exit Survey:


posted Jun 10, 2016, 5:36 AM by Samuel Konstantinovich   [ updated Jun 10, 2016, 7:52 AM ]

1. Everyone Rate the Demos:

  a) Final Projects should be done by Monday morning. You will ONLY have a few minutes in class to tweak things and make final choices on the best version to use as the "graded version"
  b) Everyone make a html file to link to their project:
            REQUIRED: Include a link to the starting page of the correct version of your final project.
            REQUIRED: What are the new features that work since your demo (not appearance related) - Update this after you finish your project.
            Optionally include any descriptions/directions that I need for your project.
            Optionally include any other info you want me to know.
  a)Monday You will have a final Project Exit Survey. This is part of your grade and must be completed.
  b)Please back up any data you have in your home directory before the summer. The home directories will be deleted at the end of the semester. You can just FTP your home directory to your home computer, OR put it on a flash drive.


posted Jun 7, 2016, 12:19 PM by Samuel Konstantinovich   [ updated Jun 7, 2016, 12:19 PM ]

CSTUY is planning on running a FREE computer science summer program throughout July 2016.

SHIP : Summer Hacker* Immersion Program

It is a 3 hour weekday program run by StuyCS Alumni/Teachers. Sessions will be held on weekdays from 9am - Noon 7/6 - 7/29 at the Microsoft Building in Times Square. There will be no cost to attend this program, but you must commit to attend all sessions. Breakfast and lunch will not be provided.

If you are available and interested in SHIP 2016, please fill out the following form. Space is very limited so we need responses back as soon as possible. 

More details are provided on the form, please read them and fill it out if you are interested!

Feel free to ask me questions
Ask people at the dojo how they liked the program last year!

*Note that this is not a computer security class, we use hacker as: an expert at programming, solving problems, and making things with computers.


posted May 26, 2016, 5:09 AM by Samuel Konstantinovich   [ updated May 26, 2016, 6:21 AM ]

Design Problem:
Given: 2D list of non-negative integers:
     e.g. [ [1,2,3], [5,6,7,8 ], [6,6,0] ] 
Write a function that takes the list as a parameter, and returns a new list with the same dimensions (number of lists, and size of each inner list) 
but! The function calculates the average of each sublist, and changes any element in the sublists that are above the average  to -1.
L1 = [ [1,2,3], [5,6,7,8], [6,6,0] ] 
L2 = fix ( L )

L1 is still [ [1,2,3], [5,6,7,8], [6,6,0] ] 
L2 is now  [ [1,2,-1], [5,6,-1,-1], [-1,-1,0] ] 

The averages for the 3 lists were 2, 6.5, and 4, so the 1st list changed the 3, the 2nd list changed the 7,8, and the 3rd list changed the 6's.

1. How would you break up this into small achievable chunks?
2. How would you write the program differently if you wanted to modify the array rather than return a copy?

def mean(L):
    return float(sum(L))/len(L)

def fix(L):
    ans = []
    for each in L:
        ave = mean(each)
        inner = []
        for value in each:
            if value <= ave:
    return ans

def fix2(L):
    for each in L:
        ave = mean(each)
        for i in range(len(each)):
            if each[i] > ave:
                each[i] = -1
L1 = [ [1,2,3], [5,6,7,8], [6,6,0] ]
print L1 

#version 1 that returns a copy
L2 = fix(L1)
print L2
#version 2 that modifies the list
L1 = [ [1,2,3], [5,6,7,8], [6,6,0] ] 
fix2 ( L1 )

print L1


posted May 24, 2016, 5:04 AM by Samuel Konstantinovich   [ updated May 24, 2016, 5:04 AM ]

Fill this out with your partner, you need to log in with your email first.


posted May 20, 2016, 5:17 AM by Samuel Konstantinovich   [ updated May 20, 2016, 5:20 AM ]

Project Outline (Write it out)
-Overview: What will it do? Give a brief description.
-List of specific features.
-How will the users interact ?(what kind of forms etc)
-Diagram of pages (what would link to what, what would be sent to the other pages)

You are making a python generated website.
-It MUST retain information about the users to enhance the user experience. e.g. Store their settings, profile, messages, history of usage, statistics etc. 

In addition you must make it do something, but the features are totally up to you!

-It COULD allow users to view/interact with other users. See their scores/profiles/posts, send messages, make comments etc. These are easy features but not required.
-It COULD analyze static data, but in a way the user chooses
-It COULD pull real time data from web sources, but this is tricky.

You will have a DEMO version ready by June 7th. This should be working, with a solid set of features. Spend your time before this making sure things work!

The final version is due June 13th. This is the polished version of the demo version. Spend your time making your page LOOK nice in the last week. You can also add a few more features, but a WORKING site with fewer features is better than a BROKEN site with tons of features. 


posted May 19, 2016, 5:08 AM by Samuel Konstantinovich   [ updated May 19, 2016, 7:50 AM ]

Goal: Get the base code you are allowed to use to start a project with.

After you download it:
1. extract the files into your public html into a directory to test that you can get it working, ie. ~/public_html/basecodetest/
2. Make a data directory
3. chmod the data directory so www-data can create a file
4. create the data files using the provided py file.
5. now the login system should work!


posted May 18, 2016, 4:12 PM by Samuel Konstantinovich   [ updated May 18, 2016, 4:12 PM ]

To Set values in a cookie: (

#do not print things yet!
import cgitb,Cookie

# set some constants so we can use them later
EXPIRE_HOUR =     60 * 60
EXPIRE_MINUTE =   60 * 1

# create the cookie with a dummy value

#set up your page in pieces, do not print in your code, just
#append to the body if you want to see text.
head = '''<html>
<head><title>Set Cookie Values</title>
body = ""
foot = '''</body>

body += "Setting cookies key1, key2, and randomName<br>\n"
body += 'Go set a cookie here: <a href="">here</a><br>'

#somewhere in your code you need to set the cookies
c['key1']['expires']= EXPIRE_MINUTE * 1
c['key2']="Value two"
c['key2']['expires']= EXPIRE_MINUTE * 2
c['randomName']="Booga booga"
c['randomName']['expires']=EXPIRE_HOUR * 1

#print the cookie first, then content type, then the page
print c
print 'content-type: text/html\n'
print head
print body
print foot

To get values from a cookie: (

import Cookie,os,cgitb

head = '''<html>
<head><title>Read Cookie values</title></head>
body = ""
foot = '''</body>\n</html>'''

if 'HTTP_COOKIE' in os.environ:
    cookie_string = os.environ.get('HTTP_COOKIE')
    c = Cookie.SimpleCookie()
    ##print all the data in the cookie
    body+= "<h1>cookie data</h1>"
    for each in c:
        body += each+":"+str(c[each].value)+"<br>"
    body+= 'No cookie?!?!?<br>\n'
    body+='Go set a cookie here:<a href="">here</a><br>'

print 'content-type: text/html\n'
print head
print body
print foot


posted May 17, 2016, 5:16 AM by Samuel Konstantinovich   [ updated May 17, 2016, 5:30 AM ]

Goal Staying Logged in Lab


1. Copy lab15 into lab16.

2. Create a new data file  'loggedin.txt' such that www-data can write to it.

3. When you successfully log in you will write to loggedin.txt:

4. Make a link to a new py file

5. Make check to see if the following is true:
a. The username is in the logged in file.
b. the ID matches the random number of the same line in the loggedin file.
c. The IP of the computer matches the IP in the same line of the loggedin file. 
When all 3 are true:
    You are successfully logged in! 
    Go log in <link to login page>

6. Make sure when you log in, you do not create duplicate entries! Delete any old logged in lines with the username that matches every time you log in.

1-10 of 62