Skip to content

Instantly share code, notes, and snippets.

View airblade's full-sized avatar

Andy Stewart airblade

View GitHub Profile
@airblade
airblade / imap_with_move.rb
Created October 27, 2022 14:53
Adds IMAP move to Mail
require 'mail'
require 'net/imap'
# Add IMAP move to Mail.
module Mail
# In addition to the options supported by the IMAP class:
#
# move: mailbox to which to move emails. This makes the :delete_after_find flag irrelevant.
#
@airblade
airblade / application.html.erb
Last active September 16, 2022 10:41
Simple page titles in Rails
<html>
<head>
<title><%= title %></title>
<!-- ... -->
</head>
<!-- ... -->
</html>
@airblade
airblade / karabiner.json
Created April 13, 2022 18:46
Karabiner rules elements
{
"description": "Left shift -> {",
"manipulators": [
{
"from": {
"key_code": "left_shift"
},
"to_if_alone": {
"key_code": "open_bracket",
"modifiers": ["left_shift"]
$ mkdir wrapper && cd wrapper
$ echo 'source "https://rubygems.org"' > Gemfile
$ echo 'gem "rails", github: "rails/rails", branch: "main"' >> Gemfile
$ bundle
$ cat ~/.railsrc
--database=postgresql
--skip-action-mailbox
--skip-action-text
--skip-sprockets
@airblade
airblade / upgrade.md
Last active October 7, 2021 13:33
Upgrading Rails 6.0 to 6.1
form_with HTTP request XHR / fetch()
6.0 local: true (default)
6.1 (default) local: false

link_to, form_for: defaults to local. Use remote: true to make remote.

@airblade
airblade / copy_attachments.rb
Created November 10, 2015 11:01
Copies S3-stored Paperclip attachments from one AR model to another
# lib/paperclip/copy_attachments.rb
# Copies S3-stored Paperclip attachments from one AR model to another.
#
# This module should be mixed into the target AR model.
if Gem::Version.new(::AWS::VERSION) >= Gem::Version.new(2)
raise NotImplementedError, 'coded for aws-sdk v1'
end
let s:async_sync_id = 0
let s:async_sync_outputs = {}
function! s:next_async_sync_id()
let async_sync_id = s:async_sync_id
let s:async_sync_id += 1
return async_sync_id
endfunction
function! s:async_sync_output(async_sync_id, output)
@airblade
airblade / gist:f78946ed45ac10011ef8
Last active February 4, 2020 12:44
Vim highlight groups

Changing attributes on a group linked to another disconnects the link

Link a highlight group to another.

:hi link Foo Comment

:hi Foo
Foo  xxx links to Comment
@airblade
airblade / raspbian.md
Last active January 7, 2020 11:38
Pi hole stuff
  • Download latest Raspbian Lite (currently Buster) from here.

  • Plug SD card into computer.

  • Unzip Raspbian image and install on SD card. This should overwrite everything on the SD card; it shouldn't be necessary to format first.

    diskutil list  # make note of disk of SD card; eg. disk4
    diskutil unmountDisk /dev/disk4
    sudo dd bs=1m if=<path of raspbian image> of=/dev/rdisk4 conv=sync  # rdisk4 is  faster than disk4
    
@airblade
airblade / vimrc
Created April 5, 2019 11:04
Using vim-gitgutter to achieve niklaas/lightline-gitdiff
let g:gitgutter_signs=0
function! GitStatus()
return join(filter(map(['A','M','D'], {i,v -> v.': '.GitGutterGetHunkSummary()[i]}), 'v:val[-1:]'), ' ')
endfunction
set statusline+=%{GitStatus()}