Skip to content

Instantly share code, notes, and snippets.

View emmahsax's full-sized avatar

Emma Sax emmahsax

View GitHub Profile
@emmahsax
emmahsax / jekyll-feed-with-multiple-environments.md
Last active November 11, 2020 19:01
Jekyll Feed with multiple environments

Jekyll Feed with Multiple Environments

What this will do is generate a two different feeds:

  • A feed.xml for your local development, which will contain the values you specify for your development environment in your _config.yml.
  • A feed.xml for your live site, which will have the values set in your _config.yml for your production environment.

This is necessary because without different values for title, description, etc, many feed readers will view the two feeds as the same, even if the post content is different This makes it difficult to test if your feed is working and updating locally.

You could add additional environments as well, such as development, test, staging, and production.

@emmahsax
emmahsax / fixing-git-history.md
Last active November 11, 2020 19:11
A few files I've used in the past to fix Git history

Fixing Git History

There are two files that I tend to use to fix up some screwed up git history. None of these files should be used on huge repositories where a lot of people have forks and clones. Running any of these files completely rewrites history and will change the git SHA of all of the later commits.

I've used this first file when I've accidentally committed a bunch of past commits with the wrong email (think work vs. personal emails). To use it:

  1. Make a backup branch: git branch default_branch_backup
  2. Make sure you're back on the default branch: git checkout default_branch
  3. Run the script: email_switch.sh
  4. Wait patiently...
@emmahsax
emmahsax / switching-from-master-to-main.md
Last active November 24, 2020 21:37
A guide of how to switch from master to main branch in the terminal

Switching from master Branch to main Branch

From the terminal, run this:

git checkout master
git branch -m master main
git fetch
git branch --unset-upstream
git branch -u origin/main
@emmahsax
emmahsax / url-encode-a-string.md
Created December 3, 2020 23:59
Turn any string into a string fit for URLs

URL Encode a string

If you ever have a string that doesn't play nice with URLs, that's probably because it has spaces, or slashes, or anything like that. So, with this easy method, we can turn that string into a URL-friendly string!

def url_encode(str)
  str.b.gsub(/[^a-zA-Z0-9_\-.~]/n) { |m| format('%%%<val>02X', val: m.unpack1('C')) }
end

> url_encode('foo/bar')
@emmahsax
emmahsax / opening-external-links-in-new-tabs.md
Last active December 10, 2020 15:04
Opening external links in new tabs with Javascript
@emmahsax
emmahsax / installing-old-brew-formulas.md
Last active September 14, 2021 22:27
Instructions to install an outdated Homebrew formula

Installing Old Homebrew Formulas

Over the past several years, Homebrew has made it continually difficult to install an outdated formula. I'm not quite sure why, but it's been a struggle for developers for the past 7+ years.

However, there is a workaround (however it's not straight-forward). For this example, I'll use ruby-build:

  1. Note the version you currently have installed:
$ ruby-build --version
ruby-build 20210825
@emmahsax
emmahsax / github-pages-deploy-with-travis.md
Last active September 29, 2021 18:14
Example .travis.yml file to deploy to GitHub Pages

Example .travis.yml file to deploy to a GitHub Pages branch

os: linux
language: ruby
cache: bundler
install: bundle install

branches:
  only:
@emmahsax
emmahsax / blog-post-pagination-with-jekyll-paginate-v2.md
Last active December 8, 2021 21:30
Blog post pagination with jekyll-paginate-v2

Blog Post Pagination with jekyll-paginate-v2

This uses the pagination provided here. See the pagination in action at https://emmasax.com/blog/.

Let's start with the basics. Here's what the Jekyll _config.yml should look like:

title: An Awesome Blog
description: My blog, which is awesome
url: https://an-awesome-blog.com
@emmahsax
emmahsax / bootstrap-navbar.md
Last active July 5, 2022 04:07
Example of a simple navigation with Bootstrap 5

Navbar with Bootstrap 5

Here's the html file. This file assumes that there's two SVG icons (an X and a menu bar) downloaded in the /assets/images/icons directory:

<header class="sticky-top">
  <nav class="navbar navbar-expand-md navbar-dark py-0 py-md-0">
    <div class="container-fluid">
      <!-- Left hand side of navbar -->
      <a class="navbar-brand mb-0" href="/" target="_self">
@emmahsax
emmahsax / turn-utc-dates-to-local-timezone.md
Last active July 5, 2022 04:11
Turn UTC dates to local Timezone with Javascript

Turn UTC Dates to Local Timezone with Javascript

Here's the snippet of HTML that can be used to call this file:

<script src="/js/turn-utc-dates-to-local-timezone.js" type="text/javascript"></script>

And here's the JS file turn-utc-dates-to-local-timezone.js: