This Week I Googled: git remote set-url, group permissions, docker, untaint, gem uninstall


This is a series of open notes on things I didn’t have committed to memory that hopefully gives some useful tidbits and also potentially alleviates any impostor syndrome as a software engineer.

How to change the remote URL on a git repository

I often end up cloning a git repository either without write permissions to it or just accidentally copying the https version of the clone URL. I’ve generally been too lazy to look up or refresh my memory on how to change the URL and just re-cloning, but recently, I’ve ended up with changes that I don’t just abandon.

https://stackoverflow.com/questions/2432764/how-do-i-change-the-uri-url-for-a-remote-git-repository

git remote set-url origin new.git.url/here

How do I change the default group upon file modification and creation?

https://cets.seas.upenn.edu/answers/default-chgrp.html (the syntax is actually wrong here). The following sets the group of project directory to ourpgroup (chgrp) and then chmod g+s sets the SGID bit on the project directory so that any new files will have the group assignment of the group owner. (See: Linux permissions: SUID, SGID, and sticky bit for more)

chgrp ourpgroup project
chmod g+s project

How to get change time for a file via ruby

I wanted to compare build logs from two different runs (using gvimdiff in my case) after processing them through a filter to strip out timestamps and identifiers that change from run to run, but I couldn’t remember how to get a modified or creation time. Note: This value can mean slightly different things depending on the operating system on which Ruby is running.

https://stackoverflow.com/questions/4009288/how-do-i-get-the-file-creation-time-in-ruby-on-windows

File.ctime("foo.txt")

# get last two log files in macOS Downloads
# note ctime is creation time in Windows
Dir.glob("#{ENV['HOME']}/Downloads/*.log").sort { |a,b| File.ctime(a) <=> File.ctime(b) }.last(2)

Docker ps and run vs. docker container

docker container ls (docker ps) and docker container run (docker run) … see docker container reference

Multiple version constraints in Gemfile

Work with Multiple Version Constraints · Issue #930 – an old bundler issue from 2012, opened by a member of sous-chefs

Looks like it got added eventually: What is the syntax to specifing multiple gem constraints in a Rails Gemfile? … the answer is Use arrays or just list it out:

gem 'rbnacl', ['>= 3.2', '< 5.0']
gem 'bcrypt_pbkdf', '>= 1.0', '< 2.0'

Load library path in Unix and ruby

export LD_LIBRARY_PATH=/library/path

configure: error: cannot compute sizeof (long long) on AIX

Untaint method in Ruby

taint and untaint were a feature of Ruby for marking input from untrustworthy sources. As of Ruby 2.7, it was made a NOOP call. As of Ruby 3.2, the method has been removed from Object, so you might now be getting errors if upgrading to Ruby 3.2 (from your dependencies)

https://apidock.com/ruby/v2_5_5/Object/untaint

Mark the object as tainted.

Objects that are marked as tainted will be restricted from various built-in methods. This is to prevent insecure data, such as command-line arguments or strings read from Kernel#gets, from inadvertently compromising the user’s system.

To check whether an object is tainted, use #tainted?.

You should only untaint a tainted object if your code has inspected it and determined that it is safe. To do so use #untaint.

https://apidock.com/ruby/Object/taint

https://stackoverflow.com/questions/14281004/what-are-tainted-objects-and-when-should-we-untaint-them

https://blog.saeloun.com/2020/02/18/ruby-2-7-access-and-setting-of-safe-warned-will-become-global-variable/ – made NOOP in Ruby 2.7

https://stackoverflow.com/questions/73522137/search-up-undefined-method-untaint-error-after-ruby-upgrade

https://bugs.ruby-lang.org/issues/16131 – Remove $SAFE, taint and trust (Ruby 3.2) … this will require a bundler >= 2.1 per https://github.com/rubygems/bundler/pull/7385

Remove versions of old gems to a specification

The following command will uninstall a gem matching the version specification provided. However, it appears to only uninstall one version at a time, even if you pair --all with it.

gem uninstall bundler --version '< 2.1'

Leave a Reply

%d bloggers like this: