Skip to content

Instantly share code, notes, and snippets.

def asset_value_total_by_date_range(beginning_date, end_date \\ Date.utc_today()) do
range = "#{Date.diff(end_date, beginning_date)} days"
now = Date.utc_today()
date_range_query =
from(v in AssetValue,
select: %{
value: v.value,
drange:
fragment(
Ingredients
2-3lb pork shoulder
1 small onion, finely diced
1 clove garlic, finely diced
2 tbsp olive oil
1⁄2 stick + 1 fat pat butter
1⁄2 cup flour
28oz can crushed tomatoes
1 cup red wine
@ethangunderson
ethangunderson / rails.sh
Created October 29, 2015 15:21
Friendly reminder that exists?, present? and any? behave differently than what you might expect.
irb(main):001:0> User.exists?
users Columns (20.3ms) SHOW FIELDS FROM `users`
User Exists (0.3ms) SELECT 1 AS one FROM `users` LIMIT 1
=> true
irb(main):002:0> User.where(:email => "foo").exists?
User Exists (0.6ms) SELECT 1 AS one FROM `users` WHERE `users`.`email` = 'foo' LIMIT 1
=> false
irb(main):003:0> User.where(:email => "foo").present?
(0.7ms) SELECT COUNT(*) FROM `users` WHERE `users`.`email` = 'foo'
=> false
@ethangunderson
ethangunderson / gist:e4403d02a05fe49872e5
Last active August 29, 2015 20:29
Required Reading
Taco Bell Programming - The examples he gives are kind of shit, and I don't really care about the devops
bashing part, but the last three paragraphs and overall message are golden.
http://widgetsandshit.com/teddziuba/2010/10/taco-bell-programming.html
Tech companies: open allocation is your only real option.
https://michaelochurch.wordpress.com/2012/09/03/tech-companies-open-allocation-is-your-only-real-option/
http://warpspire.com/posts/million-dollar-products/
@ethangunderson
ethangunderson / gist:48e53e388a781a394103
Last active February 10, 2021 16:38
new osx computer setup
osascript -e "tell application \"Terminal\" to set the font size of window 1 to 18"
touch ~/.hushlogin
xcode-select --install
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
brew install \
asdf \
words_to_redact = ["foo", "bar"]
sentance = "This is a sentance to redact, foo"
words = sentance.split(" ")
words.map do |word|
if words_to_redact.include?(word)
"REDACTED"
else
word
end
cl_cmdrate "128"
cl_updaterate "128"
cl_disablehtmlmotd "1"
cl_forcepreload "1"
cl_interp "0"
cl_interp_all "0"
rate "1048576"
cl_crosshairalpha "255"
cl_crosshaircolor "5"
irb(main):001:0> foo
NameError: undefined local variable or method `foo' for main:Object
from (irb):1
from /Users/egunderson/.rubies/ruby-2.1.2/bin/irb:11:in `<main>'
irb(main):002:0> foo = 'bar' if false
=> nil
irb(main):003:0> foo
=> nil
irb(main):004:0>
@ethangunderson
ethangunderson / gist:1d08b4cef049266727e6
Created September 3, 2014 14:39
Find potential missing foreign key indexes
ActiveRecord::Base.logger = nil
connection = ActiveRecord::Base.connection; nil
connection.tables.each do |table|
columns = connection.columns(table).map(&:name).select {|x| x.ends_with?("_id")}
indexed_columns = connection.indexes(table).map(&:columns).flatten.uniq
unindexed = columns - indexed_columns
unless unindexed.empty?
puts "#{table}: #{unindexed.join(", ")}"
end
nil
Programming Elixer
http://pragprog.com/book/elixir/programming-elixir
Programming Clojure
http://pragprog.com/book/shcloj2/programming-clojure
Web Development with Clojure
http://pragprog.com/book/dswdcloj/web-development-with-clojure
Purely Functional Data Structures