Skip to content

Instantly share code, notes, and snippets.

Hey everybody --

I just wanted to send out a few notes about homework. I saw some common issues while grading, and wanted to give some reminders, tips, and tricks which I think are going to be pretty useful for your upcoming homework assignment.

Commenting

When commenting method headers, make sure you always do the following:

  1. Describe what the method does (without describing what the code does)
  2. Describe what every parameter does
--------- beginning of /dev/log/main
D/skia ( 1225): purging 197K from font cache [27 entries]
W/PowerManagerService( 2474): Timer 0x7->0x3|0x0
V/WindowManager( 2474): Dsptch > Window{4817ffb8 mobi.mgeek.TunnyBrowser/mobi.mgeek.TunnyBrowser.BrowserActivity paused=false}
D/dalvikvm( 1860): GC_FOR_MALLOC freed 4008 objects / 531920 bytes in 27ms
This file has been truncated, but you can view the full file.
========================================================
== dumpstate: 2013-01-13 19:41:29
========================================================
Build: FROYO.UCKB1
@Michael0x2a
Michael0x2a / gist:92a6943f26c7ab6e2f4a
Last active January 11, 2021 18:39
Guide to printf (CSE 142)

Quick guide to printf

Using printf is almost identical to using print. They both print out whatever string you give it, they both don't include a newline, etc. There's just one key difference: printf has some extra features that lets you substitute and format values inside whatever you're printing.

Pragmatically, in CSE 142/143, the only time you'd use printf is if you want to round numbers. Here's an example:

double someNumber = 3.33333333333
System.out.printf("Here's a number: %.2f", someNumber);
@Michael0x2a
Michael0x2a / gist:182ec57bfe5e72a487eb
Last active August 29, 2015 14:02
CSE 142: BankAccount

Well, first off, the problem states that our method should accept a second BankAccount, not a String. So, our method header will look like:

public void transfer(BankAccount other, double amount)

I think this was the main thing you were stuck with -- getting the correct type signature. Apart from that, it looks like you were on the right track.

Then, we can get to the business of writing the code. If the balance in the current bank account is too small, we'll just terminate early:

Feedback: July 27, 2014

For reference, here is your original code:

#!/usr/bin/env python

def encrypt (raw_string, shift):
    encrypted_string = ""
    for letter in raw_string:
@Michael0x2a
Michael0x2a / gist:da6a731a8da375b75077
Created July 10, 2014 05:30
Feedback: July 9, 2014

July 9, 2014

Introduction

The primary lesson I want to go over today is [separation of concerns][soc].

When coding, there are often many different tasks or components that make up the entire program. For example, gathering user input, displaying data, running algorithms, and storing data are all examples of different "tasks" or "concerns".

One problem many beginning coders have is a tendency to "blur" these concerns together, and end up writing functions that try and do too many things at once.

@Michael0x2a
Michael0x2a / math-308-midterm-1-review.ipynb
Created October 16, 2014 06:29
Math 308 Midterm 1 Review
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Michael0x2a
Michael0x2a / reconstructing-tree.md
Last active June 30, 2020 22:42
Reconstructing tree

Reconstructing a Binary Tree

Problems 0 and 1 on the section handout today were all about writing out and reading in a tree (serializing and deserializing). Problem 0 asked you to take an existing tree and print it out into text form, and problem 1 asked you to read that output back in again using a Scanner, and reconstruct the tree.

Just as a reminder, here's the code on the solution sheet for problems 0 and 1:

// Problem 0
public void writeTree() {
    this.writeTreeHelper(this.root);
@Michael0x2a
Michael0x2a / braces.clj
Created December 7, 2014 00:40
Clojure: is string balanced?
; Given a N different open and close braces in a string ""( { [ } ] )"".
; Write a program to check to see if the braces in the string are balanced.
(ns braces
(:require [clojure.string :as str]))
(def braces #{\( \) \[ \] \{ \}})
(def pairs { \) \(,
\] \[,