Half-Elf on Tech

Thoughts From a Professional Lesbian

Author: Ipstenu (Mika Epstein)

  • Deploying from Github via TravisCI

    Deploying from Github via TravisCI

    When you develop your code on Git, you can automagically (and easily) deploy to places all you want, if the repository is on the same server. If it's not, you can use something like Codeship to automate pushing for you.

    Free Services Have Limits

    Codeship, which I like a lot, has a limit of 100 pushes a month. In October, when Tracy and I finally deployed the newest version of our website, we actually hit that. In part, this is because we don't have a great 'test' environment where we can internally develop and share the results with the other. We both have our own versions of local environments, but you can't show your cohort 3000 miles away what you've done without pushing the code to the private development site and letting her see it.

    After 100 pushes, it's $490 a year for unlimited. While the product claims to be 'free forever' for open source, there's actually no documentation that I could find on how one gets added to that list, or what the qualifications are. Does my personal open source project  qualify? I'll have to email and find out.

    TravisCI Is ‘Free’

    All 'free' services have a paid component. Travis, like Codeship, is free for public, open source, projects. And like Codeship, it doesn't require you to host (and thus) update anything yourself. Which is nice. In fact, it only has a few pre-requsits:

    Sounds like a match made in heaven, except for the part about documentation on GitHub being out of date. I don't begrudge them, as keeping up docs is a pain and if it's with another service it's nigh impossible.

    Awesome. Sign up for Travis, activate your repositories, add a .travis.yml file with the programing language, and you're ready to do… what?

    Writing The Build Script

    This is the weird part. You have to invent a way to push the code. Unlike DeployHQ or Codeship, there's no place to type in the code on their servers. You have to make a file and write the script.

    The scripts look like this (cribbed from Florian Brinkkman):

    language: php
    
    addons:
      ssh_known_hosts:
      - $DEVELOPMENT_SERVER
      - $PRODUCTION_SERVER
    
    before_script:
      - echo -e "Host $DEVELOPMENT_SERVERntStrictHostKeyChecking non" >> ~/.ssh/config
      - echo -e "Host $PRODUCTION_SERVERntStrictHostKeyChecking non" >> ~/.ssh/config
    
    script:
      -
    before_deploy:
      - openssl aes-256-cbc -K $ENCRYPTED_KEY -iv $ENCRYPTED_IV -in deploy_rsa.enc -out /tmp/deploy_rsa -d
      - eval "$(ssh-agent -s)"
      - chmod 600 /tmp/deploy_rsa
      - ssh-add /tmp/deploy_rsa
    
    deploy:
      - provider: script
        skip_cleanup: true
        script: ssh -p22 $DEVELOPMENT_SERVER_USER@$DEVELOPMENT_SERVER "mkdir -p $DEVELOPMENT_PATH_STABLE" && ssh -p22 $DEVELOPMENT_SERVER_USER@$DEVELOPMENT_SERVER "mkdir -p $DEVELOPMENT_PATH_TRUNK" && rsync -rav -e ssh --exclude='.git/' --exclude=scripts/ --exclude='.travis.yml' --delete-excluded ./ $DEVELOPMENT_SERVER_USER@$DEVELOPMENT_SERVER:$DEVELOPMENT_PATH_TRUNK && rsync -rav -e ssh --exclude='.git/' --exclude=scripts/ --exclude='.travis.yml' --delete-excluded ./ $DEVELOPMENT_SERVER_USER@$DEVELOPMENT_SERVER:$DEVELOPMENT_PATH_STABLE
        on:
          branch: DEVELOPMENT
      - provider: script
        skip_cleanup: true
        script: ssh -p22 $PRODUCTION_SERVER_USER@$PRODUCTION_SERVER "mkdir -p $PRODUCTION_PATH_STABLE" && rsync -rav -e ssh --exclude='.git/' --exclude=scripts/ --exclude='.travis.yml' --delete-excluded ./  $PRODUCTION_SERVER_USER@$PRODUCTION_SERVER:$PRODUCTION_PATH_STABLE
        on:
          branch: master

    And to be honest, it's really not that explanatory. I read it a few times and sighed. While I'm (obviously) not opposed to learning new code to do things, I am opposed to all these services making it needlessly complicated.

    One Big Problem…

    You can't (easily) set up SSH keys on Travis for free. That's because they're restricted to the pro version. Now you totally can set it up, but it's incredibly insane and not something I was willing to do in the long term. And since the cost of TravisPro is $69 a month compared to Codeship's $49 or so a month, it was a no brainer.

    I emailed Codeship to ask if I qualified for 'open source.' Most likely they'll tell me no, because I deploy to a closed system, but it doesn't hurt to ask.

  • Indiegogo Embed

    Indiegogo Embed

    Indiegogo doesn't have oEmbed, which means you can't just paste in a URL and expect it to work on a WordPress site. And worse, their directions are "Use an iframe plugin!"

    NO.

    Just say NO to iframe plugins!

    Use a shortcode instead!

    If you're brand new to shortcodes, check out Sal Ferrarello's awesome post about it (I saw him talk at WC Philly 2017 and he's amazing). I'll give you the highlights for this one code though.

    The Code

    /*
     * Embed an IndieGoGo Campaign
     *
     * Usage: [indiegogo url="https://www.indiegogo.com/projects/riley-parra-season-2-lgbt"]
     *
     * Attributes:
     *		url: The URL of the project
     */
    add_shortcode( 'indigogo', 'helf_indiegogo' );
    function helf_indiegogo() {
    	$attr = shortcode_atts( array(
    		'url' => '',
    	), $atts );
    	
    	$url    = esc_url( $attr['url'] );
    	$url    = rtrim( $url, "#/");
    	$url    = str_replace( 'projects/', 'project/', $url );
    	$return =  '<iframe src="' . $url . '/embedded" width="222px" height="445px" frameborder="0" scrolling="no"></iframe>';
    
    	return $return;
    }
    

    What It Does

    The code is as basic as I could made it, and it takes the URL of the campaign, strips out the trailing hashtag, changes projects to project (singular – and yes, that gave me a headache), and punts out an iframe.

    Thankfully they make this easy unlike places like CrowdRise where you have to magically know the ID number in order to pull this off.

  • The Never-ending Progress Bar

    The Never-ending Progress Bar

    When you download a file from Safari, it shows you a progress bar for how it's going along. If you happen to download files to a folder in your dock, you'll see a line grow as it downloads, and then vanish.

    Except… sometimes it doesn't.

    A download bar that won't go away

    And then it gets worse if your bar changes size…

    A download bar that looks worse becuase it's not connected to the folder

    Well great. Now what?

    To the terminal!

    No really. It's one command:

    killall Dock

    That's it. It restarts the dock, the download bar goes away, and you can relax.

  • Github Introduces Archiving

    Github Introduces Archiving

    One of my laments has been that I can't (easily) flag a repository in Github as archived.

    https://twitter.com/ipstenu/status/926529534580555777

    As of today, you can!

    Github just announced the ability to archive repositories, and yes, it can be undone.

    To archive a repository, go to your Repository Settings Page, scroll down to the Danger Zone and click Archive this repository. It will pop up with a screen to warn you that this is a serious change, and while it can be undone, it will ask you to type in the repository slug to confirm.

    Once you've closed the repository, you'll see it has a new banner at the top, announcing "This repository has been archived by the owner. It is now read-only."

    This repository has been archived by the owner. It is now read-only.

    The repository will also have a little 'Archived" badge in the regular view.

    So. YAY!

  • Grunt Can’t Build Sass on High Sierra

    Grunt Can’t Build Sass on High Sierra

    Working on a site, I went to run my grunt command to compile sass, I got an error.

    Running "sass:dist" (sass) task
    /usr/local/Cellar/ruby/2.4.2_1/lib/ruby/2.4.0/rubygems.rb:271:in `find_spec_for_exe': can't find gem sass (>= 0.a) (Gem::GemNotFoundException)
        from /usr/local/Cellar/ruby/2.4.2_1/lib/ruby/2.4.0/rubygems.rb:299:in `activate_bin_path'
        from /usr/local/bin/sass:22:in `<main>'
    Warning: Exited with error code 1 Use --force to continue.

    No good, right? And googling around for that didn't help me at all until I drilled down and realized the sass error was a Ruby error.

    Upgrade Ruby

    First, install Homebrew. I know there are many other ways to handle installs on Macs, but Homebrew has been my go-to for a few years. It makes my life easier.

    Once Homebrew is installed run the following command: brew install rbenv ruby-build

    If this gives you an error, like missing xcrun, then run this: xcode-select --install

    Once you have rbenv installed, it's time to upgrade ruby:

    rbenv install 2.4.2
    rbenv global 2.4.2

    Awesome! But grunt still doesn't work. And this is because Sass isn't installed.

    Install Sass

    This should be easy, right? sudo gem install -n /usr/local/bin sass and off you go. The problem is you may get this error:

    ERROR:  While executing gem ... (TypeError)
        no implicit conversion of nil into String

    Not so helpful. The magic here is going backwards to go forward. Update your gems first: sudo gem update --system and then run the installer for sass.

    Why Did This Happen?

    The short answer is that Mac changed versions and everything got out of sync. I'm not a system code expert so I can't explain it better than that.

    How you fix these things is by understanding how to logically step backwards through the errors. Most of the time, we see it as "Grunt says Sass is broken!" and the trick here is to ask yourself "What runs Sass?" and the answer is "Ruby." So instead of looking up "Why can't I run sass on grunt?" we look up "Ruby can't compile SCSS on Mac High Sierra" because that's the ultimate answer.

    Walking backwards is the secret sauce for all solutions with software, I feel. Why can't Grunt run Sass? Because Ruby can't compile? Why can't Ruby compile SCSS? Let's reinstall Sass! Oh wait, that has an error. Okay, let's upgrade Ruby. Oh that has an error too? Let's solve that.

    It's not fun, unless you're me and think snarling at a laptop in the conference room of your friends' office is cheerful.

  • PHP Spaceship

    PHP Spaceship

    It’s no Jefferson Starship, but in PHP 7 there’s an awesome new comparison operator called ‘Spaceship.’

    Dragon Fly

    Operators are those things we use to tell PHP what ‘operations’ to perform on variables and values. Comparison operators are used to compare two values (like a number or string). And Spaceship — <=> — is a cool new one.

    It’s a combined comparison operator and returns:

    • 0 if values on either side are equal
    • 1 if value on the left is greater
    • -1 if the value on the right is greater

    Red Octopus

    So why would anyone use it?

    Let’s say you have an array of characters with lists of when they died. But the characters are ordered alphabetically. Sara Lance comes after Lexa, even though Sara died first. And let’s say you want to take the list of all the characters who died and put them in the order of death, not their names.

    To do this in PHP, you would use usort or uasort to ‘user sort’ the array. The A in the sort is if you have an associative array, and you want to keep ‘name’ and ‘date of death’ connected when you sort. Which you do.

    Spitfire

    In PHP 5, the sort would look like this:

    uasort( $death_list_array, function($a, $b) {
    	$return = '0';
    	if ( $a['died'] &lt; $b['died'] ) $return = '-1';
    	if ( $a['died'] &gt; $b['died'] ) $return = '1';
    	return $return;
    }
    

    Which isn’t bad, but it’s messy right?

    Earth

    In PHP 7, the sort would look like this:

    uasort( $death_list_array, function($a, $b) {
    	$return = $a['died'] &lt;=&gt; $b['died'];
    	return $return;
    }
    

    Way nicer, and faster, isn’t it?

    Freedom at Point Zero

    Why not use it all the time? Because it’s PHP 7+ only, and for some reason not all servers have PHP 7 as the command line version of PHP. Which means if you use it, sometimes wp-cli commands don’t run.

    However. If you have PHP 7 all across the board, then use the starship and save yourself some flying time.