Skip to content

Instantly share code, notes, and snippets.

View jjlumagbas's full-sized avatar

JJ Lumagbas jjlumagbas

View GitHub Profile
@jjlumagbas
jjlumagbas / secret.py
Created November 17, 2016 01:27
Hide user input in Python
import getpass
age = getpass.getpass('Enter your age:')
print("Entered age is: " + age)
public class AVLTree {
private MyTreeNode root;
public AVLTree() {
this.root = null;
}
public void add(Integer data) throws Exception {
this.root = add(root, data);
@jjlumagbas
jjlumagbas / MyBinarySearchTree.java
Created November 11, 2016 01:11
Starter code for remove
public class MyBinarySearchTree {
private MyTreeNode root;
public MyBinarySearchTree() {
this.root = null;
}
public void add(Integer data) throws Exception {
this.root = add(root, data);
public class MyBinarySearchTree {
private MyTreeNode root;
private int size;
public MyBinarySearchTree() {
this.root = null;
size = 0;
}
@jjlumagbas
jjlumagbas / ExpressionTree.java
Created November 4, 2016 01:27
Evaluate expression tree
public class ExpressionTree {
public static int eval(MyTreeNode root) {
return 0;
}
}
@jjlumagbas
jjlumagbas / prev.py
Created November 3, 2016 02:10
Remembering previous and Range
# given a list, remove successive duplicate elements
def remove_succ_lst(lst):
result = [lst[0]]
prev = lst[0]
for curr in lst:
if ( prev != curr ):
result = result + [curr]
@jjlumagbas
jjlumagbas / fold.py
Created October 27, 2016 05:37
Examples of folds in Python
#
# fold
def sum_nums(lst):
sum = 0
for el in lst:
sum = sum + el
return sum

Machine Problem 3 - Parsing Poetry Packets

Data on the internet are broken up and passed around in what are called "packets":

Packet - Email Example

On the Internet, the network breaks an e-mail message into parts of a certain size in bytes. These are the packets. Each packet carries the information that will help it get to its destination -- the sender's IP address, the intended receiver's IP address, something that tells the network how many packets this e-mail message has been broken into and the number of this particular packet. - Read the whole article at HowStuffWorks

In this MP, you're going to parse a "network packet capture" (a listing of packets), reassemble corresponding sets of packets into the original "messages" sent, and display the messages in a human-readable format.

@jjlumagbas
jjlumagbas / 11-lab-11-lists-map-filter.md
Last active October 24, 2016 04:57
CMSC11 Lab 11 - Practice on map and filter

CMSC11 Lab Exercise 11 – Lists

Create the following functions. Don’t forget the design recipe! I’ll be looking for the following:

  • Signature, purpose, stub
  • Examples
  • Template

@jjlumagbas
jjlumagbas / lists2.py
Created October 24, 2016 04:35
Examples for map and filter
#
#
# fold
# map
# create a duplicate of the given list
def dup(lst):
result = []
for el in lst: