Friedrich Ewald My Personal Website

Posts


  • Testing email sending

    I recently came across MailHog. I needed to test some email functionality locally. MailHog creates an SMTP that accepts any email to any address and shows this in web interface.

  • Heroku Price increase

    Heroku will increase prices and remove many free tiers.

  • Change font size depending on post length

    One of the things that I like about Twitter is that the font size changes depending on the length of the tweet. Yesterday, I tried to achieve the same thing for this Jekyll based blog and came up with the following solution. First, I created a plugin (in the folder _plugins) and registered it as Liquid filter with the following code:

    module Jekyll
      module PostFilter
        def post_class(input)
          # Catch invalid posts
          return 'default' if input.nil?
          
          if input.size < 32
            return 'large'
          elsif input.size < 64
            return 'medium'
          else
            return 'default'
          end
        end
      end
    end
    
    Liquid::Template.register_filter(Jekyll::PostFilter)
    As a next step I changed the post.html template to this:
    <p itemprop="articleBody" class="{{content | post_class }}">
      {{ content | remove: "<p>" | remove: "</p>" }}
    </p>
    It is important to remove the <p> tags because they cannot be nested in valid HTML and Jekyll adds their own tags to post content. Finally, I created some SCSS to change the font-size based on the CSS class.
    /* Post pages */
    div.post {
        p.default {
            font-size: 1em;
        }
        p.medium {
            font-size: 1.6em;
        }
        p.large {
            font-size: 1.8em;
        }
    }

  • Leetcode: House robber II

    Similar to “House Robber”, but now we have to assume that the houses are aligned in a circle and the last house is a neighbor of the first house.

    Continue reading

  • Leetcode: House robber

    Given an array of nums that represent the loot of a house robber, return the maximum amount of money a robber can steal. The only rule is that a robber can not steal from two neighboring houses. When looking at this problem, we can see that we want to maximize the number of houses that we rob from. Consider the following array: [0,1,0,1]. Our maximum profit is 2, because we can rob the house at index 1 and index 3. If we were to rob at index 0 and 2, we would only gain 0 profit. We cannot however simply compare the even versus the odd indices because there could also be the following situation: [10,5,5,10]. Here, it is advantageous to skip 2 instead of just skipping 1. We need to look at every step if we want to visit the one after the next or the one after this. We don’t need to look if we want to visit the one after this, because then we could also simply have visited the one after the next.

    Continue reading

Previous Page: 1 of 26