Skip to content

Instantly share code, notes, and snippets.

View itsjohncs's full-sized avatar

John Sullivan itsjohncs

View GitHub Profile
@itsjohncs
itsjohncs / main.cpp
Created March 16, 2012 19:53
Connect 4 Game for CS 10 SI Lab
#include <iostream>
#include <vector>
using namespace std;
const char EMPTY_SPACE = '_';
const char PLAYER1_PIECE = 'X';
const char PLAYER2_PIECE = 'O';
const unsigned int NCOLUMNS = 7;
const unsigned int NROWS = 6;
@itsjohncs
itsjohncs / gist:2845876
Created May 31, 2012 20:05
Graph Lab 9
#include <map>
#include <set>
#include <iostream>
#include <string> // Don't know if neccessary...
#include <stdexcept> // Provides the RuntimeError class
using namespace std;
class Graph {
typedef string NodeName;
@itsjohncs
itsjohncs / gist:2913976
Created June 12, 2012 02:17
Terrible Code Snippet #1
private boolean compareInts(int one, int two)
{
boolean areEqual = false;
if(one == two)
{
areEqual = true;
}
return areEqual;
}
@itsjohncs
itsjohncs / gist:2914854
Created June 12, 2012 04:06
Terrible Code Snippet #2
def is_even(num):
"Returns true iff num is even."
i = 0
while i < num:
i += 2
return i == num
def get_even_numbers(a, b):
@itsjohncs
itsjohncs / RedirectForm.py
Created June 21, 2012 06:33
Flask Snippet - WTForms Secure Redirect
# The secure redirect I found in the snippets library did not satisfy me.
# Here is my version which satisfied my needs more. The next argument/
# referrer will only be used if your application knows how to route it.
# This won't work very well if you have multiple applications.
# Licensed under the Unlicense, go nuts.
## Create the base form ##
from flask import request, url_for, render_template
from flaskext.wtf import Form, HiddenField
from werkzeug.exceptions import NotFound, HTTPException
@itsjohncs
itsjohncs / gist:2985976
Created June 25, 2012 01:54
add_get_params
import urlparse
def add_get_params(url, params):
"Add the given parameters to a URL's query."
components = urlparse.urlsplit(url)
# Form a list containing each of the get parameters including the new ones.
new_query = components.query.split("&") + \
[str(k) + "=" + str(v) for k, v in params.items()]
@itsjohncs
itsjohncs / input1.txt
Created October 8, 2012 05:28
CS 10 SI Classroom Session 2 - Example 1
Twix
Fido
John
Smith
47
@itsjohncs
itsjohncs / input1.txt
Created October 8, 2012 05:29
CS 10 SI Classroom Session 2 - Example 2
237.87
9.52
@itsjohncs
itsjohncs / problem2.cpp
Created October 8, 2012 06:42
CS 10 SI - Lab Worksheet Week 2
int a = 5;
int b = 10;
cout << "a: " << a << " b: " << b << endl;
a = b;
b = a;
cout << "a: " << a << " b: " << b << endl;
@itsjohncs
itsjohncs / main.cpp
Created October 15, 2012 04:50
CS 10 SI Classroom Session 3 - cin Quiz Question
#include <iostream>
using namespace std;
int main() {
double radius;
string bulk;
cin >> radius;
cin >> bulk;