Skip to content

Instantly share code, notes, and snippets.

View danbeaulieu's full-sized avatar

Dan Beaulieu danbeaulieu

View GitHub Profile
@danbeaulieu
danbeaulieu / pre-commit.bash
Created May 3, 2012 18:28 — forked from brentsowers1/pre-commit.bash
Git pre-commit hook to prevent non-ascii characters
#!/bin/bash
# Save these contents to .git/hooks/pre-commit in your project
# folder, and give it executable permissions with
# "chmod u+x .git/hooks/pre-commit"
# Git will abort a commit if you have non ASCII characters in
# the commit, and output the non ASCII characters.
output=`git diff HEAD | tr -d "\000-\011\013-\177" | tr -d '\n'`
cnt=${#output}
if [ -n "$output" ]; then
@danbeaulieu
danbeaulieu / pre-commit.bash
Created May 3, 2012 18:28 — forked from brentsowers1/pre-commit.bash
Git pre-commit hook to prevent non-ascii characters
#!/bin/bash
# Save these contents to .git/hooks/pre-commit in your project
# folder, and give it executable permissions with
# "chmod u+x .git/hooks/pre-commit"
# Git will abort a commit if you have non ASCII characters in
# the commit, and output the non ASCII characters.
output=`git diff HEAD | grep ^+[^+] | tr -d "\000-\011\013-\177" | tr -d '\n'`
cnt=${#output}
if [ -n "$output" ]; then
RED="\[\033[0;31m\]"
YELLOW="\[\033[0;33m\]"
GREEN="\[\033[0;32m\]"
BLUE="\[\033[0;34m\]"
LIGHT_RED="\[\033[1;31m\]"
LIGHT_GREEN="\[\033[1;32m\]"
WHITE="\[\033[1;37m\]"
LIGHT_GRAY="\[\033[0;37m\]"
COLOR_NONE="\[\e[0m\]"
end_date = Date.today + 7.days
if request[:end]
end_date = Date.parse(request[:end])
end
1.9.3p194 :022 > Money.new(1000, "USD").format(:with_currency => true)
=> "$10,00 USD"
class TwoListener
def success(one, two)
puts "#{one}, #{two}"
end
end
def sender(listener, *args)
listener.send(:success, *args)
end
Loading development environment (Rails 3.2.6)
1.9.3p194 :001 > I18n.locale
=> :es
1.9.3p194 :002 > I18n.locale = :en
=> :en
1.9.3p194 :005 > p = Product.find(27)
Product Load (0.8ms) SELECT "products".* FROM "products" WHERE "products"."id" = $1 LIMIT 1 [["id", 27]]
=> #<Product id: 27, min_capacity: 2, max_capacity: 10, start_time: "2000-01-01 22:18:00", languages: "English, Spanish", tour_operator_id: 4, created_at: "2012-10-19 22:20:53", updated_at: "2012-10-31 16:06:05", location: "Santiago", duration: #<BigDecimal:5267690,'0.8E1',9(18)>, price_in_local_units: 120000, internal_name: "Dans Climbing Trip", min_api_reservation_hours: 10>
1.9.3p194 :006 > p.translations
Installing pg (0.14.1) with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/home/dan/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb
checking for pg_config... yes
Using config values from /usr/bin/pg_config
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for pg_config_manual.h... yes
checking for PQconnectdb() in -lpq... no
routes:
'calendar': 'calendar',
'calendar/': 'calendar',
'calendar/:date': 'calendar',
'calendar/:date/': 'calendar',
'calendar/:date/:selected_tour_id': 'calendar',
'': 'calendar'
SELECT st.id, sum(r.number_of_people) as people_total
FROM scheduled_tours as st
LEFT JOIN reservations AS r ON st.id = r.scheduled_tour_id
LEFT JOIN products AS p ON p.id = st.product_id
WHERE st.date = '2012-11-08'
GROUP BY st.id, p.max_capacity
HAVING SUM(r.number_of_people) IS null OR SUM(r.number_of_people) < p.max_capacity;
ScheduledTour.
joins(:reservations, :product).