Jekyll2023-01-25T20:40:21+00:00/feed.xmlDylan WilburSetting Up A New Macbook2020-06-10T00:00:00+00:002020-06-10T00:00:00+00:00/2020/06/10/setting-up-new-mac<h1 id="my-essentials-for-a-new-laptop">My Essentials For A New Laptop</h1>
<p><img src="/assets/images/showcase.gif" alt="" />
<strong>What you’re seeing here</strong>:</p>
<ul>
<li>Music window(vaporwave artist called 2814 check it out) is “floating”: not affected by tiling window manager</li>
<li>Enter a command <code class="language-plaintext highlighter-rouge">tw</code> with Alfred to create a new window of iTerm2</li>
<li>Enter a command <code class="language-plaintext highlighter-rouge">ns</code> with Alfred to create a new window of Safari</li>
<li>Open up my vim configuration</li>
<li>Use Contexts with Command+Tab to switch to the music window</li>
<li>“Unfloat” the window</li>
<li>Use a key command to temporarily fullscreen the safari window</li>
</ul>
<p>I’m going to organize this list in “tier list” format. Stuff I use every day and I think is absolutely essential will be near the top, while more niche things will gather near the bottom.</p>
<p>I’ll likely be continuously updating these posts as I use the laptop more and more. I’ve just been adding stuff as I go along to try and mimic my old laptop, but hopefully cut down on some of the bloat that I don’t need.</p>
<h2 id="tier-one-absolute-essentials">Tier One: Absolute Essentials</h2>
<h3 id="iterm2">iTerm2</h3>
<h5 id="used-for-everything">Used For: Everything</h5>
<p><img src="/assets/images/iterm.png" alt="image-left" class="align-left" /> First thing to do on a new mac: install iTerm2. Way better than the default terminal, and I use a terminal for almost everything so this suits my needs perfectly.</p>
<p><strong>Theming</strong>: I use the <a href="https://github.com/nathanbuchar/atom-one-dark-terminal">OneDark</a> theme for iterm, but you can find many more <a href="https://iterm2colorschemes.com">here</a></p>
<p><strong>Dropdown Terminal</strong>: In iTerm preferences, create a new profile called Dropdown. Then go to the keys section and select “A hotkey opens….”. I have my hotkey as <code class="language-plaintext highlighter-rouge">CMD+CTRL Space</code> which is super fast to hit because I remapped my Caps Lock key.</p>
<h3 id="homebrew">Homebrew</h3>
<h5 id="used-for-installing-everything">Used For: Installing everything</h5>
<p>Second thing to do on a new mac: install homebrew. Just paste this into iTerm:</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>xcode-select <span class="nt">--install</span>
/bin/bash <span class="nt">-c</span> <span class="s2">"</span><span class="si">$(</span>curl <span class="nt">-fsSL</span> https://raw.githubusercontent.com/Homebrew/install/master/install.sh<span class="si">)</span><span class="s2">"</span>
</code></pre></div></div>
<p>If you ever need to install an application, odds are you can do it from the command line with homebrew which is my preferred method. For instance, to install Firefox:
<code class="language-plaintext highlighter-rouge">brew cask install firefox</code>
The <code class="language-plaintext highlighter-rouge">cask</code> part is typically used for stuff that isn’t a CLI. For CLI stuff, you would just use brew install, like for installing python 3:
<code class="language-plaintext highlighter-rouge">brew install python3</code></p>
<h3 id="oh-my-zsh">Oh My Zsh</h3>
<p>Allows me to trick out my terminal window. The github is <a href="">here</a> and it’ll give more info but you can install it by running this on the terminal:
<code class="language-plaintext highlighter-rouge">sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"</code></p>
<p>I personally use the <a href="https://github.com/pascaldevink/spaceship-zsh-theme"> Spaceship prompt </a></p>
<h3 id="alfred">Alfred</h3>
<h5 id="used-for-launching-apps-and-scriptable-commands">Used For: Launching Apps and scriptable commands</h5>
<p>You can download it with homebrew:
<code class="language-plaintext highlighter-rouge">brew cask install Alfred</code></p>
<p>Costs like 15 bucks but it’s worth it</p>
<h3 id="yabai">Yabai</h3>
<h5 id="used-for-tiling-window-manager">Used For: Tiling Window Manager</h5>
<p>This is highly keyboard based and requires some configuration. If you want a different window manager look up Magnets.
<code class="language-plaintext highlighter-rouge">brew cask install yabai</code>
Check out my dotfiles for this and skhd <a href="https://github.com/dylanwilbur/my-dotfiles">here</a>.</p>
<h3 id="karabiner-elements">Karabiner Elements</h3>
<h5 id="used-for-remapping-caps-lock-to-be-more-useful">Used For: Remapping Caps Lock to be more useful</h5>
<p><img src="/assets/images/karabiner.png" alt="image-left" class="align-left" /> One of those apps I just completely couldn’t live without, and it doesn’t even do very much for me. There’s a ton of stuff you can do with this, but I only use two complex modifications:</p>
<ul>
<li>Change caps_lock to control if pressed with other keys, escape if pressed alone</li>
<li>Change right_command+hjkl to arrow keys</li>
</ul>
<p>The first one I use almost every five minutes, and it’s one of those things where I feel lost if I don’t have it. It’s especially useful for vim since the escape key and control keys are used all the time but are in really unnatural spots</p>
<p><strong>Note</strong>: This one didn’t work with a brew cask install because there were some preferences in system preferences that weren’t showing up. So it’s easier to just download straight off the website.</p>
<h3 id="contexts">Contexts</h3>
<h5 id="used-for-commandtab-app-switching-windows-style">Used For: Command+Tab App switching, Windows style</h5>
<h5 id="price-10">Price: $10</h5>
<p>One thing windows does right is their ctrl+tab app switcher. On MacOS, by default you can only switch between different apps, not specific windows. So if you have, say, 2 iTerm windows open, you’re out of luck if you want to command tab to one of them in particular. It was writing this that made me go and redownload this app because the default was so annoying.</p>
<p>Dark Mode, of course.</p>
<h2 id="clis">CLI’s</h2>
<h4 id="vimneovim">Vim(Neovim)</h4>
<h5 id="writing-with-vim">Writing with Vim</h5>
<p>Writing with vim is cool, especially spell check.
<img src="/assets/images/vimwriting.gif" alt="" /></p>
<p>Note:</p>
<ul>
<li>the tiling window manager</li>
<li>the awesome writing vim theme</li>
<li>using Ctrl-F while typing to immediately correct the last spell check</li>
<li>using the alfred command <code class="language-plaintext highlighter-rouge">ns</code> to create a new safari tab</li>
</ul>
<p>Check out my dotfiles <a href="https://github.com/dylanwilbur/my-dotfiles">here</a>.</p>
<h4 id="ruby-related-stuff">Ruby Related Stuff</h4>
<p>I used <a href="https://jekyllrb.com/docs/installation/macos/">this</a> guide on Jekyll’s website. You end up with rbenv and ruby installed.
You might need to run
<code class="language-plaintext highlighter-rouge">export GEM_HOME="$HOME/.gem"</code>
to get some of the commands working with the gems. I added this to my <code class="language-plaintext highlighter-rouge">.zshrc</code> to make it permanent.</p>
<h4 id="vim-browser-plugin">Vim Browser Plugin</h4>
<p>Hard to stop that keyboard-based stint once you hop on that vim train. Obviously one would think to port vim functionality over to the browser, and it actually tends to work quite well. I’ve tried qutebrowser, not worth it for me but worth a try. I use safari so unfortunately my beloved <a href="https://github.com/flippidippi/sVim">sVim</a> broke with the introduction of Mojave. If you use Chrome or Firefox I would recommend using one of their vim extensions, really speeds things up.</p>My Essentials For A New Laptop What you’re seeing here: Music window(vaporwave artist called 2814 check it out) is “floating”: not affected by tiling window manager Enter a command tw with Alfred to create a new window of iTerm2 Enter a command ns with Alfred to create a new window of Safari Open up my vim configuration Use Contexts with Command+Tab to switch to the music window “Unfloat” the window Use a key command to temporarily fullscreen the safari windowHow To Make a Rails Model Into A Downloadable Spreadsheet2019-09-13T00:00:00+00:002019-09-13T00:00:00+00:00/rails-notes/2019/09/13/downloadable-spreadsheet-in-rails<p>This might be useful to do if the data needs to be transported for any reason. The file can be accessed from anywhere after doing this with a <code class="language-plaintext highlighter-rouge">courses_path</code> request.</p>
<h2 id="steps">Steps</h2>
<ol>
<li>
<p><strong>Add download links</strong></p>
<p>In <code class="language-plaintext highlighter-rouge">index.html.erb</code> (or wherever you want the buttons to go)</p>
<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="o"><</span><span class="n">h4</span><span class="o">></span><span class="no">Download</span><span class="ss">:<</span><span class="o">/</span><span class="n">h4</span><span class="o">></span>
<span class="o"><</span><span class="sx">%= link_to "CSV", courses_path(format: "csv"), class: "btn btn-primary"%>
<%=</span> <span class="n">link_to</span> <span class="s2">"Excel"</span><span class="p">,</span> <span class="n">courses_path</span><span class="p">(</span><span class="ss">format: </span><span class="s2">"xls"</span><span class="p">),</span> <span class="ss">class: </span><span class="s2">"btn btn-primary"</span><span class="o">%></span>
</code></pre></div> </div>
</li>
<li>
<p><strong>Change the index controller action to accommodate serving different file types</strong></p>
<p>In <code class="language-plaintext highlighter-rouge">model_controller.rb</code></p>
<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">respond_to</span> <span class="k">do</span> <span class="o">|</span><span class="nb">format</span><span class="o">|</span>
<span class="nb">format</span><span class="p">.</span><span class="nf">html</span>
<span class="nb">format</span><span class="p">.</span><span class="nf">csv</span> <span class="p">{</span> <span class="n">send_data</span> <span class="vi">@models</span><span class="p">.</span><span class="nf">to_csv</span> <span class="p">}</span>
<span class="nb">format</span><span class="p">.</span><span class="nf">xls</span>
<span class="k">end</span>
</code></pre></div> </div>
</li>
<li>
<p><strong>Add a <code class="language-plaintext highlighter-rouge">to_csv</code> method to the model’s class</strong></p>
<p>In <code class="language-plaintext highlighter-rouge">model.rb</code></p>
<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">def</span> <span class="nc">self</span><span class="o">.</span><span class="nf">to_csv</span><span class="p">(</span><span class="n">options</span> <span class="o">=</span> <span class="p">{})</span>
<span class="no">CSV</span><span class="p">.</span><span class="nf">generate</span><span class="p">(</span><span class="n">options</span><span class="p">)</span> <span class="k">do</span> <span class="o">|</span><span class="n">csv</span><span class="o">|</span>
<span class="n">csv</span> <span class="o"><<</span> <span class="n">column_names</span>
<span class="n">all</span><span class="p">.</span><span class="nf">each</span> <span class="k">do</span> <span class="o">|</span><span class="n">model</span><span class="o">|</span>
<span class="n">csv</span> <span class="o"><<</span> <span class="n">model</span><span class="p">.</span><span class="nf">attributes</span><span class="p">.</span><span class="nf">values</span>
<span class="k">end</span>
<span class="k">end</span>
<span class="k">end</span>
</code></pre></div> </div>
</li>
<li>
<p><strong>Add xls to mime types</strong></p>
<p>In <code class="language-plaintext highlighter-rouge">config/initializers/mime_types.rb</code></p>
<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="no">Mime</span><span class="o">::</span><span class="no">Type</span><span class="p">.</span><span class="nf">register</span> <span class="s2">"application/xls"</span><span class="p">,</span> <span class="ss">:xls</span>
</code></pre></div> </div>
</li>
<li>
<p><strong>Require csv in the model class</strong></p>
<p>In <code class="language-plaintext highlighter-rouge">model.rb</code></p>
<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">require</span> <span class="s1">'csv'</span>
</code></pre></div> </div>
</li>
<li>
<p><strong>Add an xls format file to serve</strong></p>
<p>In <code class="language-plaintext highlighter-rouge">index.xls.erb</code>
(fill in erb code specific to model)</p>
<div class="language-xml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="cp"><?xml version="1.0"?></span>
<span class="nt"><Workbook</span> <span class="na">xmlns=</span><span class="s">"urn:schemas-microsoft-com:office:spreadsheet"</span>
<span class="na">xmlns:o=</span><span class="s">"urn:schemas-microsoft-com:office:office"</span>
<span class="na">xmlns:x=</span><span class="s">"urn:schemas-microsoft-com:office:excel"</span>
<span class="na">xmlns:ss=</span><span class="s">"urn:schemas-microsoft-com:office:spreadsheet"</span>
<span class="na">xmlns:html=</span><span class="s">"http://www.w3.org/TR/REC-html40"</span><span class="nt">></span>
<span class="nt"><Worksheet</span> <span class="na">ss:Name=</span><span class="s">"Sheet1"</span><span class="nt">></span>
<span class="nt"><Table></span>
<span class="nt"><Row></span>
<span class="nt"><Cell><Data</span> <span class="na">ss:Type=</span><span class="s">"String"</span><span class="nt">></span>ID<span class="nt"></Data></Cell></span>
<span class="nt"><Cell><Data</span> <span class="na">ss:Type=</span><span class="s">"String"</span><span class="nt">></span>Course Title<span class="nt"></Data></Cell></span>
<span class="nt"><Cell><Data</span> <span class="na">ss:Type=</span><span class="s">"String"</span><span class="nt">></span>Fee(in $)<span class="nt"></Data></Cell></span>
<span class="nt"><Cell><Data</span> <span class="na">ss:Type=</span><span class="s">"String"</span><span class="nt">></span>Created at<span class="nt"></Data></Cell></span>
<span class="nt"></Row></span>
<span class="err"><</span>% @courses.each do |course| %>
<span class="nt"><Row></span>
<span class="nt"><Cell><Data</span> <span class="na">ss:Type=</span><span class="s">"Number"</span><span class="nt">></span><span class="err"><</span>%= course.id %><span class="nt"></Data></Cell></span>
<span class="nt"><Cell><Data</span> <span class="na">ss:Type=</span><span class="s">"String"</span><span class="nt">></span><span class="err"><</span>%= product.name %><span class="nt"></Data></Cell></span>
<span class="nt"><Cell><Data</span> <span class="na">ss:Type=</span><span class="s">"Number"</span><span class="nt">></span><span class="err"><</span>%= product.fee %><span class="nt"></Data></Cell></span>
<span class="nt"><Cell><Data</span> <span class="na">ss:Type=</span><span class="s">"String"</span><span class="nt">></span><span class="err"><</span>%= product.created_at.to_s("%B %d, %Y") %><span class="nt"></Data></Cell></span>
<span class="nt"></Row></span>
<span class="err"><</span>% end %>
<span class="nt"></Table></span>
<span class="nt"></Worksheet></span>
<span class="nt"></Workbook></span>
</code></pre></div> </div>
</li>
</ol>This might be useful to do if the data needs to be transported for any reason. The file can be accessed from anywhere after doing this with a courses_path request.Rails Tutorial Book Chapter 1 Notes2019-06-26T00:00:00+00:002019-06-26T00:00:00+00:00/rails-notes/2019/06/26/rails-tutorial-notes-chapter-1<p>Chapter 1 is one of the chapters I come back to most often. I usually don’t remember how to do specific “set-up” type tasks, which this chapter addresses.</p>
<h4 id="about-development-environments">About Development Environments</h4>
<p>The book discusses a topic called “development environments” - essentially just the way a computer needs to be set up to start making an app in rails. The book plugs their affiliate “web IDE” called Cloud9, warning readers against setting up their own environment locally. I personally used Cloud9 for about a year before switching to my own local environment to have greater control over my text editing and console configurations, but Cloud9 is a perfectly viable option for most people.</p>
<h4 id="command-line">Command Line</h4>
<p>The book then shifts into a quick mini-lesson about the command line. This is also something important to pick up on, and something which I use every day. This stuff will come up time and time again, so it’s best to get used to it as early as possible.</p>
<h4 id="initializing-a-new-app">Initializing a New App</h4>
<p>The book goes into detail about what is happening when creating a new app, and how to do it, but I mainly come back to this section when I forget how to do it. Commands are executed in the command line to create an app, along with editing some files to get your “hello world”. To boil it down, the steps are:</p>
<ol>
<li><strong>*Create app from command line</strong>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span><span class="nb">cd</span> ~/environment <span class="c"># get to the right directory</span>
<span class="nv">$ </span>rails _5.1.6_ new hello_app <span class="c"># where _5.1.6_ = version, hello_app = name</span>
</code></pre></div> </div>
</li>
<li>Create an action in the controller(<code class="language-plaintext highlighter-rouge">app/controllers/application_controller</code>)
```ruby
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception</li>
</ol>
<p>def hello
render html: “hello, world!”
end
end</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
3. Change the routing(`config/routes.rb`)
```ruby
Rails.application.routes.draw do
root 'application#hello'
end
</code></pre></div></div>
<h4 id="git">Git</h4>
<h6 id="note-on-githubbitbucket">Note on Github/Bitbucket</h6>
<p>This book uses bitbucket as a hosting service for git repositories, which is functionally parallel to Github, which you are more likely to have heard of before. Their justification is that Bitbucket offers unlimited private repositories, and Github does not; however, Github has updated their site to allow infinite private repositories as well. Because of this, I would recommend using Github as it is a larger platform for developers.</p>
<h6 id="git-1">Git</h6>
<p>The <a href="https://www.railstutorial.org/book/beginning#sec-version_control">git tutorial in this section</a> is actually extremely useful as an introduction to git, so its certainly worth a read. This book also assumes command line git(which I prefer), as opposed to the desktop app However, I’ll boil it down to the steps I come back to:</p>
<ol>
<li>Set up config(<strong>only need to do once</strong>)
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span>git config <span class="nt">--global</span> user.name <span class="s2">"Your Name"</span>
<span class="nv">$ </span>git config <span class="nt">--global</span> user.email your.email@example.com
</code></pre></div> </div>
</li>
<li>Initialize repository
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># Make sure your current working directory is the location of your app.</span>
<span class="c"># Otherwise, use $ cd ~/path/to/your/app/</span>
<span class="nv">$ </span>git init
<span class="nv">$ </span>git add <span class="nt">-A</span>
<span class="nv">$ </span>git commit <span class="nt">-m</span> <span class="s2">"initialize repository"</span>
</code></pre></div> </div>
</li>
<li>Create new repository on github
<ul>
<li>click the plus button on top right</li>
</ul>
</li>
<li>
<p>Copy the URL(should end in .git)</p>
</li>
<li>Tell git to push to your repository
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span>git remote add origin YOUR_URL
<span class="nv">$ </span>git push <span class="nt">-u</span> origin master
</code></pre></div> </div>
</li>
</ol>
<h4 id="heroku">Heroku</h4>
<p>Heroku is a great way to put whatever app you are building onto the actual internet. If this is your first time doing this, I would recommend walking through the steps outlined in the book <a href="https://www.railstutorial.org/book/beginning#sec-deploying">here</a>. Otherwise, the steps I will put here are for creating another app after already having created one.</p>
<ol>
<li>Modify Gemfile
<ul>
<li>add the following to Gemfile
<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">group</span> <span class="ss">:production</span> <span class="k">do</span>
<span class="n">gem</span> <span class="s1">'pg'</span><span class="p">,</span> <span class="s1">'0.20.0'</span>
<span class="k">end</span>
</code></pre></div> </div>
</li>
</ul>
</li>
</ol>
<ul>
<li>remove <code class="language-plaintext highlighter-rouge">gem 'sqlite3'</code> from the top of the file, put into the test/development group
<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">group</span> <span class="ss">:development</span><span class="p">,</span> <span class="ss">:test</span> <span class="k">do</span>
<span class="n">gem</span> <span class="s1">'sqlite3'</span>
<span class="k">end</span>
</code></pre></div> </div>
<ol>
<li>Save and commit changes
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span>bundle <span class="nb">install</span> <span class="nt">--without</span> production
<span class="nv">$ </span>git commit <span class="nt">-am</span> <span class="s2">"update gemfile"</span>
</code></pre></div> </div>
</li>
</ol>
</li>
</ul>
<ol>
<li>Initialize heroku app
<ul>
<li>ensure that your current directory is the same as your rails app
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span>heroku create
</code></pre></div> </div>
</li>
</ul>
</li>
<li>Deploy the application
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span>git push <span class="nt">-u</span> heroku master
</code></pre></div> </div>
<p><em>note</em>: try running <code class="language-plaintext highlighter-rouge">$ heroku buildpacks:set https://github.com/bundler/heroku-buildpack-bundler2</code> if this step fails</p>
</li>
</ol>
<h4 id="lockup">Lockup</h4>
<p>This isn’t in the book, but I believe this is important if you are building an app for a customer. The <a href="https://github.com/gblakeman/lockup">Lockup Gem</a> is a gem you can add to your rails app which secures your app behind a passcode, but only requires each user to do so once per machine. This ensures that no one should have access to your app unless they are supposed to, even when hosted online.</p>
<p>Follow the steps <a href="https://github.com/gblakeman/lockup#installation">here</a>.
Make sure that your place <code class="language-plaintext highlighter-rouge">gem 'lockup'</code> within the production group, like so:</p>
<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">group</span> <span class="ss">:production</span> <span class="k">do</span>
<span class="n">gem</span> <span class="s1">'lockup'</span>
<span class="k">end</span>
</code></pre></div></div>
<p>Also, I have found more success placing <code class="language-plaintext highlighter-rouge">ENV["LOCKUP_CODEWORD"] = 'secret'</code> within <code class="language-plaintext highlighter-rouge">config/environments/production.rb</code> than any other option.</p>
<p>You may also need to run <code class="language-plaintext highlighter-rouge">$ bundle install --with production</code></p>Chapter 1 is one of the chapters I come back to most often. I usually don’t remember how to do specific “set-up” type tasks, which this chapter addresses.