Skip to content

Instantly share code, notes, and snippets.

@BrandonLMorris
BrandonLMorris / ConvertToPositive.java
Created January 28, 2016 15:25
Pointing out an interesting quirk with Java's Math.abs() where it actually returns a negative number
import java.util.*;
/**
* Problem statement: Given a number (that is guaranteed to fit within a 32 bit
* two's compliment integer), print the absolute value of that number.
*
* The catch: A two's compliment signed integer has a larger range for negative
* numbers than it does positive. So simply returning Math.abs() on the input
* won't always work if the input is Integer.MIN_VALUE (-2147483648).
*/
#!/usr/bin python3
"""
A simple script to send a text message over gmail. Text messages are sent as
emails. The mail address depends on the carrier, based on the table below:
AT&T: number@txt.att.net
T-Mobile: number@tmomail.net
Verizon: number@vtext.com
Sprint: number@messaging.sprintpcs.com or number@pm.sprint.com
Virgin Mobile: number@vmobl.com
@BrandonLMorris
BrandonLMorris / quote.py
Created July 5, 2015 00:29
Pull stock quote from markitondemand.com API
import urllib.request
import json
base_url = "http://dev.markitondemand.com/Api/v2/Quote/json?symbol="
def get_quote(symbol):
html = urllib.request.urlopen(base_url + symbol).read().decode("utf-8")
parsed_json = json.loads(html)
return parsed_json["Name"] + ": " + str(parsed_json["LastPrice"])