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:5575550
Last active December 17, 2015 07:49
Rails Engine view paths
Missing template layouts/application with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. Searched in: * "/Users/mike.campbell/projects/engines/myengine_shell/app/views" * "/Users/mike.campbell/projects/engines/myengine/app/views"
# Myengine is the engine, and MyengineShell is an app which mounts it.
# When I create the engine it generates an application.html.erb layout file in app/views/layouts/myengine/application.html.erb.
# How come my app can't find the layout?
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
@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 =========================================
<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 / 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')
@mikecmpbll
mikecmpbll / totp
Last active October 29, 2015 14:23 — forked from jurisgalang/totp
Ruby implementation of the Time-Based One-Time Password (TOTP) Algorithm described at http://tools.ietf.org/html/rfc6238
[jgalang@rashomon:~/Code/skunkworks/2fa]
∴ ruby totp_demo.rb
Time(sec) Time (UTC format) Value of T(Hex) TOTP Mode OK
------------------------------------------------------------------------------------------
59 1970-01-01 00:00:59 0000000000000001 94287082 SHA1 ✔
59 1970-01-01 00:00:59 0000000000000001 46119246 SHA256 ✔
59 1970-01-01 00:00:59 0000000000000001 90693936 SHA512 ✔
1111111109 2005-03-18 01:58:29 00000000023523EC 07081804 SHA1 ✔
1111111109 2005-03-18 01:58:29 00000000023523EC 68084774 SHA256 ✔
@mikecmpbll
mikecmpbll / _form.html.haml
Created October 27, 2015 16:45
trying to embed erb inside yml locale file
.form-actions
- if params[:action] == "new"
= button_tag type: "submit", class: "btn btn-success btn-cons",
id: "submit" do
= fa_icon "check"
%span &nbsp;Create
= link_to courses_path, class: "btn btn-danger btn-cons" do
= fa_icon "close"
%span &nbsp;Cancel
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
.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")
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