Skip to content

Instantly share code, notes, and snippets.

Java Questions
1. Why do we hide data behind getters and setters?
2. What is the difference between an `ArrayList` and a `LinkedList`? When should you use them?
3. Explain insides of a `HashMap`
4. Explain insides of a `TreeMap`
5. Abstract class vs interface
6. Why calling public methods in a constructor is a bad practice?
7. Overriding vs overloading
8. Explain exceptions (checked/unchecked)
class example(object):
stuff = "nothing"
def test():
return "Blah blah"
library = {1: "toy",
2: "box",
import csv
import datetime
import matplotlib.pyplot as plt
with open('brentdata.csv') as f:
csv_data = csv.DictReader(f)
data = list(csv_data)
# Data now contains a list of dictionaries, each dictionary containing a line of the csv
# Here's what the dictionary equalling one line looks like
import random
relationships = {'Spock': {'Scissors': 'smashes', 'Rock': 'vaporizes'},
'Scissors': {'Paper': 'cuts', 'Lizard': 'decapitates'},
'Lizard': {'Paper': 'eats', 'Spock': 'poisons'},
'Rock': {'Lizard': 'crushes', 'Scissors': 'crushes'},
'Paper': {'Spock': 'disapproves', 'Rock': 'covers'}
}
from urllib.request import urlretrieve
from time import sleep
import requests
from bs4 import BeautifulSoup as bs
def get_files():
""" Gets files of specified extension through user input
from a specified full URL path; downloads each file to
from unittest import TestCase
from triangle import get_num_divisors
class TestGet_num_devisors(TestCase):
def test_get_num_devisors(self):
assert get_num_divisors(1) == 1
assert get_num_divisors(3) == 2
assert get_num_divisors(6) == 4
+-----------------------+--------+---------+
| Title | #Jobs | Avg.Sal |
+-----------------------+--------+---------+
| Python Developer | 36670 | 97992 |
| Java Developer | 116285 | 98014 |
| C# Developer | 58974 | 95915 |
| C++ Developer | 36950 | 97905 |
| Ruby Developer | 22772 | 88315 |
| PHP Developer | 26466 | 75204 |
| HTML5 Developer | 31565 | 87505 |
>>> from requests.auth import HTTPBasicAuth
>>> auth = HTTPBasicAuth('fake@example.com', 'not_a_real_password')
>>> r = requests.post(url=url, data=body, auth=auth)
>>> r.status_code
201
>>> content = r.json()
>>> print(content[u'body'])
Sounds great! I'll get right on it.
from flask import json
import websocket
def get_bar(time, max_elements):
return '[{}{}]'.format('|' * time, ' ' * (max_elements - time))
def on_message(ws, message):
import random
JAPANESE_CHARACTERS = [
['いちまい', 'にまい', 'さんまい', 'よんまい', 'ごまい', 'ろくまい', 'ななまい', 'はちまい', 'きゅうまい', 'じゅうまい'],
['いっさつ', 'にさつ', 'さんさつ', 'よんさつ', 'ごさつ', 'ろくさつ', 'ななさつ', 'はっさつ', 'きゅうさつ', 'じゅさつ'],
['いっぽん', 'にほん', 'さんぼん', 'よんまい', 'ごまい', 'ろくまい', 'ななまい', 'はちまい', 'きゅうまい', 'じゅうまい'],
['ひとつ', 'ふたつ', 'みっつ', 'よっつ', 'いつつ', 'むっつ', 'ななつ', 'やっつ', 'ここのつ', 'とお']
]
answer_selections = ["a", "b", "c", "d"]