Today I Learned

4 posts by piotrmotak

Pass hex color to fill svg in background url (SCSS)

Passing svg into background url might be useful for eg. in case of dropdown arrow selects.

but there is a problem if you want to pass dynamically color to fill that svg. url is not accepting # from that hex.

I found that if we use

@use "sass:string";
@use "sass:color";

we can build something similar to encodeURI

@function escape-url-hex-color($hex_color) {
  $ie-color-string: color.ie-hex-str($hex_color);
  $string: string.quote($ie-color-string);
  $color: string.slice($string, 4);
  @return '%23' + $color;
}

then we can easily use it to set color variable and pass it to fill attribute.

Searching for files in AWS s3 from rails console

first set your credentials to AWS_ACCESS_KEY_ID, AWS_REGION, AWS_SECRET_ACCESS_KEY in .env

then

rails c
s3_client = Aws::S3::Client.new()

if credentials are set it will by default look for them there, but there is much more other options

then we can

s3_client.list_objects_v2(
    bucket: 'S3_BUCKET',
    max_keys: 'max_records by def 1000',
    prefix: 'some/key/to/file/'
  ).contents

It is good to note that prefix doesn’t begin from ‘/‘

also it works from ‘aws-sdk’ > 2.3.2