This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def maxSubarray(numbers): | |
currentMax = 0 | |
totalMax = 0 | |
for n in numbers: | |
currentMax = max(0, currentMax + n) | |
totalMax = max(totalMax, currentMax) | |
return totalMax | |
numbers = [-10, 2,2,-4,2,3,4,-5] | |
print(str(maxSubarray(numbers))) # 9 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Git branch in prompt. | |
parse_git_branch() { | |
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/' | |
} | |
# PS1 prompt | |
export PS1="\w\[\033[32m\]\$(parse_git_branch)\[\033[00m\]$ " |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# prereqs: | |
# Create a Twitter app and generate oauth credentials at https://apps.twitter.com | |
# python 2.7 | |
# pip install oauth2 | |
import oauth2 as oauth | |
import json | |
import urllib | |
CONSUMER_KEY = 'your consumer key' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require('http'); | |
var url = require('url'); | |
var port = process.argv[2]; | |
http.createServer(function (request, response) { | |
urlInfo = url.parse(request.url, true); | |
iso = urlInfo.query['iso']; | |
response.writeHead(200, {'Content-Type': 'application/json'}); | |
if (urlInfo.pathname === '/api/parsetime') { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require('http'); | |
var map = require('through2-map'); | |
var port = process.argv[2]; | |
var server = http.createServer(function (request, response) { | |
if (request.method = 'POST') { | |
request.pipe(map(function (chunk) { | |
return chunk.toString().toUpperCase(); | |
})).pipe(response); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var net = require('net'); | |
var port = process.argv[2]; | |
var strftime = require('strftime'); | |
var server = net.createServer(function (socket) { | |
var timestamp = strftime('%F %H:%M', new Date()); | |
console.log(timestamp); | |
socket.write(timestamp); | |
socket.end(); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require('http'); | |
var url = process.argv[2]; | |
http.get(url, function (response) { | |
response.setEncoding('utf8'); | |
response.on('error', console.error); | |
var allCharacters = ''; | |
response.on('data', function (data) { | |
allCharacters += data; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int getEditDistance(String a, String b) { | |
int[][] distances = new int[a.length()][b.length()]; | |
for(int i = 0; i < distances.length; i++) { | |
distances[i][0] = i; | |
} | |
for(int j = 0; j < distances[0].length; j++) { | |
distances[0][j] = j; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var isRotation = function(s1, s2) { | |
return (s1.length === s2.length) && ((s1 + s1).indexOf(s2) !== -1); | |
}; | |
s1 = "stackoverflow" | |
s2 = "tackoverflows" | |
s3 = "ackoverflowst" | |
s4 = "overflowstack" | |
s5 = "ovegflgwsgacg" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Definition for a binary tree node. | |
* public class TreeNode { | |
* int val; | |
* TreeNode left; | |
* TreeNode right; | |
* TreeNode(int x) { val = x; } | |
* } | |
*/ | |
public int maxDepth(TreeNode root) { |