python – Creating nested list comprehension of files starting with specific string

I have a directory with ‘sets’ of files that start with a state name followed by 4 or 5 digits (typically indicating year). Each ‘file set’ contains 3 files a .txt, a .png, and a .jpg.

Example of files in directory:

California1998_reform_paper.txt 
California1998_reform_paper.pdf
California1998_reform_paper.jpg
California2002_waterdensity_paper.txt
California2002_waterdensity_paper.pdf
California2002_waterdensity_paper.jpg

Based on a users input I am trying to write some code that can put each of these file sets into a list of lists. Ultimately I would like to iterate over the list of lists. That said, I am not married to any one data type if a dictionary or something else may be more efficient.

I would like the user to be able to enter either:

  • The state name i.e. ‘California’ – to get all files from California
    OR
  • The state name + year i.e. ‘California1998’ to get all files from California 1998
import os
import regex

directory = #path to directory
input = 'California1998'

# Does input match proper format? If not error.
mm = regex.match('^((a-z)+)((0-9){4,5})|^((a-z)+)', input)
dir = str(os.listdir(directory))
if mm.group(1):
    state = mm.group(1)
    number = mm.group(2)
    state_num = state + number
    fileset = regex.findall(state_num, dir)
elif mm.group(3):
    state = mm.group(3)
    fileset = regex.findall(state + r'(0-9){4,5}', dir)
else:
    print('Put some error message here')

# Does input exist? If not error.
if len(fileset) > 0:
    fileset = tuple(set(sorted(fileset)))
else:
    print('Put some error message here')

# Get list of lists
state_num_files = ((file.path
    for file in os.scandir(directory)
    if file.name.startswith(state_num))
    for state_num in fileset)
return state_num_files

Above is the code I have thus far. It first uses regex.match to check the input, then regex.findall to find all matching state + years. I then create a sorted() set() from this list, which is converted into a tuple() called fileset. The last bit of code is a nested list comprehension that produces the list of lists by iterating through all files in the directory and iterating through all the state + years in fileset.

It certainly works, but seems repetitive and slower than it needs to be. My goal is to increase efficiency and remove any unnecessary iteration.

Thoughts on improvements:

  • Possibly replace each regex.findall with a nested list comprehension? and thus remove the state_num_files nested comprehension at the end of script?

Any thoughts are greatly appreciated!

synchronization – How to sync my local files in a shared Google drive folder?

You will find detailed instructions to your answer within the Back up & sync files with Google Drive and the Drive File Stream help pages, depending on the kind of account you have.

Having already gone through the first step (Choose a sync solution), you can Turn on sync for your organization.

As a quick reference for the differences between the two options (Compare Backup and Sync & Drive File Stream) please read the following:

+-------------------------------------------------------------------------+-----------------+-------------------+
|               Compare Backup and Sync & Drive File Stream               |                 |                   |
+-------------------------------------------------------------------------+-----------------+-------------------+
|                                                                         | Backup and Sync | Drive File Stream |
| Use files in My Drive                                                   | Yes             | Yes               |
| Use files in shared drives                                              | No              | Yes               |
| Sync only selected folders in My Drive                                  | Yes             | Yes               |
| Sync only individual files in My Drive                                  | No              | Yes               |
| Use native apps, like Microsoft Office & Photoshop                      | Yes             | Yes               |
| See who's editing with real-time presence in Microsoft Office           | No              | Yes               |
| Integrates with Microsoft Outlook, Meet scheduling                      | No              | Yes               |
| Sync other folders, like Documents or Desktop                           | Yes             | No                |
| Use with your personal Google Account, like MyPersonalAccount@gmail.com | Yes             | No                |
| Use with your work or school Google Account                             | Maybe           | Yes               |
| Upload photos and videos to Google Photos                               | Yes             | No                |
+-------------------------------------------------------------------------+-----------------+-------------------+

clustering – Increase TempDB Files, Shrink VLF’s with FCI

I am planning to resize and increase the number of tempDB files and shrink the VLF’s on an FCI. In this case, the tempdb files are stored on the network drive, rather than the local disk. I couldn’t find anything that addresses situation, but I need to know the impact the increase would have on a FCI. Thanks!

FFMPEG – HLS files for more than 150 cameras

I’d like to know if someone has tried to generate HLS files using FFMPEG for more than 150 cameras in the same computer / server.

I tried with 13 cameras and it consumed a huge memory from the computer (windows 10 without a video board). this is the command that I used:
ffmpeg -i rtsp://<ip-camera> -g 60 -hls_time 2 -movflags frag_keyframe+empty_moov -f mp4 <output-path-file>.m3u8

