When brew punks out

26 March 2014 |

Today I was trying to upgrade all my brew kegs with brew upgrade. But it trips up on libiconv. You might try like I did and call brew with sudo but you get this message

Error: Cowardly refusing to `sudo brew upgrade`
You can use brew with sudo, but only if the brew executable is owned by root.
However, this is both not recommended and completely unsupported so do so at
your own risk.

Interesting, so now what? We could login as root but that might complicate things. What I did was give myself (a non-root user) access to the file. Like so

sudo su
chown <username> /usr/local/Cellar/libiconv/

Now that directory belongs to the current user and brew has no issues modifying that directory!

Using github pages environment variables

05 March 2014 |

This method is now outdated. Github Pages now exposes the site.github namespace

I use jekyll with github pages to build this blog. I also use disqus for comments. You just have to add a code snippet into the page. Problem is when developing with jekyll I usually like to test how things look locally and then push the site to github pages. Which means whenever I look at a blog post I haven't pushed, Disqus will create a thread like localhost:4000/something.html in addition to the intended one morenoh149.github.io/something.html. I asked around and found a jekyll plugin for environment variables. But github pages disables plugins. So I dug through the site variable on both production and github pages and found github pages sets GH_ENV which I haven't seen documented anywhere. Now I simply do

{% if site.GH_ENV == 'gh_pages' %}
  < disqus snippet >
{% endif %}

to get the disqus thread generated only if the post is being viewed on github pages.

Changing the owner of a heroku app with S3 assets

24 February 2014 |

I recently had to migrate a Heroku app that was under my personal accounts, Heroku and s3, to another user. But this app also had assets under Amazon Web Services Simple Storage Service which made the process more complicated. You can use something like bucket explorer to manage S3 with a gui. I'll show you how to do it with aws-cli. I'm assuming you installed it and you're familiar with the commandline in general.

Since we are using more than one aws account we should use a config file to store both sets of credentials. See AWS configuring environment. Place your personal credentials under default and make another set for the recipient.


  [profile client001]

Remember to clear your env variables if you were using them before. aws-cli defaults to using the env variables if present, even if you pass the --profile argument.

Now you should be able to do aws s3 ls and get your file listing. And aws s3 ls --profile client001 and get the client's files. If you are dealing with a small amount of data < 1TB we can simply copy the files to our local machine and then copy them back to the new bucket. For larger amounts I have no clue :(

  aws s3 cp s3://mybucket/ . --recursive

Note aws-cli cp command doesn't support matching by * so you have to use the --recursive flag. You can test what will happen if you run the command, with the --dryrun flag.

You can copy the files to the new bucket like so.

  aws s3 cp . s3://new-bucket --profile client001 --recursive

Note you may have to specifiy --region some-region for some reason specifying the region in my config file didn't work.

You have to set the heroku env variables to the new aws credentials using the heroku toolbelt

heroku config:set AWS_ACCESS_KEY_ID=new_blah
heroku config:set AWS_SECRET_ACCESS_KEY=new_blah
heroku config:set AWS_S3_BUCKET=new_blah

and just transfer it using heroku's system.

Bash script for creating a bootable usb stick on OS X

26 January 2014 |

Many times you have to create a bootable usb stick on a mac. I always follow the instructions at How to create a bootable USB stick on OS X. I created a quick bash script that makes this process faster

 1 #!/bin/bash
 2 HELP_STR="please provide location of .iso"
 3 if [ "$#" -lt 1 ]; then
 4   echo $HELP_STR
 5 else
 6   echo "`diskutil list`"
 7   echo "==============="
 8   echo "enter disk to eject"
 9   echo -e ">> \c"
10   read word
11   echo "ejecting: $word"
12   echo "`diskutil unmountDisk $word`"
13   echo "copying $1 to $word note this may take a while and there won't be a progress bar"
14   echo "`sudo dd if=$1 of=$word bs=1m`"
15 fi

Gist on Github

Getting started with emberjs and phonegap (work in progress)

30 December 2013 |

Source code for this project can be found here.

The ember app kit is currently the defacto starting point for any ember project.

You're going to have to learn a little grunt and bower. The getting started tutorial on the ember site is a good starting point. To add bootstrap, moment.js and showdown.js add them to the end of the dependencies section. Note, bower in the ember-app-kit installs to the vendor/ directory as opposed to the bower_components which is usually the default.

 1 {
 2   "name": "ember-app-kit",
 3   "dependencies": {
 4     "handlebars": "~1.1.2",
 5     "jquery": "~1.9.1",
 6     "qunit": "~1.12.0",
 7     "ember": "~1.3.0-beta.4",
 8     "ember-data": "~1.0.0-beta.4",
 9     "ember-resolver": "git://github.com/stefanpenner/ember-jj-abrams-resolver.git#master",
10     "ic-ajax": "~0.2",
11     "ember-testing-httpRespond": "~0.1.1",
12     "bootstrap": "~3",
13     "momentjs": "",
14     "showdown": ""
15   },
16   "resolutions": {
17     "ember": "~1.3.0-beta.4"
18   }
19 }

putting an "" empty string seems to work fine. Then reference these assets from index.html as normal.

The next deviation deals with how handlebars is setup. In the tutorial you see dale declaring <script type="text/x-handlebars"> and writing his handlebars stuff right there. With EAK the templating is put into the templates/ directory. With application.hbs wrapping the other templates.


 1 <div class="navbar navbar-default" role="navigation">
 2   <div class="navbar-header">
 3     <a class="navbar-brand" href="#">Bloggr</a>
 4   </div>
 5   <div class="collapse navbar-collapse">
 6     <ul class="nav navbar-nav">
 7       <li><a href="#">Posts</a></li>
 8       <li><a>About</a></li>
 9     </ul>
10   </div>
11 </div>
13 {{outlet}}

We then add the about resource to router.js

In the tutorial tom simply adds a posts var for our sample data fixture. In EAK there's a api-stub mechanism. Let's use that instead.

You'll need to read (and probably re-read) Using Modules & the Resolver

How to disable subtitles in VLC by default

18 September 2013 |

VLC is my media player of choice. One of my only complaints is that it loads subtitles by default. It'd be really nice if you could have them off by default, with the option of loading them if you need them.

This is how you do that. Go to Preferences > Show All (in the lower left corner) > Video > Subtitles/OCD Here you'll see some checkboxes. Uncheck Autodetect subtitle file.

And that's that. You can still load subtitles manually by going to Video > subtitles track > Open file... Navigate to your subtitles file and it'll be loaded.