๐ a linked post to
jvns.ca »
—
originally shared here on
I make a lot of small simple websites, I have approximately 0 maintenance energy for any of them, and I change them very infrequently.
My goal is that if I have a site that I made 3 or 5 years ago, Iโd like to be able to, in 20 minutes:
get the source from github on a new computer
make some changes
put it on the internet
But my experience with build systems (not just Javascript build systems!), is that if you have a 5-year-old site, often itโs a huge pain to get the site built again.
I have websites that I made in middle school that Iโm able to get up and running in roughly as much time as it takes to find the old folders.
I also have websites that I am unable to run on my new laptop because the dependencies are too out of date and now supported on my new architecture.
RailsConf 2019 - Opening Keynote by David Heinemeier Hansson
๐ a linked post to
youtube.com »
—
originally shared here on
I've never heard any of DHH's RailsConf keynote speeches before, so I guess I kind of expected it to be more about the state of Rails and where things are going.
In a way, I suppose this is that. But really, it's a personal manifesto about the intrinsic value of software, human worth, and capitalism.
How to detect and replace YouTube links by extending the Redcarpet gem
originally shared here on
As I'll explain in a future post, I had an old Wordpress blog that I got sick of maintaining and updating, so I did what any red-blooded developer would do: build my own blog engine.
In doing so, however, I needed to import all my old posts from Wordpress over to my own Rails form. This worked nearly flawlessly, with the exception of my YouTube videos, which looked something like this (without the space inside the tag):
[youtube]nFZZxOHHZlo[/youtube ]
Because I am using the Redcarpet gem, I thought I'd extend its parsing capabilities to detect anything like this and wrap it in a responsive frame.
Here's how I did it (with extreme thanks to this SO post):
Step 1: Create a folder called app/services, and then create a file called custom_markdown.rb:
class CustomMarkdown < Redcarpet::Render::HTML
def preprocess(text)
format_youtube(text)
end
def format_youtube(text)
text.gsub! /\[youtube](.*?)\[\/youtube]/ do
"<div class='embed-container'><iframe src='https://www.youtube.com/embed/#{$1}' frameborder='0' allowfullscreen></iframe></div>"
end
text
end
end
This code will perform a regular expression to find anything wrapped in [youtube] tags and replace it with a <div> that we can now style with CSS.
Step 2: Add the following SCSS somewhere in your project where it makes sense:
Step 3: Use the custom parser when including Redcarpet in your project:
require './app/services/custom_markdown.rb' # This was necessary for me, might not be necessary for you
@blogs = Blog.all.order("published_at desc")
renderer = CustomMarkdown.new()
@markdown = Redcarpet::Markdown.new(renderer, extensions = {})
Now, anywhere you use those [youtube] tags, you'll get this fancy rendering instead:
Saving images locally using the Paperclip gem on Linux
originally shared here on
Like most red-blooded Ruby on Rails developers, I make copious use of the Paperclip gem.
Paperclip (and basically, every developer on the internet) seems to encourage you to use a service like Amazon S3 or some other 3rd party service to store your files.
However, I find that for simple projects, I'm just fine storing the images locally on my Linux server and using good ol' Apache to serve them up.
By default, Paperclip saves these images in your public/system folder, and assigns the same permissions as your Rails app to those images.
The problem I run into is that frequently, it doesn't use the right permissions. I'd be able to upload and save the image, but when I'd load the image, I'd get a 403 error.
In order to solve that issue, you need to set the correct permissions for your public/system/[model] directory.
Here's how to quickly solve that:
1) SSH into your public/system/[model] directory
2) Run "umask 002". This will allow your Linux group to write into this directory.
3) Run "chgrp [your-systems-group] .". In my case, that's www-data. This will change the ownership of the folder to your group.
Now, all the files in your folders (and all subsequently created files) will belong to the correct group, and you won't see any more nasty 403 errors!