Is this a good idea using ffmpeg for this purposal or there is another way to handle multiple cameras to generate hls files?

Thanks in advance.

primeng – Unable to load language.json and css files in Firebase hosting

I have my app developed in StackBlitz, and incldued with ngx-translate package.
It is working perfectly until it deployed to firebase…. basically everything broken (sobbing…)
I tried my best to detail out my configs and the error log as i couldn’t resolve it myself.
I also dig through the internet but no luck to resolve any of them.
Sorry for the lengthy post.

index.html

<link rel="stylesheet" type="text/css" href="https://stackoverflow.com/node_modules/primeicons/primeicons.css" />
<link rel="stylesheet" type="text/css" href="https://stackoverflow.com/node_modules/primeng/resources/themes/nova-light/theme.css" />
<link rel="stylesheet" type="text/css" href="https://stackoverflow.com/node_modules/primeng/resources/primeng.min.css" />

The above code error out in Firebase but not StackBlitz (run perfectly)

Resource interpreted as Stylesheet but transferred with MIME type text/html: "https://fireforgez.firebaseapp.com/node_modules/primeng/resources/themes/nova-light/theme.css".
Resource interpreted as Stylesheet but transferred with MIME type text/html: "https://fireforgez.firebaseapp.com/node_modules/primeng/resources/primeng.min.css".
Resource interpreted as Stylesheet but transferred with MIME type text/html: "https://fireforgez.firebaseapp.com/node_modules/primeicons/primeicons.css".

To get rid of it, i did a silly patch by replace it with actual web URL

<link rel="stylesheet" type="text/css" href="https://unpkg.com/primeicons@4.0.0-rc.2/primeicons.css" />
<link rel="stylesheet" type="text/css" href="https://unpkg.com/primeng@9.1.0/resources/themes/nova-light/theme.css" />
<link rel="stylesheet" type="text/css" href="https://unpkg.com/primeng@9.1.0/resources/primeng.min.css" />

PrimeFlex package also hit the similar error

    DevTools failed to load SourceMap: Could not parse content for
https://fireforgez.firebaseapp.com/primeflex.css.map: Unexpected token < in JSON at position 0

I compared both StackBlitz and Firebase, the stylesheet files are all load-able. But when i replace with firebase hosting url, all .css revert back to firebase main url
e.g.
https://fireforgez.firebaseapp.com/node_modules/primeng/resources/themes/nova-light/theme.css
will redirect to
https://fireforgez.firebaseapp.com/
and generated a series of error

Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'node_modules/primeng/resources/themes/nova-light/theme.css'
Error: Cannot match any routes. URL Segment: 'node_modules/primeng/resources/themes/nova-light/theme.css'
    at ApplyRedirects.noMatchError (router.umd.js:2284) (angular)
    at CatchSubscriber.eval (as selector) (router.umd.js:2265) (angular)
    at CatchSubscriber.error (catchError.js:48) (angular)
    at MapSubscriber.Subscriber._error (Subscriber.js:92) (angular)
    at MapSubscriber.Subscriber.error (Subscriber.js:72) (angular)
    at MapSubscriber.Subscriber._error (Subscriber.js:92) (angular)
    at MapSubscriber.Subscriber.error (Subscriber.js:72) (angular)
    at MapSubscriber.Subscriber._error (Subscriber.js:92) (angular)
    at MapSubscriber.Subscriber.error (Subscriber.js:72) (angular)
    at ThrowIfEmptySubscriber.Subscriber._error (Subscriber.js:92) (angular)
    at ThrowIfEmptySubscriber.Subscriber.error (Subscriber.js:72) (angular)
    at TakeLastSubscriber.Subscriber._error (Subscriber.js:92) (angular)
    at TakeLastSubscriber.Subscriber.error (Subscriber.js:72) (angular)
    at MergeMapSubscriber.OuterSubscriber.notifyError (OuterSubscriber.js:26) (angular)
    at resolvePromise (zone.js:816) (angular)
    at resolvePromise (zone.js:768) (angular)
    at eval (zone.js:878) (angular)
    at Object.onInvokeTask (core.umd.js:19397) (angular)
    at drainMicroTaskQueue (zone.js:591) (<root>)

For ngx-translate, it’s also working correctly in StackBlitz but couldn’t load language files.

