Skip to content

Instantly share code, notes, and snippets.

scott hamilton shamil614

View GitHub Profile
@shamil614
shamil614 / thread_queue.rb
Created Feb 8, 2017
thread queue example
View thread_queue.rb
require "thread"
require "awesome_print"
start_time = Time.now
results = { body: [] }
queue = Queue.new
0..50.times { |x| queue.push x }
@shamil614
shamil614 / math.exs
Created Nov 29, 2016
Learn Elixir Episode 06
View math.exs
defmodule Math do
def sum(list) do
sum(list, 0)
end
def sum([], 0), do: 0
def sum([], total) when total > 0, do: total
def sum(list, total) do
@shamil614
shamil614 / logstash.rb
Created Jun 10, 2016
Snipped of how Logstash is setup
View logstash.rb
require "logstash-logger"
# Sensible configuration options that we want to share accross ENVs
Rails.application.configure do
# Logstash has a bunch more config options that have sensible defaults.
config.logstash.uri = ENV["LOG_SERVER"]
# Use the lowest log level to ensure availability of diagnostic information
# when problems arise.
config.log_level = ENV["LOG_LEVEL"] || :info
@shamil614
shamil614 / config.exs
Last active Nov 11, 2015
Override Dogma LineLength
View config.exs
# Keep your sanity by making a simple change to Dogma config.
# Known to be compatible with v0.0.11
# Override the default 80 for max_length and set it to 120
config :dogma,
rule_set: Dogma.RuleSet.All,
override: %{ LineLength => [ max_length: 120 ] }
@shamil614
shamil614 / docker_scripts.sh
Last active Dec 4, 2015
Quick and dirty bash scripts to streamline repetitive tasks.
View docker_scripts.sh
#!/bin/bash
# Instructions
# 1. Download to ~/scripts
# 2. chmod u+x ~/scripts/docker_scripts.sh
# 3. Add the /scripts into your PATH by including this in your ~/.bashrc `export PATH="$PATH:/$HOME/scripts"`
# 4. Open a new terminal and execute `docker_scripts.sh`
# 5. Choose from any of the options at the prompt
function stop_containers() {
id=$(docker ps | awk 'NR > 1 {print $1}' | tr '\n' ' ')
@shamil614
shamil614 / en.yml
Created Nov 18, 2014
Demo how to use localize ActiveRecord errors
View en.yml
en:
helpers:
submit:
offer:
create: "Make Offer"
bid:
create: "Place Bid"
activerecord:
errors:
models:
@shamil614
shamil614 / redis.conf
Created Oct 16, 2014
Basic Redis Config (development)
View redis.conf
loglevel notice
logfile ""
dir vendor/redis/db/
View job_quote.json
// job quote make the following assumptions:
// 1 hr job during the week (normal/standard rate)
// travel costs are included
// includes interp minimum job hours (some interps have a requirement for two hours)
// does not include tax
{ "job_quote": { "min_cost": "$20", "max_cost": "$65" }
"interpreters":
[
{ "cityState": "Austin, TX 78758", "latitude": 123.456, "longitude": 123.456, "hourlyRate": "$45" },
{ "cityState": "San Antonio, TX 77577", "latitude": 456.789, "longitude": 456.789, "hourlyRate": "$65" },
@shamil614
shamil614 / scopes_on_joins.rb
Created Apr 28, 2014
Using Scopes on Arel Join Queries
View scopes_on_joins.rb
# Let's say you have a join between Address and Job
# You want to use a scope on Job to limit the jobs that have to be joined otherwise you would join all jobs.
# So you try this
Address.joins('INNER JOIN jobs ON jobs.id = addresses.addressable_id AND addresses.addressable_type = "Job" AND ' \
'addresses.address_type = "physical"').where(Job.in_the_future)
# What you get is an error like so
# Job Load (1.1ms) SELECT `jobs`.* FROM `jobs` WHERE (start_datetime > '2014-04-28 16:06:12')
# (pry) output error: #<TypeError: Cannot visit ActiveRecord::Relation::ActiveRecord_Relation_Job>
View overlapping.rb
# find any jobs that chronologically overlap an array of job_assignments
# ex: find any jobs that overlap an interpreter's existing jobs via the job_assignments
def self.overlapping(job_assignments)
jobs_table = Job.arel_table
query = Job.scoped
job_assignments.each do |ja|
query = query.where((jobs_table[:start_datetime].in(ja.scheduled_start..ja.estimated_end)).
or(jobs_table[:end_datetime].in(ja.scheduled_start..ja.estimated_end)))
end
query
You can’t perform that action at this time.