Reset Postgres table sequence after DELETE

When deleting recent records from a table, you can reset it's sequence counter if auto-increment field continuity is important to you. Consider actions on the following table, users: ``` select max(id) from users;

+-----+ | max | +-----+ | 896 | +-----+ 1 rows in set (0.03 sec) Then, some delete action against most recent rows: delete from users where created_at > timestamp 'yesterday';

96 rows in set (0.15 sec) `` The next auto-increment value foridwould be 897 on the next insert. Use the following command to reduce the sequence value for theusers` table by 96.

select setval('users_id_seq',(select max(id) from users));

| setval |
| 800    |
1 rows in set (0.04 sec)


My most used slack shortcuts

⌘-K(or T) to open the channel switcher (I navigate channels solely with this shortcut and have my slack set to hide all channels without new messages)

⌘-F opens the search box. Can modify searches with from:@user and in:#channel for extra awesomeness

Up Arrow will edit you last message; perfect for when you hit Enter too early or mispell things

+:emoji: react to the last message. Have to be quick so nobody else replies before you react though or you'll react to the wrong message

/remind [someone usually myself] [to do something] [at this time in words] not really a shortcut but is great for not forgetting simple tasks

The channel switcher also supports fuzzy matching to some extent. If a channel is named foo-bar you can type fb to show it. It's doesn't work so well with multi-user-dm's though.


Chrome tab manipulation

Sometimes I want to go back to the last page I viewed while still keeping the same one open. You can very easily achieve this with shortcuts

  1. ⌘-L to focus the omnibox
  2. ⌘-Enter to open the current URL in a new tab
  3. ⌘-⇧-[ to go back to the original tab
  4. ⌘-[ to go back to the previously viewed page in the original tab

Add spacers to your macOS app dock to make groups

Open term (or equivalent) and paste the following one-liner:

defaults write persistent-apps -array-add '{tile-data={}; tile-type="spacer-tile";}'; killall Dock

When the Dock restarts, there should be a draggable blank space that you can move anywhere. Repeat to your heart's desire.


Change system names on macOS

From term (or equivalent), copy and paste:

To change your public Host Name (i.e., sh sudo scutil --set HostName

To change your local Host Name (i.e., jeff.local): sh sudo scutil --set LocalHostName

To change your Finder Computer Name (i.e., Jeff's MBP): sh sudo scutil --set ComputerName

Finally, flush your DNS cache to force refresh: sh dscacheutil -flushcache


Use FFmpeg and Apple Script to compress videos

Build an application you can drag-and-drop videos onto to compress them significantely:

Make sure you have ffmpeg installed (brew install ffmpeg).

Create a new Apple Script app: AppleScript on open filelist repeat with i in filelist tell application "Terminal" do script "ffmpeg -i " & POSIX path of i & " -vcodec h264 -acodec mp2 " & POSIX path of i & "_compressed.mp4" end tell end repeat end open


Get the password of the wifi you're on

wifi_password() {
    ssid="`$airport -I | awk '/ SSID/ {print substr($0, index($0, $2))}'`"
    pwd="`security find-generic-password -D 'AirPort network password' -ga \"$ssid\" 2>&1 >/dev/null`"
    echo $pwd

$ wifi_password

password: "!forHackers"


Cleanup stale formulas on brew

Use brew cleanup to get some spaces back!

Use brew cleanup -n to list what's gonna get cleanup

Use brew cleanup to clean only that particular formula