Skip to content

Instantly share code, notes, and snippets.

View mrdougwright's full-sized avatar
🏠
Working from home

Doug Wright mrdougwright

🏠
Working from home
View GitHub Profile
def max_slice(arr)
arr.size.times do |x|
if sum(arr[x..-1]) >= sum(arr)
arr.shift
end
if sum(arr[x..-2]) > sum(arr)
arr.pop
end
end
p arr
arr = [20,30,50,40,100,10,45,95,30,10]
def low_high(stock_prices)
max = 0
stock_prices.each_with_index do |x, index|
current_max = 0
stock_prices[index..-1].each do |y|
current_max = y - x
if current_max > max
max = current_max
require 'time'
SHIFTS = [
{id: 1, shiftStart: "2014-07-08 09:00:42 -0700", shiftEnd: "2014-07-08 18:00:42 -0700"},
{id: 1, shiftStart: "2014-07-08 06:57:42 -0700", shiftEnd: "2014-07-08 08:57:42 -0700"},
{id: 1, shiftStart: "2014-07-08 01:57:42 -0700", shiftEnd: "2014-07-08 05:57:42 -0700"},
{id: 1, shiftStart: "2014-07-07 06:57:42 -0700", shiftEnd: "2014-07-07 12:57:42 -0700"},
{id: 1, shiftStart: "2014-07-06 05:57:42 -0700", shiftEnd: "2014-07-06 11:57:42 -0700"}
]
$.post(form.prop("action"), parms, function(res) {
if (res.success) {
$(".overlay.hidden").fadeIn().delay(5000).fadeOut();
form.get(0).reset();
}
}, "json");
// Change to this --->>
$.post(form.prop("action"), parms, function() {
/* this rotates a string: "lohel".rotate(3) is "hello" */
String.prototype.rotate = function(n) { // n is an integer
n %= this.length; // if n too large: modulo
var cut = n < 0 ? -n : this.length - n; // cutting point
return this.substr(cut) + this.substr(0,cut);
};
function rot13_creator() {
// compose the dictionary
var alph = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
@mrdougwright
mrdougwright / email-extractor
Last active December 20, 2015 09:18
My first ever Python program I used to pull emails out of a messy document.
myList = []
with open('file.txt') as file:
for line in file:
myList += line.split(' ')
for word in myList:
if '@' in word:
print word