Monday, August 24, 2015
Friday, August 21, 2015
create a rails app dir first
mkdir jwptest cd jwptest rvm use ruby-2.2.2@jwptest --ruby-version --create gem install rails rails new .
use link_to with an image_tag
<%= link_to image_tag("http://images.prepware.com/thumbnails/vtpp/00.jpg", :alt => 'vtpp-00', size:"130"), view_video_path(content_id:"00") %>
install tidy5 using homebrew
http://stackoverflow.com/questions/13380012/tidy-html5-on-mac-os-how-to-install
[smr@smr ~]$ tidy5 -indent --indent-spaces 2 --tab-size 2 -wrap /Users/smr/Desktop/student-home.html [smr@smr ~]$ tidy5 -indent --indent-spaces 2 -wrap --show-warnings 0 --output-file tidied.html /Users/smr/Desktop/student-home.html
[smr@smr ~]$ tidy5 -show-config | pbcopy Configuration File Settings: Name Type Current Value =========================== ========= ======================================== accessibility-check enum 0 (Tidy Classic) add-xml-decl Boolean no add-xml-space Boolean no alt-text String anchor-as-name Boolean yes ascii-chars Boolean no assume-xml-procins Boolean no bare Boolean no break-before-br Boolean no char-encoding Encoding utf8 clean Boolean no coerce-endtags Boolean yes css-prefix String decorate-inferred-ul Boolean no doctype DocType auto doctype-mode Integer *2 drop-empty-elements Boolean yes drop-empty-paras Boolean yes drop-font-tags Boolean no drop-proprietary-attributes Boolean no enclose-block-text Boolean no enclose-text Boolean no error-file String escape-cdata Boolean no fix-backslash Boolean yes fix-bad-comments Boolean yes fix-uri Boolean yes force-output Boolean no gdoc Boolean no gnu-emacs Boolean no gnu-emacs-file String hide-comments Boolean no hide-endtags Boolean no indent AutoBool no indent-attributes Boolean no indent-cdata Boolean no indent-spaces Integer 2 indent-with-tabs Boolean no input-encoding Encoding utf8 input-xml Boolean no join-classes Boolean no join-styles Boolean yes keep-time Boolean no language String literal-attributes Boolean no logical-emphasis Boolean no lower-literals Boolean yes markup Boolean yes merge-divs AutoBool auto merge-emphasis Boolean yes merge-spans AutoBool auto ncr Boolean yes new-blocklevel-tags Tag names new-empty-tags Tag names new-inline-tags Tag names new-pre-tags Tag names newline enum LF numeric-entities Boolean no omit-optional-tags Boolean no output-bom AutoBool auto output-encoding Encoding utf8 output-file String output-html Boolean no output-xhtml Boolean no output-xml Boolean no preserve-entities Boolean no punctuation-wrap Boolean no quiet Boolean no quote-ampersand Boolean yes quote-marks Boolean no quote-nbsp Boolean yes repeated-attributes enum keep-last replace-color Boolean no show-body-only AutoBool no show-errors Integer 6 show-info Boolean yes show-warnings Boolean yes slide-style String sort-attributes enum none split Boolean no tab-size Integer 8 tidy-mark Boolean yes uppercase-attributes Boolean no uppercase-tags Boolean no vertical-space Boolean no word-2000 Boolean no wrap Integer 68 wrap-asp Boolean yes wrap-attributes Boolean no wrap-jste Boolean yes wrap-php Boolean yes wrap-script-literals Boolean no wrap-sections Boolean yes write-back Boolean no Values marked with an *asterisk are calculated internally by HTML Tidy
Sunday, August 16, 2015
command line rename utility
http://plasmasturm.org/code/rename/
install with homebrew:
install with homebrew:
[smr@smr ~]$ brew install rename ==> Downloading https://homebrew.bintray.com/bottles/rename-1.600.mavericks.bott ######################################################################## 100.0% ==> Pouring rename-1.600.mavericks.bottle.tar.gz 🍺 /usr/local/Cellar/rename/1.600: 3 files, 48K
examplesrename -N ...01 -X -e '$_ = "File-$N"' *specify 0-padding of a given width:rename --dry-run -N 001 -e '$_ = "$N-$_"' *specify a certain starting number:rename --dry-run -N 007 -e '$_ = "$N-$_"' *prepend:rename --dry-run -A "500"- *rename --dry-run -N 001 -A 'xxxx' *rename to incrementally numbered files:rename -N ...01 -X -e '$_ = "File-$N"' *This will throw away all the existing filenames and simply number the files from 1 through however many files there are – except that it will preserve their extensions.perl-like replacement (delete spaces)rename --dry-run 's/ //g' -c *rename s/jpeg/jpg/ *[smr@macpro e-pix]$ rename s/jpeg/jpg/ *[smr@macpro e-pix]$ lltotal 7688drwxr-xr-x 6 smr staff 204 Sep 18 10:14 .drwxr-xr-x 5 smr staff 170 Sep 18 10:11 ..-rw-r--r--@ 1 smr staff 999424 Sep 18 10:10 IMG_4849.jpg-rw-r--r--@ 1 smr staff 983040 Sep 18 10:10 IMG_5051.jpg-rw-r--r--@ 1 smr staff 974848 Sep 18 10:10 IMG_9503.jpg-rw-r--r--@ 1 smr staff 978944 Sep 18 10:10 IMG_9909.jpg
Friday, August 14, 2015
ruby gsub doesnt escape single quotes
# ' means $' which is everything after the match. Escape the \ again and it works
# http://stackoverflow.com/questions/2180322/ruby-gsub-doesnt-escape-single-quotes
to_fix = "Sporty's"
result = to_fix.gsub(/'/, "\\\\'")
puts "result=#{result}"
Thursday, August 13, 2015
set the rvm default, using a gemset
[smr@macbook junkapp]$ rvm use 2.2.2@rails4 --defaulthttp://stackoverflow.com/questions/7788946/rails-keeps-telling-me-that-its-not-currently-installed
use rvm to install ruby 2.2.2 and rails 4.2.2
rvm get head && rvm reload # update rvm
rvm gemset delete rails4 # delete old gemset
rvm install 2.2.2
rvm use 2.2.2
rvm gemset create rails4
rvm use 2.2.2@rails4
which ruby # check to be sure the ruby interpreter is properly set to 2.2.2
hash -r # if ruby interpreter is not pointing to 2.2.2
# install the latest version
gem install rails
# or install a specific version
gem install rails -v 4.2.2
which rails # check to be sure we are using rvm version of rails
##################################################
# useful commands
##################################################
rvm current
rvm info
rvm gemset list
[smr@macbook ~]$ rvm current
ruby-2.2.2@rails4
[smr@macbook ~]$ rvm gemset list
gemsets for ruby-2.2.2 (found in /Users/smr/.rvm/gems/ruby-2.2.2)
(default)
global
=> rails4
[smr@macbook ~]$ rvm info
ruby-2.2.2@rails4:
system:
uname: "Darwin macbook.local 14.1.0 Darwin Kernel Version 14.1.0: Mon Dec 22 23:10:38 PST 2014; root:xnu-2782.10.72~2/RELEASE_X86_64 x86_64"
system: "osx/10.10/x86_64"
bash: "/bin/bash => GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin14)"
zsh: "/bin/zsh => zsh 5.0.5 (x86_64-apple-darwin14.0)"
rvm:
version: "rvm 1.26.11 (master) by Wayne E. Seguin , Michal Papis [https://rvm.io/]"
updated: "18 minutes 29 seconds ago"
path: "/Users/smr/.rvm"
ruby:
interpreter: "ruby"
version: "2.2.2p95"
date: "2015-04-13"
platform: "x86_64-darwin14"
patchlevel: "2015-04-13 revision 50295"
full_version: "ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin14]"
homes:
gem: "/Users/smr/.rvm/gems/ruby-2.2.2@rails4"
ruby: "/Users/smr/.rvm/rubies/ruby-2.2.2"
binaries:
ruby: "/Users/smr/.rvm/rubies/ruby-2.2.2/bin/ruby"
irb: "/Users/smr/.rvm/rubies/ruby-2.2.2/bin/irb"
gem: "/Users/smr/.rvm/rubies/ruby-2.2.2/bin/gem"
rake: "/Users/smr/.rvm/rubies/ruby-2.2.2/bin/rake"
environment:
PATH: "/Users/smr/.rvm/gems/ruby-2.2.2@rails4/bin:/Users/smr/.rvm/gems/ruby-2.2.2@global/bin:/Users/smr/.rvm/rubies/ruby-2.2.2/bin:/Users/smr/.rvm/bin:/usr/local/bin:/usr/local/sbin:/bin:/Developer/Tools:/usr/local/mysql/bin:/Users/smr/bin:/Users/smr/android_dev/android-sdk-mac_x86/tools:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
GEM_HOME: "/Users/smr/.rvm/gems/ruby-2.2.2@rails4"
GEM_PATH: "/Users/smr/.rvm/gems/ruby-2.2.2@rails4:/Users/smr/.rvm/gems/ruby-2.2.2@global"
MY_RUBY_HOME: "/Users/smr/.rvm/rubies/ruby-2.2.2"
IRBRC: "/Users/smr/.rvm/rubies/ruby-2.2.2/.irbrc"
RUBYOPT: ""
gemset: "rails4"
[smr@macbook ~]$
reference:
http://stackoverflow.com/questions/3648392/install-rails-3-on-osx-with-rvm/3652137#3652137
Wednesday, August 12, 2015
coffeescript button loading state
use .button('loading') and .button('reset')
jQuery ->
if $('div.performance-history').length
$(".btn-show-perf-chart").on "click", (event) ->
# set the loading state of the clicked button
$(this).button('loading')
$(".btn-show-perf-chart").on "ajax:success", (event) ->
# we render the chartusing as js.erb template. now show it.
$('#chartDialog').modal()
# reset the loading state of the clicked button
$(this).button('reset')
Thursday, August 6, 2015
notes for adding or manually tweaking PWO school/users/subscriptions
need:
- school with act code
- user
- subscription with user and same act code
- school affiliation with user and school
ruby script to generate secure passwords
#!/usr/bin/env ruby require 'securerandom' puts SecureRandom.urlsafe_base64http://ruby-doc.org/stdlib-1.9.3/libdoc/securerandom/rdoc/SecureRandom.html
Wednesday, August 5, 2015
Tuesday, August 4, 2015
add images to a prawn pdf
# figures
if should_print_figures
seen = {}
questions.each do |question|
question.figures.each do |figure|
seen[figure.filename] = true #filename is just a stem
end
end
seen.each_key do |filename|
ext = "jpg"
if filename =~ /airframe|cfi|general|private|powerplant/ #png versions exist for these
ext = "png"
end
path = "#{Rails.root}/content/figs_for_print_quiz/#{filename}.#{ext}"
# image path, :width => bounds.width
# http://prawnpdf.org/docs/0.11.1/Prawn/Images.html
image path, :fit => [bounds.width, bounds.height]
end
# questions.each do |question|
# if question.figures.count
# question.figures.each do |figure|
# # text figure.filename
# # the url way
# # url = "http://images.prepware.com.s3.amazonaws.com/prepware/#{figure.filename}.png"
# # url = "http://images.prepware.com.s3.amazonaws.com/prepware_figs_for_print_quiz_TEST/#{figure.filename}.png"
# # content = open(url)
# # the local file way
# path = "#{Rails.root}/content/figs_for_print_quiz/#{figure.filename}.png"
# image path, :width => bounds.width
# # p bounds.width
# end
# end
# end
end
Monday, August 3, 2015
PWO testing gotcha
if you manually duplicate users in the dev database as part of low level hacking, remember to change the remember_token to a unique value.
Saturday, August 1, 2015
troubleshoot PWO-107 wrong numq in Ground Instructor quiz
bug in a nutshell
- generating a onestep quiz calls qdbm.qids_for_quiz_defn
- chapter.questions with category joins is returning duplicates. e.g. book id 7, chapter 2 returns [3388, 3601, 4200, 3348, 3288, 3483, 3376, 3284, 4096, 3427, 3656, 3301, 3543, 3316, 3601]
- need to rework to add uniq
new approach
- add uniq get ids with out dups
- shuffle
- pull num ids required from shuffles list
1.9.3p286 :047 > qids=qdbm.qids_for_quiz_defn(qd); p qids.count; p qids; p qids.uniq.count; p qids.uniq!
(0.5ms) SELECT `categories`.id FROM `categories` INNER JOIN `categories_quiz_definitions` ON `categories`.`id` = `categories_quiz_definitions`.`category_id` WHERE `categories_quiz_definitions`.`quiz_definition_id` = 15
Chapter Load (0.3ms) SELECT `chapters`.* FROM `chapters` WHERE `chapters`.`book_id` = 7 AND `chapters`.`chapnum` = 1 LIMIT 1
(0.2ms) SELECT questions.id FROM `questions` INNER JOIN `categories_questions` ON `categories_questions`.`question_id` = `questions`.`id` INNER JOIN `categories` ON `categories`.`id` = `categories_questions`.`category_id` INNER JOIN `book_mappings` ON `questions`.`id` = `book_mappings`.`question_id` WHERE `book_mappings`.`chapter_id` = 76 AND `questions`.`deprecated` = 0 AND (category_id in (3,4,10,11,12,15,17,19)) ORDER BY RAND() LIMIT 0
[]
Chapter Load (0.2ms) SELECT `chapters`.* FROM `chapters` WHERE `chapters`.`book_id` = 7 AND `chapters`.`chapnum` = 2 LIMIT 1
(3.6ms) SELECT questions.id FROM `questions` INNER JOIN `categories_questions` ON `categories_questions`.`question_id` = `questions`.`id` INNER JOIN `categories` ON `categories`.`id` = `categories_questions`.`category_id` INNER JOIN `book_mappings` ON `questions`.`id` = `book_mappings`.`question_id` WHERE `book_mappings`.`chapter_id` = 77 AND `questions`.`deprecated` = 0 AND (category_id in (3,4,10,11,12,15,17,19)) ORDER BY RAND() LIMIT 15
[3388, 3601, 4200, 3348, 3288, 3483, 3376, 3284, 4096, 3427, 3656, 3301, 3543, 3316, 3601]
Chapter Load (0.4ms) SELECT `chapters`.* FROM `chapters` WHERE `chapters`.`book_id` = 7 AND `chapters`.`chapnum` = 3 LIMIT 1
(2.8ms) SELECT questions.id FROM `questions` INNER JOIN `categories_questions` ON `categories_questions`.`question_id` = `questions`.`id` INNER JOIN `categories` ON `categories`.`id` = `categories_questions`.`category_id` INNER JOIN `book_mappings` ON `questions`.`id` = `book_mappings`.`question_id` WHERE `book_mappings`.`chapter_id` = 78 AND `questions`.`deprecated` = 0 AND (category_id in (3,4,10,11,12,15,17,19)) ORDER BY RAND() LIMIT 9
[3368, 4084, 3448, 4110, 3441, 4055, 3438, 4111, 4105]
Chapter Load (0.2ms) SELECT `chapters`.* FROM `chapters` WHERE `chapters`.`book_id` = 7 AND `chapters`.`chapnum` = 4 LIMIT 1
(2.1ms) SELECT questions.id FROM `questions` INNER JOIN `categories_questions` ON `categories_questions`.`question_id` = `questions`.`id` INNER JOIN `categories` ON `categories`.`id` = `categories_questions`.`category_id` INNER JOIN `book_mappings` ON `questions`.`id` = `book_mappings`.`question_id` WHERE `book_mappings`.`chapter_id` = 79 AND `questions`.`deprecated` = 0 AND (category_id in (3,4,10,11,12,15,17,19)) ORDER BY RAND() LIMIT 9
[3577, 3557, 3620, 3565, 3591, 3546, 10896, 3576, 3607]
Chapter Load (0.2ms) SELECT `chapters`.* FROM `chapters` WHERE `chapters`.`book_id` = 7 AND `chapters`.`chapnum` = 5 LIMIT 1
(2.3ms) SELECT questions.id FROM `questions` INNER JOIN `categories_questions` ON `categories_questions`.`question_id` = `questions`.`id` INNER JOIN `categories` ON `categories`.`id` = `categories_questions`.`category_id` INNER JOIN `book_mappings` ON `questions`.`id` = `book_mappings`.`question_id` WHERE `book_mappings`.`chapter_id` = 80 AND `questions`.`deprecated` = 0 AND (category_id in (3,4,10,11,12,15,17,19)) ORDER BY RAND() LIMIT 15
[2940, 3064, 2978, 3000, 3042, 2926, 2961, 10847, 3048, 10948, 3026, 2942, 10949, 3011, 4129]
Chapter Load (0.3ms) SELECT `chapters`.* FROM `chapters` WHERE `chapters`.`book_id` = 7 AND `chapters`.`chapnum` = 6 LIMIT 1
(1.7ms) SELECT questions.id FROM `questions` INNER JOIN `categories_questions` ON `categories_questions`.`question_id` = `questions`.`id` INNER JOIN `categories` ON `categories`.`id` = `categories_questions`.`category_id` INNER JOIN `book_mappings` ON `questions`.`id` = `book_mappings`.`question_id` WHERE `book_mappings`.`chapter_id` = 81 AND `questions`.`deprecated` = 0 AND (category_id in (3,4,10,11,12,15,17,19)) ORDER BY RAND() LIMIT 10
[3673, 3753, 3659, 3706, 3659, 3719, 3663, 3673, 3738, 3660]
Chapter Load (0.3ms) SELECT `chapters`.* FROM `chapters` WHERE `chapters`.`book_id` = 7 AND `chapters`.`chapnum` = 7 LIMIT 1
(1.8ms) SELECT questions.id FROM `questions` INNER JOIN `categories_questions` ON `categories_questions`.`question_id` = `questions`.`id` INNER JOIN `categories` ON `categories`.`id` = `categories_questions`.`category_id` INNER JOIN `book_mappings` ON `questions`.`id` = `book_mappings`.`question_id` WHERE `book_mappings`.`chapter_id` = 82 AND `questions`.`deprecated` = 0 AND (category_id in (3,4,10,11,12,15,17,19)) ORDER BY RAND() LIMIT 8
[3724, 3936, 3904, 3904, 3940, 4043, 3933, 3208]
Chapter Load (0.2ms) SELECT `chapters`.* FROM `chapters` WHERE `chapters`.`book_id` = 7 AND `chapters`.`chapnum` = 8 LIMIT 1
(3.2ms) SELECT questions.id FROM `questions` INNER JOIN `categories_questions` ON `categories_questions`.`question_id` = `questions`.`id` INNER JOIN `categories` ON `categories`.`id` = `categories_questions`.`category_id` INNER JOIN `book_mappings` ON `questions`.`id` = `book_mappings`.`question_id` WHERE `book_mappings`.`chapter_id` = 83 AND `questions`.`deprecated` = 0 AND (category_id in (3,4,10,11,12,15,17,19)) ORDER BY RAND() LIMIT 15
[3081, 4224, 3272, 3222, 3127, 3197, 3195, 3186, 3266, 3172, 3228, 3080, 3246, 3162, 3198]
Chapter Load (0.2ms) SELECT `chapters`.* FROM `chapters` WHERE `chapters`.`book_id` = 7 AND `chapters`.`chapnum` = 9 LIMIT 1
(3.9ms) SELECT questions.id FROM `questions` INNER JOIN `categories_questions` ON `categories_questions`.`question_id` = `questions`.`id` INNER JOIN `categories` ON `categories`.`id` = `categories_questions`.`category_id` INNER JOIN `book_mappings` ON `questions`.`id` = `book_mappings`.`question_id` WHERE `book_mappings`.`chapter_id` = 84 AND `questions`.`deprecated` = 0 AND (category_id in (3,4,10,11,12,15,17,19)) ORDER BY RAND() LIMIT 15
[3809, 3801, 3784, 3843, 3855, 3812, 3814, 3790, 3783, 3990, 3994, 3772, 3804, 3900, 3817]
Chapter Load (0.2ms) SELECT `chapters`.* FROM `chapters` WHERE `chapters`.`book_id` = 7 AND `chapters`.`chapnum` = 10 LIMIT 1
(1.0ms) SELECT questions.id FROM `questions` INNER JOIN `categories_questions` ON `categories_questions`.`question_id` = `questions`.`id` INNER JOIN `categories` ON `categories`.`id` = `categories_questions`.`category_id` INNER JOIN `book_mappings` ON `questions`.`id` = `book_mappings`.`question_id` WHERE `book_mappings`.`chapter_id` = 85 AND `questions`.`deprecated` = 0 AND (category_id in (3,4,10,11,12,15,17,19)) ORDER BY RAND() LIMIT 4
[3943, 4035, 3974, 4029]
100 qids pulled from QuestionDatabaseMiner
[3388, 3601, 4200, 3348, 3288, 3483, 3376, 3284, 4096, 3427, 3656, 3301, 3543, 3316, 3601, 3368, 4084, 3448, 4110, 3441, 4055, 3438, 4111, 4105, 3577, 3557, 3620, 3565, 3591, 3546, 10896, 3576, 3607, 2940, 3064, 2978, 3000, 3042, 2926, 2961, 10847, 3048, 10948, 3026, 2942, 10949, 3011, 4129, 3673, 3753, 3659, 3706, 3659, 3719, 3663, 3673, 3738, 3660, 3724, 3936, 3904, 3904, 3940, 4043, 3933, 3208, 3081, 4224, 3272, 3222, 3127, 3197, 3195, 3186, 3266, 3172, 3228, 3080, 3246, 3162, 3198, 3809, 3801, 3784, 3843, 3855, 3812, 3814, 3790, 3783, 3990, 3994, 3772, 3804, 3900, 3817, 3943, 4035, 3974, 4029]
use uniq! to get rid of duplicates, only 96 remain
[3388, 3601, 4200, 3348, 3288, 3483, 3376, 3284, 4096, 3427, 3656, 3301, 3543, 3316, 3368, 4084, 3448, 4110, 3441, 4055, 3438, 4111, 4105, 3577, 3557, 3620, 3565, 3591, 3546, 10896, 3576, 3607, 2940, 3064, 2978, 3000, 3042, 2926, 2961, 10847, 3048, 10948, 3026, 2942, 10949, 3011, 4129, 3673, 3753, 3659, 3706, 3719, 3663, 3738, 3660, 3724, 3936, 3904, 3940, 4043, 3933, 3208, 3081, 4224, 3272, 3222, 3127, 3197, 3195, 3186, 3266, 3172, 3228, 3080, 3246, 3162, 3198, 3809, 3801, 3784, 3843, 3855, 3812, 3814, 3790, 3783, 3990, 3994, 3772, 3804, 3900, 3817, 3943, 4035, 3974, 4029]
the initial array, sorted to help ferret out the duplicates
[2926, 2940, 2942, 2961, 2978, 3000, 3011, 3026, 3042, 3048, 3064, 3080, 3081, 3127, 3162, 3172, 3186, 3195, 3197, 3198, 3208, 3222, 3228, 3246, 3266, 3272, 3284, 3288, 3301, 3316, 3348, 3368, 3376, 3388, 3427, 3438, 3441, 3448, 3483, 3543, 3546, 3557, 3565, 3576, 3577, 3591, 3601, 3601, 3607, 3620, 3656, 3659, 3659, 3660, 3663, 3673, 3673, 3706, 3719, 3724, 3738, 3753, 3772, 3783, 3784, 3790, 3801, 3804, 3809, 3812, 3814, 3817, 3843, 3855, 3900, 3904, 3904, 3933, 3936, 3940, 3943, 3974, 3990, 3994, 4029, 4035, 4043, 4055, 4084, 4096, 4105, 4110, 4111, 4129, 4200, 4224, 10847, 10896, 10948, 10949]
##################################################
# chapter questions
##################################################
1.9.3p286 :067 > chapter=Book.find(7).chapters.find_by_chapnum(2)
1.9.3p286 :067 > chapter.questions.pluck("questions.id")
(0.9ms) SELECT questions.id FROM `questions` INNER JOIN `book_mappings` ON `questions`.`id` = `book_mappings`.`question_id` WHERE `book_mappings`.`chapter_id` = 77
=> [3274, 3275, 3276, 3277, 3278, 3279, 3280, 3281, 3282, 3283, 3284, 3285, 3286, 3287, 3288, 3289, 3290, 3291, 3292, 3293, 3294, 3295, 3296, 3297, 3298, 3299, 3300, 3301, 3302, 3303, 3304, 3305, 3306, 3307, 3308, 3309, 3310, 3311, 3312, 3313, 3314, 3315, 3316, 3317, 3318, 3319, 3320, 3321, 3322, 3323, 3324, 3325, 3326, 3327, 3328, 3329, 3330, 3331, 3332, 3333, 3334, 3335, 3336, 3337, 3338, 3339, 3340, 3341, 3342, 3343, 3344, 3345, 3346, 3347, 3348, 3349, 3350, 3351, 3352, 3353, 3354, 3355, 3356, 3370, 3371, 3373, 3374, 3375, 3376, 3377, 3378, 3379, 3380, 3381, 3382, 3383, 3384, 3385, 3386, 3387, 3388, 3389, 3390, 3391, 3392, 3393, 3394, 3395, 3396, 3397, 3398, 3399, 3400, 3401, 3402, 3403, 3404, 3409, 3411, 3413, 3414, 3415, 3416, 3417, 3418, 3419, 3420, 3421, 3422, 3423, 3424, 3425, 3426, 3427, 3428, 3429, 3430, 3431, 3432, 3480, 3481, 3482, 3483, 3484, 3485, 3491, 3492, 3494, 3509, 3525, 3526, 3527, 3528, 3529, 3543, 3601, 3609, 3623, 3633, 3636, 3637, 3638, 3639, 3640, 3642, 3652, 3653, 3654, 3655, 3656, 3657, 3890, 3891, 3893, 3894, 3895, 3896, 3897, 3898, 3992, 4002, 4003, 4016, 4017, 4018, 4019, 4020, 4021, 4022, 4023, 4024, 4025, 4057, 4058, 4059, 4076, 4077, 4078, 4079, 4080, 4081, 4082, 4083, 4085, 4086, 4087, 4088, 4089, 4090, 4091, 4092, 4094, 4096, 4097, 4098, 4200, 4201]
217 records
1.9.3p286 :092 > Book.find(7).chapters.find_by_chapnum(2).questions.pluck("questions.id").count
=> 217
no duplicates
1.9.3p286 :079 > Book.find(7).chapters.find_by_chapnum(2).questions.pluck("questions.id").uniq!
=> nil
chap 2
Chapter Load (0.2ms) SELECT `chapters`.* FROM `chapters` WHERE `chapters`.`book_id` = 7 AND `chapters`.`chapnum` = 2 LIMIT 1
(3.7ms) SELECT questions.id FROM `questions` INNER JOIN `categories_questions` ON `categories_questions`.`question_id` = `questions`.`id` INNER JOIN `categories` ON `categories`.`id` = `categories_questions`.`category_id` INNER JOIN `book_mappings` ON `questions`.`id` = `book_mappings`.`question_id` WHERE `book_mappings`.`chapter_id` = 77 AND `questions`.`deprecated` = 0 AND (category_id in (3,4,10,11,12,15,17,19)) ORDER BY RAND() LIMIT 15
##################################################
# adding the category where clause
##################################################
1.9.3p286 :101 > Book.find(7).chapters.find_by_chapnum(2).questions.joins(:categories).where("category_id in (3,4,10,11,12,15,17,19)").where(deprecated:false).pluck("questions.id")
Book Load (0.3ms) SELECT `books`.* FROM `books` WHERE `books`.`id` = 7 LIMIT 1
Chapter Load (0.2ms) SELECT `chapters`.* FROM `chapters` WHERE `chapters`.`book_id` = 7 AND `chapters`.`chapnum` = 2 LIMIT 1
(3.8ms) SELECT questions.id FROM `questions` INNER JOIN `categories_questions` ON `categories_questions`.`question_id` = `questions`.`id` INNER JOIN `categories` ON `categories`.`id` = `categories_questions`.`category_id` INNER JOIN `book_mappings` ON `questions`.`id` = `book_mappings`.`question_id` WHERE `book_mappings`.`chapter_id` = 77 AND `questions`.`deprecated` = 0 AND (category_id in (3,4,10,11,12,15,17,19))
=> [3274, 3278, 3279, 3280, 3281, 3282, 3284, 3291, 3292, 3301, 3302, 3304, 3307, 3308, 3309, 3310, 3311, 3312, 3313, 3314, 3315, 3316, 3317, 3318, 3319, 3320, 3321, 3322, 3323, 3324, 3325, 3326, 3327, 3328, 3330, 3331, 3334, 3344, 3345, 3346, 3347, 3348, 3349, 3350, 3351, 3352, 3353, 3354, 3355, 3356, 3480, 3481, 3482, 3483, 3484, 3485, 3543, 3601, 4096, 4097, 4098, 4200, 3275, 3277, 3283, 3285, 3286, 3287, 3288, 3289, 3290, 3293, 3294, 3295, 3296, 3297, 3298, 3299, 3300, 3303, 3305, 3306, 3329, 3332, 3333, 3335, 3336, 3337, 3338, 3339, 3340, 3341, 3342, 3343, 3609, 3278, 3281, 3282, 3284, 3299, 3304, 3306, 3308, 3309, 3310, 3311, 3331, 3334, 3348, 3350, 3351, 3352, 3353, 3354, 3355, 3356, 3414, 3415, 3416, 3417, 3480, 3481, 3482, 3483, 3484, 3485, 3509, 3601, 3638, 3639, 3640, 3642, 3992, 4096, 4097, 3274, 3278, 3279, 3280, 3281, 3282, 3284, 3291, 3292, 3301, 3302, 3304, 3307, 3308, 3309, 3310, 3311, 3312, 3313, 3314, 3315, 3316, 3317, 3318, 3319, 3320, 3321, 3322, 3323, 3324, 3325, 3326, 3327, 3328, 3330, 3331, 3334, 3344, 3345, 3346, 3347, 3348, 3349, 3350, 3351, 3352, 3353, 3354, 3355, 3356, 3480, 3481, 3482, 3483, 3484, 3485, 3543, 3601, 4096, 4097, 4098, 4200, 3418, 3419, 3420, 3421, 3422, 3423, 3424, 3425, 3426, 3427, 3428, 3429, 3430, 3431, 3432, 3525, 3526, 3527, 3528, 3529, 3652, 3653, 3654, 3655, 3656, 3657, 4002, 4003, 4016, 4017, 4018, 4019, 4020, 4021, 4022, 4023, 4024, 4025, 3278, 3280, 3284, 3292, 3301, 3302, 3307, 3308, 3309, 3310, 3311, 3312, 3313, 3314, 3315, 3323, 3324, 3325, 3326, 3327, 3331, 3345, 3346, 3347, 3350, 3351, 3352, 3353, 3354, 3355, 3356, 3543, 3601, 4057, 4058, 4059, 4076, 4077, 4078, 4079, 4080, 4081, 4082, 4083, 4085, 4094, 4096, 4097, 3276, 3370, 3371, 3373, 3374, 3375, 3376, 3377, 3378, 3379, 3380, 3381, 3382, 3383, 3384, 3385, 3386, 3387, 3388, 3389, 3390, 3391, 3392, 3393, 3394, 3395, 3396, 3397, 3398, 3399, 3400, 3401, 3402, 3403, 3404, 3409, 3411, 3413, 3491, 3492, 3494, 3623, 3633, 3636, 3637, 3890, 3891, 3893, 3894, 3895, 3896, 3897, 3898, 4201, 3278, 3279, 3280, 3284, 3292, 3301, 3302, 3304, 3307, 3308, 3309, 3310, 3311, 3312, 3313, 3314, 3315, 3316, 3317, 3318, 3319, 3320, 3321, 3322, 3323, 3324, 3325, 3326, 3327, 3328, 3330, 3331, 3334, 3345, 3346, 3347, 3348, 3350, 3351, 3352, 3353, 3354, 3355, 3356, 3543, 3601, 4086, 4087, 4088, 4089, 4090, 4091, 4092, 4096, 4097, 4200]
1.9.3p286 :102 > Book.find(7).chapters.find_by_chapnum(2).questions.joins(:categories).where("category_id in (3,4,10,11,12,15,17,19)").where(deprecated:false).pluck("questions.id").count
Book Load (0.3ms) SELECT `books`.* FROM `books` WHERE `books`.`id` = 7 LIMIT 1
Chapter Load (0.2ms) SELECT `chapters`.* FROM `chapters` WHERE `chapters`.`book_id` = 7 AND `chapters`.`chapnum` = 2 LIMIT 1
(3.7ms) SELECT questions.id FROM `questions` INNER JOIN `categories_questions` ON `categories_questions`.`question_id` = `questions`.`id` INNER JOIN `categories` ON `categories`.`id` = `categories_questions`.`category_id` INNER JOIN `book_mappings` ON `questions`.`id` = `book_mappings`.`question_id` WHERE `book_mappings`.`chapter_id` = 77 AND `questions`.`deprecated` = 0 AND (category_id in (3,4,10,11,12,15,17,19))
=> 393
##################################################
# duplicates related to the join
##################################################
http://stackoverflow.com/questions/38549/difference-between-inner-and-outer-joins
e.g.
3279 cfi 6506 PLT477 2 5 AIR, LSA, WSC An airplane would have a tendency
3279 cfi 6506 PLT477 2 5 AIR, LSA, WSC An airplane would have a tendency
3279 cfi 6506 PLT477 2 5 AIR, LSA, WSC An airplane would have a tendency
3280 cfi 6507 PLT242 2 4 AIR, LSA, WSC, PPC When considering the forces
3280 cfi 6507 PLT242 2 4 AIR, LSA, WSC, PPC When considering the forces
3280 cfi 6507 PLT242 2 4 AIR, LSA, WSC, PPC When considering the forces
3280 cfi 6507 PLT242 2 4 AIR, LSA, WSC, PPC When considering the forces
##################################################
# resolve with uniq
##################################################
1.9.3p286 :105 > Book.find(7).chapters.find_by_chapnum(2).questions.joins(:categories).where("category_id in (3,4,10,11,12,15,17,19)").where(deprecated:false).pluck("questions.id").uniq
Book Load (0.3ms) SELECT `books`.* FROM `books` WHERE `books`.`id` = 7 LIMIT 1
Chapter Load (0.2ms) SELECT `chapters`.* FROM `chapters` WHERE `chapters`.`book_id` = 7 AND `chapters`.`chapnum` = 2 LIMIT 1
(3.8ms) SELECT questions.id FROM `questions` INNER JOIN `categories_questions` ON `categories_questions`.`question_id` = `questions`.`id` INNER JOIN `categories` ON `categories`.`id` = `categories_questions`.`category_id` INNER JOIN `book_mappings` ON `questions`.`id` = `book_mappings`.`question_id` WHERE `book_mappings`.`chapter_id` = 77 AND `questions`.`deprecated` = 0 AND (category_id in (3,4,10,11,12,15,17,19))
=> [3274, 3278, 3279, 3280, 3281, 3282, 3284, 3291, 3292, 3301, 3302, 3304, 3307, 3308, 3309, 3310, 3311, 3312, 3313, 3314, 3315, 3316, 3317, 3318, 3319, 3320, 3321, 3322, 3323, 3324, 3325, 3326, 3327, 3328, 3330, 3331, 3334, 3344, 3345, 3346, 3347, 3348, 3349, 3350, 3351, 3352, 3353, 3354, 3355, 3356, 3480, 3481, 3482, 3483, 3484, 3485, 3543, 3601, 4096, 4097, 4098, 4200, 3275, 3277, 3283, 3285, 3286, 3287, 3288, 3289, 3290, 3293, 3294, 3295, 3296, 3297, 3298, 3299, 3300, 3303, 3305, 3306, 3329, 3332, 3333, 3335, 3336, 3337, 3338, 3339, 3340, 3341, 3342, 3343, 3609, 3414, 3415, 3416, 3417, 3509, 3638, 3639, 3640, 3642, 3992, 3418, 3419, 3420, 3421, 3422, 3423, 3424, 3425, 3426, 3427, 3428, 3429, 3430, 3431, 3432, 3525, 3526, 3527, 3528, 3529, 3652, 3653, 3654, 3655, 3656, 3657, 4002, 4003, 4016, 4017, 4018, 4019, 4020, 4021, 4022, 4023, 4024, 4025, 4057, 4058, 4059, 4076, 4077, 4078, 4079, 4080, 4081, 4082, 4083, 4085, 4094, 3276, 3370, 3371, 3373, 3374, 3375, 3376, 3377, 3378, 3379, 3380, 3381, 3382, 3383, 3384, 3385, 3386, 3387, 3388, 3389, 3390, 3391, 3392, 3393, 3394, 3395, 3396, 3397, 3398, 3399, 3400, 3401, 3402, 3403, 3404, 3409, 3411, 3413, 3491, 3492, 3494, 3623, 3633, 3636, 3637, 3890, 3891, 3893, 3894, 3895, 3896, 3897, 3898, 4201, 4086, 4087, 4088, 4089, 4090, 4091, 4092]
1.9.3p286 :106 > Book.find(7).chapters.find_by_chapnum(2).questions.joins(:categories).where("category_id in (3,4,10,11,12,15,17,19)").where(deprecated:false).pluck("questions.id").uniq.count
Book Load (0.4ms) SELECT `books`.* FROM `books` WHERE `books`.`id` = 7 LIMIT 1
Chapter Load (0.2ms) SELECT `chapters`.* FROM `chapters` WHERE `chapters`.`book_id` = 7 AND `chapters`.`chapnum` = 2 LIMIT 1
(3.7ms) SELECT questions.id FROM `questions` INNER JOIN `categories_questions` ON `categories_questions`.`question_id` = `questions`.`id` INNER JOIN `categories` ON `categories`.`id` = `categories_questions`.`category_id` INNER JOIN `book_mappings` ON `questions`.`id` = `book_mappings`.`question_id` WHERE `book_mappings`.`chapter_id` = 77 AND `questions`.`deprecated` = 0 AND (category_id in (3,4,10,11,12,15,17,19))
=> 217
coffeescript - run code when an item is chosen from a select control
if $('div#onestep-quizmaker').length
$(".onestep-quiz-type").on "change", ->
$(".onestep-quiz-name").select()
Subscribe to:
Comments (Atom)