Skip to content

Instantly share code, notes, and snippets.

View adammcarth's full-sized avatar

Adam McArthur adammcarth

View GitHub Profile
# .github/workflows/example-1.yml
name: My First Manual Workflow
on: [workflow_dispatch]
jobs:
example:
name: Example Job
runs-on: ubuntu-latest
steps:
- name: Clone Repository
[{
"userId": "",
"email": "",
"pin": "",
"recordList": [
{
"type": "discogs",
"id": "<discogs_id>"
},
@adammcarth
adammcarth / homepage.marko
Created November 27, 2015 12:30
Potential navigation bar component in Marko JS
<!-- /src/pages/homepage/homepage.marko -->
<layout-use template="../../layouts/layout.marko" navbar-current="home">
<layout-put into="body">
...
</layout-put>
</layout-use>
@adammcarth
adammcarth / app.js
Last active December 25, 2015 18:39
Working with a json response in jQuery.
$.ajax({
// blah-blah-blah,
success: outputSomething
});
function outputSomething(data) {
$.each(data.errors, function(field, message) {
alert(field); // alert("body"), alert ("name")
})
}
@adammcarth
adammcarth / app.js
Last active December 25, 2015 16:09
Ajax post request in jQuery
var commentForm = $("form#newComment");
commentForm.submit(function() {
event.preventDefault();
$("#commentName").attr("disabled", true);
$("#commentGravatar").attr("disabled", true);
$("#commentWebsite").attr("disabled", true);
$("#commentBody").attr("disabled", true);
$("#createComment").attr("disabled", true);
@adammcarth
adammcarth / comment.rb
Last active December 25, 2015 03:59
Validate website url
class Comment < ActiveModel::Base
validate :valid_url?, :allow_blank => true
def valid_url?
if (self.website).start_with?("http://", "https://") and (self.website).end_with?(".*")
return true
elsif (self.website).end_with?(".*")
return true
self.website = "http://#{self.website}"
else
return self.errors[:website] << "The website you entered (#{self.website}) is invalid. Please try again."
@adammcarth
adammcarth / comment.rb
Created October 9, 2013 10:36
Validating and saving a Gravatar URL
class AvatarValidator < ActiveModel::Validator
def validate(record)
unless gravatar_exists?
return record.errors[:avatar] << "No display picture could be found on Gravatar using #{record.avatar}."
end
end
end
class Comment < ActiveRecord::Base
has_one :post
@adammcarth
adammcarth / search.rb
Last active December 21, 2015 11:59
SQL syntax to execute a search from query string.
# URL Visiting: example.com/posts?search=My+search+text&m=aug&y=13
search_sql = "MATCH (title,tags) AGAINST ('query_string('search')' IN BOOLEAN MODE)"
#=> MATCH (title,tags) AGAINST ('My search text' IN BOOLEAN MODE)
month_sql = "created_at LIKE ('%-#{return_month_number(query_string('m'))}-%')"
#=> created_at LIKE ('%-08-%')
year_sql = "MATCH (created_at) AGAINST ('#{(Time.now.strftime('%Y')[0..1]).to_s + query_string('y').to_s}' IN BOOLEAN MODE)"
#=> MATCH (created_at) AGAINST ('2013')
Post.where(
@adammcarth
adammcarth / aim.txt
Created March 10, 2013 07:57
If statement inside an image_tag
What I'm trying to achieve?
I want to have a left tooltip (tooltip-left) for the 2 results which display on the left hand side, and a right tooltip (tooltip-right) for the other 2 results which display on the right.
@adammcarth
adammcarth / andrewpank.js
Last active December 10, 2015 14:59
:)
var andrewpank = array(
"watermelon",
"pinapple",
"strawberrires"
);