Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am alistairtweed on github.
  • I am alistairtweed (https://keybase.io/alistairtweed) on keybase.
  • I have a public key ASB84mvFmEMo3bf8aLdX-0VrcFHibp_XR1KB9fJV9ZFsHAo

To claim this, I am signing this object:

@alistairtweed
alistairtweed / 2.rb
Last active February 2, 2021 15:06
Advent of Code
data = File.readlines('./input/2.txt').map(&:strip).map do |line|
range, character, string = line.split /:? /
[range.split('-').map(&:to_i), character, string]
end
# Part 1
valid = data.select do |range, character, string|
string.count(character).between?(*range)
end
@alistairtweed
alistairtweed / .rspec
Last active May 9, 2024 22:02
Testing Rails with RSpec, Factory Bot, Faker and Shoulda Matchers
--require spec_helper
@alistairtweed
alistairtweed / my_service.service
Last active November 30, 2019 21:27
systemd Startup Script
[Unit]
Description=<description>
[Service]
Type=<type:forking,oneshot...>
User=<user>
WorkingDirectory=<absolute path to working directory>
Environment=<environment variable>
ExecStart=/bin/bash <script to run on start>
ExecStop=/bin/bash <script to run on stop>
doctype html
html
head
meta charset="UTF-8"
meta name="description" content=""
meta name="keywords" content=""
meta name="viewport" content="width=device-width, initial-scale=1.0"
title
= stylesheet_link_tag "application"
= javascript_include_tag "application"
= form_for @task, remote: true do |f|
- if @task.errors.any?
.errors
p Please correct the following errors:
ul
- @task.errors.full_messages.each do |message|
li = message
.field
= f.label :name
div id="resource_#{resource.id}"= resource.name
class ApplicationController < ActionController::Base
def remote_link
respond_to do |format|
format.js
end
end
end
@alistairtweed
alistairtweed / resources_controller.rb
Last active April 4, 2017 07:18
Resources Controller
class ResourcesController < ApplicationController
before_action :set_resource, only: [:show, :edit, :update, :destroy]
def index
@resources = Resource.all
end
def show
end