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
| module TreeGenerator | |
| def self.generate_tree | |
| pages = all.select('id, name, depth, parent_id, sort_order').order('sort_order ASC') | |
| ordered_pages = ActiveSupport::OrderedHash.new | |
| pages.each do |page| | |
| ordered_pages[page.id] = {page: page, children: generate_children(page.id, pages)} if page.depth == 0 | |
| end | |
| ordered_pages |
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
| # From the ACR 2016 coding challenge. | |
| defmodule SnakeCase do | |
| @doc """ | |
| Brute force, single process. | |
| """ | |
| def single do | |
| range = 0..round(:math.pow(2, 20)) | |
| count = Enum.count(range, fn x -> check_one_bits(x) == 10 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
| # Snake Case multi-process! | |
| defmodule SnakeCase do | |
| def multi do | |
| Agent.start_link(fn -> 0 end, name: __MODULE__) | |
| ranges = Enum.chunk(0..round(:math.pow(2, 20)), 262144) | |
| tasks = Enum.map ranges, fn range -> | |
| Task.async(fn -> subrange(range) end) | |
| end | |
| for task <- tasks, do: Task.await(task) |
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
| class GameOfLife | |
| def initialize(size, iterations) | |
| @square_size = size | |
| @max_iterations = iterations | |
| end | |
| def run | |
| # Set up the initial array. | |
| @board = Array.new(@square_size) |
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
| class AdminController < ApplicationController | |
| set_current_tenant_through_filter | |
| before_action :authenticate_user! | |
| before_filter :load_tenant | |
| def load_tenant | |
| begin | |
| tenant = if session[:current_tenant] |
OlderNewer