Skip to content

Instantly share code, notes, and snippets.

View itsjohncs's full-sized avatar

John Sullivan itsjohncs

View GitHub Profile
@itsjohncs
itsjohncs / when-no-chess.py
Created March 4, 2021 04:41
When ran against your chess data export from Lichess, prints out the dates during which you played no games.
#!/usr/bin/env python3
import re
import datetime
played_chess_on = set()
with open("/Users/johnsullivan/Downloads/lichess_johncs_2021-03-04.pgn") as f:
for line in f:
match_obj = re.match(r'^\[Date "([^"]+)"]\s*$', line)
if match_obj:
@itsjohncs
itsjohncs / division.c
Created March 10, 2020 19:16
Solution to the "Divide Two Integers" problem on leetcode
#include <stdio.h>
#include <stdbool.h>
#include <limits.h>
// Leftshift by 3 is equivalent to multiplying by 8
#define BITS_IN(a) (sizeof(a) << 3)
bool maybeLeftShift(unsigned int const a, int const b, unsigned int * const out) {
if (b == 0 || (a >> (BITS_IN(a) - b)) == 0) {
*out = a << b;
#!/usr/bin/env python3
import sys
def doesAny2SumTo(target, lst):
multiset = {}
for i in lst:
if i in multiset:
multiset[i] += 1
@itsjohncs
itsjohncs / gist:f448649181f051f566d74ec13f14e9e4
Created November 29, 2018 21:46
Today's line counts in Shmeppy
jyggalag:shmeppy johnsullivan$ make line-count
find ./client/src ./server/src -name '*.js' | xargs wc -l
110 ./client/src/AccountLocalStorageSyncer.js
61 ./client/src/drawing/impromptu/tokens.js
9 ./client/src/drawing/impromptu/cellFills.js
72 ./client/src/drawing/impromptu/fogOfWar.js
67 ./client/src/drawing/impromptu/tokenLabels.js
69 ./client/src/drawing/impromptu/gridGuides.js
88 ./client/src/drawing/impromptu/ImpromptuViewport.js
55 ./client/src/drawing/impromptu/cellEdges.js
CHUNK_WIDTH = 32
class Point(object):
def __init__(self, x, y, z):
self.x = x
self.y = y
self.z = z
def to_index(self):
return point.x + point.y * CHUNK_WIDTH + point.z * CHUNK_WIDTH * CHUNK_WIDTH
@itsjohncs
itsjohncs / main.py
Created July 13, 2015 03:12
html_aware_wrap
def html_aware_wrap(string, width=72):
"""Wraps some HTML to the given width.
This ignores the HTML for the purpose of determining the width of each
line.
Warning: This takes a pretty trivial approach to matching HTML tags, so
buyer beware.
"""
lines = [""]
#include "stdafx.h"
#include <iostream>
#undef UNICODE
#include <Windows.h>
#include <WinDNS.h>
#pragma comment(lib, "dnsapi.lib")
#pragma comment(lib, "ws2_32.lib")
using namespace std;

CS 10 Mock Final

It is unlikely you will finish this test in the allotted time. Try to do as many problems as you can.

Things to keep in mind:

  • If the problem states you can select multiple answers, you don't necessarily have to select more than one (or even any at all).
  • If you see a mistake please tell me.
  • This may or may not be an accurrate represenation of what your final will look like. I do not know what your final looks like and am not responsible for creating it. This is a tool to help you study created by the SI leader assigned to this class (who is an undergraduate student with the same status as you).
  • Each question is worth 1 point. No partial credit.

Functions and Reference Parameters

Code Tracing

Determine the output of the following programs (assuming a using namespace std and #include <iostream> are provided at the top). If there are errors, make reasonable changes to fix the error and then determine the output.

Program 1

int foo(int & a, int & b) {
#include <vector>
#include <iostream>
struct ListNode {
int data;
ListNode * next;
};
ListNode * construct_linked_list(std::vector<int> const & v) {
ListNode * head = NULL;