Skip to content

Instantly share code, notes, and snippets.

@lukewduncan
Last active April 11, 2017 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukewduncan/8f75549e7954a0ac7fe9913120effbd8 to your computer and use it in GitHub Desktop.
Save lukewduncan/8f75549e7954a0ac7fe9913120effbd8 to your computer and use it in GitHub Desktop.
SELECT STUDENTS.name, case when PAYMENTS.amount > 0 then 'true' else 'false' end AS have_paid,
FROM students WHERE MONTH(PAYMENTS.created_at) = 2
class StringValidator
attr_accessor :string
def initialize(string)
puts valid_string?(string)
end
def valid_string?(string)
return false unless string.length >= 8
return false unless string =~ /[0-9]/
return false unless string =~ /[[:upper:]]/
return false unless string =~ /[[:lower:]]/
true
end
end
result_false = StringValidator.new('hello123')
puts result_false #false
result_true = StringValidator.new('hello123Hi')
puts result_true #true
class SimpleMath
def initialize(number1, number2)
@number1 = number1
@number2 = number2
end
def add
puts @number1 + @number2
end
def subtract
puts @number1 - @number2
end
def multiply
puts @number1 * @number2
end
def divide
puts @number1 / @number2
end
end
# example use
# m = SimpleMath.new(4,3)
# m.add
# m.subtract
# m.multiply
# m.divide
I would simply run either: tail -f log production.log
OR
try to run the rails console to see if it booted up on the server
p {
color: blue;
}
SELECT registered_at, COUNT(DISTINCT id) FROM students GROUP BY registered_at
class Person
attr_accessor :title, :first_name, :middle_name, :last_name
def initialize(first_name, middle_name, last_name, title)
return create_person(first_name, middle_name, last_name, title)
end
private
def get_title(title)
if ['Dr.', 'Mr.', 'Mrs.', 'Ms.'].include? title
return title
end
end
def create_person(first_name, middle_name, last_name, title)
person = { first_name: first_name, middle_name: middle_name, last_name: last_name, title: get_title(title) }
end
end
person = Person.new('Robert', 'William', 'Barker', 'Mr.')
puts person
Since a 500 error is occurring, I can narrow down that the error is coming from somewhere on the server side of my application. Hopefully my application is organized enough to where I can narrow the 5xx error and figure out what exactly might be happening.
1) First thing is I would check the applications log file to see if there were any specific errors that the 500 was pulling. This would probably give me my best chance of figuring out what is wrong. But if not I would move onto step 2.
2) I would check out the code/api endpoint that needs diagnosed, and I would evaluate if any dependencies might be effecting the response. I would also make sure logging is turned on in production to make sure that errors are being logged.
3) After evaluating and checking out the code to make sure it looks good, I would test the endpoint in a development environment to see if I could replicate getting the 500 error.
3) If I couldn't get the 500 error, I would perhaps see if I could refactor any of the endpoint to potentially fix the problem. At this point
4) Here I would start to think it was a connection issue, where too many connections might be occuring at one time on the endpoint. I would try and increase allowed connections and also see if I could decrease any external connections to my database so I can make sure that data gets passed through without 500 error.
5) At this point, if my application had an .htaccess file, I would remove it to make sure that this is not the problem (which most likely it wouldn't be because my API for the most part is working).
$.ajax({
url: '/api/v1/students.json',
dataType: 'json',
success: function(data) {
$('#students').append(data.students);
},
error: function (request, error) {
console.log(error);
}
});
// or render partial through js.erb where my endpoint responds to format.js
$.ajax({
url: '/api/v1/students.json',
dataType: 'json',
success: function(data) {
$('#students').html('<%= @students_variable %>');
},
error: function (request, error) {
console.log(error);
}
});
Object.keys(people).forEach(function (key) {
console.log(people[key].first_name);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment