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
@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
/* 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";
$.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() {
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"}
]
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
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
@mrdougwright
mrdougwright / gist:3b95c798646403f061f2
Last active August 29, 2015 14:10
Life Counter for Words
ALPHA = %W(0 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z)
def read_word(word)
word.gsub(/\s+/, '').upcase.split('').map{|l| ALPHA.index(l)}.reduce(:+)
end
def get_word
puts "Enter a word or more for life count.\n(type quit to quit):"
word = gets.chomp
p read_word(word)
arr = [-10,-5,6,6,-10,-100]
arr2 = [10,-5,6,6,-10,-100]
def max_slice(arr)
max = 0
biggest_slice = arr[0..1]
arr.each_with_index do |x,i|
arr.each_with_index do |y,index|
if sum(arr[index..i]) > max
biggest_slice = arr[index..i]
@mrdougwright
mrdougwright / gist:7ef85a0ce930554078a2db0f37c5b7a2
Last active March 29, 2016 16:40
CreateFind Method in Lib, with Spec
require 'rails_helper'
require 'create/create_find_resident'
describe CreateFindResident do
let!(:resident) { FactoryGirl.create :resident }
let(:resident_data) {
{
"DisplayName"=>"Smith, Bob M",
"ResidentSys"=>123,
<ul>
{% for content in contents %}
<li>
<div class="post-item">
{% if not simple_list_page %}
<div class="post-header">
<h2><a href="{{content.absolute_url}}">{{ content.name }}</a></h2>