SyntaxError: Unexpected token < in JSON at position 0
at JSON.parse (<anonymous>)
at XMLHttpRequest.onLoad (https://fireforgez.firebaseapp.com/turbo_modules/@angular/common@9.1.9/bundles/common-http.umd.js:1390:55)
at ZoneDelegate.invokeTask (https://fireforgez.firebaseapp.com/turbo_modules/zone.js@0.10.3/dist/zone.js:411:35)
at Object.onInvokeTask (https://fireforgez.firebaseapp.com/turbo_modules/@angular/core@9.1.9/bundles/core.umd.js:19397:37)
at ZoneDelegate.invokeTask (https://fireforgez.firebaseapp.com/turbo_modules/zone.js@0.10.3/dist/zone.js:410:40)
at Zone.runTask (https://fireforgez.firebaseapp.com/turbo_modules/zone.js@0.10.3/dist/zone.js:178:51)
at ZoneTask.invokeTask (as invoke) (https://fireforgez.firebaseapp.com/turbo_modules/zone.js@0.10.3/dist/zone.js:493:38)
at invokeTask (https://fireforgez.firebaseapp.com/turbo_modules/zone.js@0.10.3/dist/zone.js:1633:18)
at XMLHttpRequest.globalZoneAwareCallback (https://fireforgez.firebaseapp.com/turbo_modules/zone.js@0.10.3/dist/zone.js:1670:25)
...
message: "Http failure during parsing for https://fireforgez.firebaseapp.com/assets/i18n/en.json"
name: "HttpErrorResponse"
ok: false
status: 200
statusText: "OK"
url: "https://fireforgez.firebaseapp.com/assets/i18n/en.json"

Here i my complete angular.json file

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "demo": {
      "root": "",
      "sourceRoot": "src",
      "projectType": "application",
      "prefix": "app",
      "schematics": {},
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/demo",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.app.json",
            "assets": (
              "src/favicon.ico",
              "src/assets"
            ),
            "styles": (
              "src/styles.css",
              "node_modules/primeicons/primeicons.css",
              "node_modules/primeng/resources/themes/nova-light/theme.css",
              "node_modules/primeng/resources/primeng.min.css",
              "../node_modules/quill/dist/quill.core.css",
              "../node_modules/quill/dist/quill.snow.css",
              "node_modules/primeflex/primeflex.css"
            ),
            "scripts": (
              "../node_modules/quill/dist/quill.js"
            )
          },
          "configurations": {
            "production": {
              "fileReplacements": (
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ),
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "demo:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "demo:build:production"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "demo:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.spec.json",
            "karmaConfig": "src/karma.conf.js",
            "styles": (
              "styles.css"
            ),
            "scripts": (
              "../node_modules/quill/dist/quill.js"
            ),
            "assets": (
              "src/favicon.ico",
              "src/assets"
            )
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": (
              "src/tsconfig.app.json",
              "src/tsconfig.spec.json"
            ),
            "exclude": (
              "**/node_modules/**"
            )
          }
        }
      }
    }
  },
  "defaultProject": "demo"
}

windows – Can we keep only X number of files rotated by Y MB with Apache rotatelogs

Can we rotate Apache logs keeping n number of backups rotated by size.

We can rotate apache logs with size by doing following:

ErrorLog “|bin/rotatelogs.exe logs/error_log-%Y-%m-%d.log 20M”

How I can keep only 5 backups always? What I mean is files should be always when it reaches to 20 MB and it should always keep 5 backups.

I am using Apache 2.4.20 on windows.

Can skype app copy, open or delete my personal files?

I just wanted to install Skype but it says that this app can access to all my personal files and system resources. What does this mean? Does this means that somehow Skype can copy, delete or open my personal files? or change my computer setup like installing files, etc?
Is it safe to install Skype app?
Thanks.

disk utility – External drive’s files not showing, but I know it has been half-filled with data. It works fine on Ubuntu but not on macOS?

My external hard drive used to work just fine (my OS is Mojave) – I can read and write because I used NTFS Paragon software free trial. But now that I wiped all traces of said software, my external hard drive won’t show its contents anymore. I know it’s not a problem of the hard drive because when I click on Get Info it says it’s half-full. And when I use Ubuntu, I can see and edit the files.

I tried Disk Utility (unmounting,mounting,repairing), booting into Recovery Mode and using Disk Utility to perform the same steps, leaving the external drive for hours, but none worked.

Please help!

gnome – I cant get .desktop files to work :(

i wrote a .desktop file for discord and it just doesnt launch. The icon doesnt apear either. The File :

[Desktop Entry]
Name=Discord
Exec=/usr/share/discord/Discord
Icon=/usr/share/discord/discord.png
Type=Application
Categories=GTK;GNOME;

I grabbed a template from the gnome website and put in my info.
Hope someone can help me. 😀