Skip to content

Instantly share code, notes, and snippets.

View scmx's full-sized avatar

Albert Arvidsson scmx

View GitHub Profile
@scmx
scmx / removing-duplicate-records-rails4.rb
Last active July 5, 2017 20:10
Removing duplicate records Rails 4 #rails4, #uniqueness, #accepts_nested_attributes_for
# Related article
# http://robots.thoughtbot.com/accepts-nested-attributes-for-with-has-many-through
# Pluck ids
arr = CompanyEmployment.pluck(:company_id, :company_user_id)
#=> [[1,1], [1,2], [2,1], [2,1]]
# Select duplicates http://stackoverflow.com/a/8922408/2037928
dups = arr.select {|e| arr.rindex(e) != arr.index(e) }.uniq
#=> [[2,1]]
@scmx
scmx / killall-comtrol-strip.md
Last active July 13, 2017 20:29
How to fix a frozen MacBook Pro TouchBar (killall ControlStrip)

How to fix a frozen MacBook Pro TouchBar

tl;dr killall ControlStrip

After having used a MacBook Pro with a TouchBar for a few months, I've experienced a few times that the TouchBar can sometimes hang up so that none of the buttons work. I don't really use it that much, so I can just continue working, but it's annoying to not be able to change screen brightness etc.

The last few times I've just resorted to rebooting my computer after failing to google how to restart only the touchbar.

But today it was easier too google it. Cnet has an article that mentions various ways to fix it. For me it was enough to restart the ControlStrip, the rightmost part of the TouchBar.

@scmx
scmx / ctrl-to-stay-on-homerow.md
Last active September 26, 2017 09:12
Using <Ctrl> to stay on the home row in your terminal and vim #terminal #vim #osx #unix

Here are some tricks you can use to be able to stay on the home row (asdfghjkl etc) when you're in a terminal or in vim.

Terminal

  • <Ctrl>+l Clear the terminal
  • <Ctrl>+a go to beginning of line
  • <Ctrl>+e go to end of line
  • <Ctrl>+p instead of <Up>, to see previous command
  • <Ctrl>+n instead of <Down>, to see next command
  • <Ctrl>+k + <Ctrl>+u Cut current command
  • +y Paste command
@scmx
scmx / .thymerc
Last active December 1, 2017 09:21
thyme pomodoro configured to change skype status and say -v albert "pomodoro"
#!/usr/bin/env ruby
set :tmux, true
before do
%x(~/bin/set-skype-status DND)
%x(say -v albert 'pomodoro started')
end
after do
@scmx
scmx / keybase.md
Last active January 29, 2018 07:23
keybase.md

Keybase proof

I hereby claim:

  • I am scmx on github.
  • I am albertarv (https://keybase.io/albertarv) on keybase.
  • I have a public key ASDpTXwwbwneSxsaoy4j2gb7eo0GyQI_3UGCJrYCIqx7Igo

To claim this, I am signing this object:

@scmx
scmx / screenshot-with-touchbar.md
Last active May 9, 2018 06:09
Mac OS Screenshot with TouchBar #macos #screenshot #touchbar #imagemagick #convert #append #resize

Mac OS Screenshot with TouchBar

Many know that there are some keyboard bindings on Mac OS for taking screen shots

  • <Cmd> + <Shift> + 3 Full screenshot
  • <Cmd> + <Shift> + 4 Choose rectangle of what to screenshot
  • <Cmd> + <Shift> + 4 + <Space> Choose an app to screenshot

But for those with a Macbook Pro with a Touch Bar there is also

  • <Cmd> + <Shift> + 6 Screenshot of TouchBar
@scmx
scmx / bash-prompt-git.md
Created May 9, 2018 12:32
Bash prompt with Git and autocompletion #bash #prompt #git #complete #autocomplete

Bash prompt with Git and autocompletion

First install HomeBrew and then use brew to install the bash-completion package

brew install bash-completion

After that you can open up your ~/.bashrc file and add the following:

# Load git prompt that display current branch etc
@scmx
scmx / hyper-term-cursor-hard-to-see.md
Created June 20, 2018 14:00
Hyper Term Fix cursor hard to see #hyper #hyperterm #macos #cursor #black #text #pointer

The text cursor in Hyper term can be very hard to see, so I looked into changing it to white or similar for better visibility. Here's a related issue about this vercel/hyper#1045

The currently proposed solutions didn't entirely work for me until I used css: instead of termCSS:.

~/.hyper.js

css: `
  .xterm {
 cursor: default;
@scmx
scmx / asdf-node-yarn.md
Created July 10, 2018 10:03
#asdf #nodejs #yarn
@scmx
scmx / marbles.ex
Last active December 9, 2018 22:34
Elixir circular data structure marbles for solving Advent of Code 2018 day 9
defmodule Marbles do
def new do
%{size: 0, current: 0, counter: 0}
end
def to_list(state) do
[]
|> do_to_list(state, state.current, state.current)
|> Enum.reverse
end