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

1.07 Thousand
Const

Scope or scope in Rails

# app/models/user.rb
...
enum role: { user: 0, author: 1, admin: 2, robot: 3 }

scope :human, -> { user.or(author) }
scope :terminator, -> { admin.or(robot) }


Produces

User.human.to_sql
#=> "SELECT \"users\".* FROM \"users\" WHERE (\"users\".\"role\" = 0 OR \"users\".\"role\" = 1)"


HTML forms that submit to another action

I've known for a long time that you can submit values with submit buttons so you can track which button was used to submit the form e.g.

language-html

However, today I needed to actually submit the form to a completely differnt action. Turns out you can do this with formaction attributes

language-html

Get the password of the wifi you're on

wifi_password() {
    airport="/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport"
    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"


1.07 Thousand
Ali

Run rubocop before commit

Introduction


Git hooks are super powerful for automating tasks and enforcing coding standards in a Git repository. One common use case for Git hooks is to run automated tests and code analysis tools before allowing a commit to proceed. In this article we’ll cover pre-commit hooks, how to skip them and how to set up a pre-commit hook to run Rubocop, a Ruby code analysis tool.

What is Rubocop?


Rubocop is a static code analysis tool for Ruby that checks code for style and security issues. It’s a popular tool among Ruby developers to ensure their code follows the Ruby style guide and best practices. Rubocop can be run manually but integrating it with a pre-commit hook ensures code is checked automatically before each commit.

Copy this into .git/hooks/pre-commit (remove .sample)

#!/usr/bin/env ruby

require 'english'
require 'rubocop'

ADDED_OR_MODIFIED = /A|AM|^M/.freeze

changed_files = `git status --porcelain`.split(/\n/).
    select { |file_name_with_status|
      file_name_with_status =~ ADDED_OR_MODIFIED
    }.
    map { |file_name_with_status|
      file_name_with_status.split(' ')[1]
    }.
    select { |file_name|
      File.extname(file_name) == '.rb'
    }.join(' ')

system("rubocop #{changed_files}") unless changed_files.empty?

exit $CHILD_STATUS.exitstatus



Make it executable 

$ chmod +x .git/hooks/pre-commit



You're good to go, from now it'd run rubocop against your changes and prevents from commiting unless you fix the offences.

How to skip pre-commit? just pass -n to git commit

$ git commit -n -m "[hotfix] blah blah"


What is a Pre-Commit Hook?


A pre-commit hook is a client-side Git hook that runs before a commit is created. It’s a script that can do various things like run automated tests, check code style or enforce coding standards. If the pre-commit hook fails the commit is aborted and you have to fix the issues before committing again.

Why Run Rubocop Before Commit


Running Rubocop before commit has several advantages:

  • Code quality: Rubocop checks code for style and security issues so the codebase is consistent and secure.
  • Time saver: By running Rubocop automatically before commit you can catch issues early and avoid wasting time debugging later.
  • Collaboration: By enforcing coding standards pre-commit hooks promote collaboration and consistency among team members.

How to set up a pre-commit hook

  1. Install Rubocop and the pre-commit hook tool of your choice (e.g., Husky or Pre-commit).
  2. Create a new file in the .git/hooks directory called pre-commit.
  3. Add the Rubocop command to the pre-commit file, e.g., rubocop -a.
  4. Make the pre-commit file executable by running chmod +x .git/hooks/pre-commit.
  5. Test the pre-commit hook by running git commit -m “Test commit”

Note: If you want to skip the pre-commit hook temporarily you can use the –no-verify option with the git commit command, e.g., git commit -m “Test commit” –no-verify.
1.07 Thousand
Ali

Show TODO and other notes in your Rails app

Did you know you can show all TODOs/OPTIMIZE/FIXME in your rails app with rails notes?

$ rails notes
app/helpers/users_helper.rb:
  * [10] [TODO] Use ActiveSupport extension methods for Date/Time

app/services/slack.rb:
  * [20] [OPTIMIZE] Replace library with core Net::HTTP



You can even focus with notes:todo etc.:

$ rails notes:todo
app/helpers/users_helper.rb:
  * [10] [TODO] Use ActiveSupport extension methods for Date/Time


1.07 Thousand
Const

Create a Hash from an Enumerable (Rails 6.0)

New method allowing you to create a Hash from an Enumerable:

%w(driver owner drivy).index_with(nil)
# => { 'driver' => nil, 'owner' => nil, 'drivy' => nil }

%w(driver owner drivy).index_with { |role| delta_amount_for(role) }
# => { 'driver' => '...', 'owner' => '...', 'drivy' => '...' }


Restore a deleted file in Git

# Find in which commit it's been deleted
$ git rev-list -n 1 HEAD -- 
4058ef780d2f6c4c6d57cfd7fd4ebe14c9dc28b3
# Restore it back
$ git checkout 4058ef780d2f6c4c6d57cfd7fd4ebe14c9dc28b3^ -- 


1.07 Thousand
Ali

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

<3

1.11 Thousand
Tino

make a pr from command line using hub

install hub first with brew: brew install hub then use a simple command, like at the example below: hub pull-request -m "best pr ever" -b oozou:develop -h feature/awesome-improvements

or even smarter:

hub pull-request -m "best pr ever" -b oozou:develop -h $(git rev-parse --abbrev-ref HEAD)


for more detailed info how to make pull requests see at hub pull-request --help

1.07 Thousand
Stan