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 / elixir-basics.md
Last active February 18, 2018 03:17
Elixir basics

Elixir

Setup

Installation

$ brew update
$ brew install erlang
$ brew install elixir
def expanded_key(key) # :nodoc:
return key.cache_key.to_s if key.respond_to?(:cache_key)
case key
when Array
if key.size > 1
key = key.collect{|element| expanded_key(element)}
else
key = key.first
end
@mrdougwright
mrdougwright / rails_fetch.rb
Last active May 30, 2017 19:29
Rails Fetch
def fetch(name, options = nil)
if block_given?
options = merged_options(options)
key = namespaced_key(name, options)
#code omitted
end
@mrdougwright
mrdougwright / flatten_array.rb
Created February 16, 2017 04:50
Flatten an array of an arbitrary amount of arrays.
def make_flat(arr, flat_arr=[])
arr.each do |el|
el.is_a?(Array) ? make_flat(el, flat_arr) : flat_arr.push(el)
end
flat_arr
end
// create anagram db
// str = "care race bear face heart earth etc"
function sortJoin(word) {
return word.split('').sort().join('')
}
function anagram(str){
let words = str.split(' ')
let obj = {}
words.forEach(function(w) {
@mrdougwright
mrdougwright / rectangle_intersect_exercise.rb
Created December 5, 2016 19:26
rectangular intersection
# write an algorithm to find the intersection of two users' love rectangles.
def intersection(rectangle1, rectangle2)
rect_hash1 = calc_space(rectangle1)
rect_hash2 = calc_space(rectangle2)
intersect_hash = overlap(rect_hash1, rect_hash2)
convert_to_rectangle(intersect_hash)
end
def calc_space(rectangle)
<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>
@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,
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: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)