Skip to content

Instantly share code, notes, and snippets.

View mikecmpbll's full-sized avatar
🎯
Focusing

Mike Campbell mikecmpbll

🎯
Focusing
  • Skipton, North Yorkshire
View GitHub Profile
@mikecmpbll
mikecmpbll / gist:3426276
Created August 22, 2012 14:42
Mysql2 error
# MySQL db, Rails 3.2, Ruby 1.8.7
# Works for anything other than 1 in: `students`.`sen_status_id` IN ...
# sens_status_id is an int column.
# There are significantly more rows with 1 than anything else, some are NULL, others are 2 and 3
Student Load (38.5ms) SELECT DISTINCT students.* FROM `students` LEFT JOIN klasses_students ON ( klasses_students.student_id = students.id ) WHERE `students`.`sen_status_id` IN (1, 2) AND `klasses_students`.`klass_id` IN (1, 2, 3, 4, 5, 6, 7, 8, 9) AND (archived = 0) ORDER BY firstname ASC
Mysql2::Error: Lost connection to MySQL server during query: SELECT DISTINCT students.* FROM `students` LEFT JOIN klasses_students ON ( klasses_students.student_id = students.id ) WHERE `students`.`sen_status_id` IN (1, 2) AND `klasses_students`.`klass_id` IN (1, 2, 3, 4, 5, 6, 7, 8, 9) AND (archived = 0) ORDER BY firstname ASC
Completed 500 Internal Server Error in 85ms
ActiveRecord::StatementInvalid (Mysql2::Error: Lost connection to MySQL server during query: SELECT DISTINCT student
* executing `bundle:install'
* executing "cd /home/deploy/myapp/releases/20120907141346 && bundle install --gemfile /home/deploy/myapp/releases/20120907141346/Gemfile --path /home/deploy/myapp/shared/bundle --deployment --quiet --without development test"
servers: ["mike-test"]
[mike-test] executing command
[mike-test] rvm_path=$HOME/.rvm/ $HOME/.rvm/bin/rvm-shell '1.9.3' -c 'cd /home/deploy/myapp/releases/20120907141346 && bundle install --gemfile /home/deploy/myapp/releases/20120907141346/Gemfile --path /home/deploy/myapp/shared/bundle --deployment --quiet --without development test'
** [out :: mike-test] Some gems seem to be missing from your vendor/cache directory.
** [out :: mike-test] Could not find log4r-1.1.10 in any of the sources
command finished in 10398ms
*** [deploy:update_code] rolling back
$(document).ready( function() {
school_id = $('h1 a:first').attr('data-id');
source_code = $('h1 a:first').attr('data-sc');
$.ajax({
url: 'https://api.mywebsite.net/schools/' + school_id + '/imports?source_code=' + source_code,
dataType: 'json',
success: function(data) {
$('tr#results_placeholder').remove();
SELECT `students`.`id`
FROM `students`
LEFT OUTER JOIN `klasses_students`
ON `klasses_students`.`student_id` = `students`.`id`
LEFT OUTER JOIN `klasses`
ON `klasses`.`id` = `klasses_students`.`klass_id`
WHERE (klasses_students.klass_id IN (360,377,378))
AND (students.name LIKE '%charles%')
ORDER BY surname ASC, firstname ASC
.fields.condition{ "data-object-name" => f.object_name }
%p
= link_to_remove_fields t(:advanced_search_remove_condition), f
= f.attribute_fields do |a|
%span.fields{ "data-object-name" => f.object_name }
= a.attribute_select :associations => %w(account tags activities emails addresses)
= f.predicate_select({:only => [:cont, :not_cont, :blank, :present, :null, :not_null, :matches, :does_not_match, :eq, :not_eq, :lt, :gt], :compounds => false}, :class => "predicate")
4 def import
5 unless params[:file].blank?
6 labels = Array.new
7 IO.foreach( params[:file].tempfile ) do |line|
8 if /;/.match( line )
9 labels << line.split( ';' )
10 elsif /,/.match( line )
11 labels << line.split( ',' )
12 else
13 labels << line
@mikecmpbll
mikecmpbll / schema.rb
Last active December 14, 2015 23:59
I'm hoping to return only the Incidents where the user has permission "inc" for ALL categories of that Incident.
Incident.joins(categories: [{category_marks: [{ user_group: :users }] }])
.where("users.id = ? AND category_marks.inc = ?", user.id, true)
.group('incidents.id')
<p class="notice" style="display: none;"></p>
<p class="errorExplanation" style="display: none;"></p>
<%= form_tag contact_path, remote: true do -%>
<ul>
<li><%= label_tag :subject %> <%= text_field_tag :subject %></li>
<li><%= label_tag :phone %> <%= text_field_tag :phone, nil, class: :required %></li>
<li><%= label_tag :message %> <%= text_area_tag :message, nil, rows: 6, class: :required %>
<span class="desc">Please provide as much detail as you can about the nature of your request.</span>
</li>
<li><%= button_tag "Send" %></li>
@mikecmpbll
mikecmpbll / gist:5487888
Last active December 16, 2015 19:50
execute SQL syntax
execute <<-SQL
CREATE TABLE #{t}2 LIKE #{t};
INSERT INTO #{t}2 (SELECT * FROM #{t} GROUP BY #{c.join(", ")});
DROP TABLE #{t};
RENAME TABLE #{t}2 TO #{t};
SQL
Error:
== AddIndexesOnJoinTables: migrating =========================================
ans = TestAnswer.find_by_test_id_and_question_number(test.id, question.number)
if ans.nil?
TestAnswer.create(test_id: test.id, question_number: question.number, answer: params[:answer])
end