Skip to content

Instantly share code, notes, and snippets.

View baldwindavid's full-sized avatar

David Baldwin baldwindavid

  • Indianapolis, IN
View GitHub Profile
@baldwindavid
baldwindavid / gist:3229724
Created August 1, 2012 18:47
Git aliases
alias g="git"
# Log
alias gl="gitx"
# Commit: Prepare Commit in Gitx (run gitx first to refresh)
alias gc="gitx; gitx -c"
# Checkout branch
alias gco="g checkout"
@baldwindavid
baldwindavid / dependent_presence_validator.rb
Created February 27, 2013 19:19
A validator that checks the presence of other related fields that should be present. It would probably always be used in conjunction with :allow_blank => true.
class DependentPresenceValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
dependents = [options[:dependents]].flatten
dependents.each do |dependent|
unless record.send(dependent).present?
record.errors.add dependent, "must not be blank when #{attribute.to_s.humanize} is present."
end

Keybase proof

I hereby claim:

  • I am baldwindavid on github.
  • I am baldwindavid (https://keybase.io/baldwindavid) on keybase.
  • I have a public key whose fingerprint is 4F3A C424 8315 8EF6 3CC5 DCF1 E130 F0B0 D0D2 73C2

To claim this, I am signing this object:

@baldwindavid
baldwindavid / thesaurus.rb
Last active April 15, 2021 16:09
You'll need an API key from words.bighugelabs.com
require 'rubygems'
require 'net/http'
require 'uri'
require 'json'
require 'cgi'
# Get a free API key at https://words.bighugelabs.com/account/getkey
API_KEY = '[YOUR API KEY HERE]'
API_VERSION = 2
WORDS_PER_LINE = 4
module Pipe
# Calls a list of methods in succession (i.e. pipes through)
# Include the module in your class to prove the `pipe` method.
#
# Example:
#
# include Pipe
#
# def do_a_thing
defmodule Elevate.Networking.NetworkUpdater do
alias Elevate.Networking.NetworkConnection, as: Connection
alias Elevate.Networking.SubnetBuilder
def disable_access(
user_id: user_id,
network_id: network_id,
vlan_only_id: vlan_only_id,
site_id: site_id
) do
@baldwindavid
baldwindavid / s3_direct.ex
Last active October 1, 2019 05:54
Some methods to generate fields to be used for direct s3 upload
defmodule S3.DirectUpload do
import ExAws.Auth.Utils, only: [amz_date: 1]
import ExAws.S3.Utils
@default_max_size_kilobytes 5_242_880
@default_expiry_seconds 3600
@type canned_acl ::
:private
| :public_read
defmodule Capturepipe do
@doc """
A pipe-operator that extends the normal pipe
in one tiny way:
It allows the syntax of having a bare `&1` capture
to exist inside a datastructure as one of the pipe results.
This is useful to insert the pipe's results into a datastructure
such as a tuple.
unit_statuses =
# There is a Unit schema that is tied to a "units" table
from(unit in Unit,
# grab a lease tied to a unit (office space)
# Leases have start and end dates so the lease must be during the week
# of the given `date`. This will scope leases to that requirement.
left_join: lease in ^Leasing.filter_active_leases_during_week(Lease, date),
on: lease.unit_id == unit.id,
# join the unit type (Salon, Office, Focus, etc)
join: unit_type in assoc(unit, :unit_type),
############################################################
# APP ROLES
############################################################
def insert_app_super_admin_role, do: insert(:super_admin) |> Roles.role_for()
def insert_app_admin_role, do: insert(:admin) |> Roles.role_for()
def insert_app_marketer_role, do: insert(:marketer) |> Roles.role_for()
def insert_app_user_role, do: insert(:user) |> Roles.role_for()
def insert_all_app_roles, do: insert_app_roles(@roles)