User Query sort on custom field then name

I am trying to sort a list of attorneys (set up as Users) classified as founding members, members, and associates. Those classifications are stored in the attorney_title meta field.

I need them to sort by title (in this specific order, not alphabetically), then sort the attorneys alphabetically:

  • Founding Members
  • Members
  • Associates

Currently I’m doing a query for founders, then a query for members, then a query for associates. But I figure there might be a sensible way to do it in one query. If the attorney titles were alphabetical then I could probably get it, but since they must be sorted in a specific order, I’m not getting it.

applescript – Script sort MP4 (and other) videos by orientation to portrait and landscape folders >>> IMPOSSIBLE?

I’ve been wrestling with a 14TB+ video library for the last months trying to dedupe and sort all of it into production ready folder structure.

For the life of me I have not been able to find (spent 3 solid days with no sleep) a script that will sort a folder of video files, using their dimensions, into Portrait and Landscape folders.

The closest I’ve found is this –

#!/bin/bash
shopt -s nullglob

for f in *.{mp4,MP4,mov,MOV,m4v,M4V}
    do 
        height=`mdls -raw -name  kMDItemPixelHeight "$f"`
        width=`mdls -raw -name  kMDItemPixelWidth "$f"`
        mkdir -p "${height}x${width}"
        mv "$f" "${height}x${width}"/
        
        printf "File: $fn"     
        printf "> Dimensions: $height x $width nn"
    done

printf "All done! n"

Which gets me closer by sorting them into folders based on dimensions, but it’s not what I’m trying to achieve.

Alternatively I found this script for images using Imagemagick, (which I installed via Homebrew) it does read the files, though it moves them ALL into the portraits directory. I’m assuming the variables may be different to extract height and width from a video file?

#/bin/zsh
mkdir -p portraits
mkdir -p landscapes
for f in ./*.mp4
do
  r=$(identify -format '%(fx:(h/w))' "$f")
  if (( r < 1.0 )) 
  then
      echo "Portrait detected."
  mv "$f" ./portraits/
  elif  (( r > 1.0 ))
  then
  echo "Landscape detected."
      mv "$f" ./landscapes/
  fi
done

If ANYONE OUT THERE can help me with this, it’s worth a PayPal to me. I know it’s quick work for the right mind.

The same, if someone has another solution using folder actions or automator or ANYTHING else. I’m running Mac OS with terminal.

Much appreciated!

jason@speedheathens.com

performance – How do I optimize the bubble sort in Assembly8086?

I tried to implement bubble sort in Assembly 8086.

datasg      SEGMENT BYTE 'data'
array       DB 1, 3, 2, 5, 4
n           DW 5
datasg      ENDS
stacksg     SEGMENT BYTE STACK 'stack'
            DW 12 DUP(?)
stacksg     ENDS
codesg      SEGMENT PARA 'code'
            ASSUME CS:codesg, DS:datasg, SS:stacksg
MAIN        PROC FAR

; Pushing the previous data segment to keep it secure.
            PUSH DS
            XOR AX, AX
            PUSH AX
            MOV AX, datasg
            MOV DS, AX
;SI = i
            XOR SI, SI
            MOV CX, n
            DEC CX
out:        PUSH CX; Pushing CX to the stack before entering the second for loop
            XOR DI, DI
            MOV CX, n
            DEC CX
            SUB CX, SI
in:         MOV AH, array(DI)
            CMP AH, array(DI+1)
            JLE if_end
            XCHG AH, array(DI+1)
            MOV array(DI), AH
if_end:     INC DI
            LOOP in
            POP CX
            INC SI
            LOOP out
            XOR SI, SI
; Some garbage code to move array elements to AL register one by one to see them while debugging.
            MOV AL, array(SI)
            INC SI
            MOV AL, array(SI)
            INC SI
            MOV AL, array(SI)
            INC SI
            MOV AL, array(SI)
            INC SI
            MOV AL, array(SI)
            RETF
MAIN        ENDP
codesg      ENDS
            END MAIN

It seems to be working for the given example in the above code. I also tried it with different arrays and they all seem to work.
I just want to learn if there is a way to improve it? Improvements like changing JMP codes to decrease the size of code or using AX with XCHG because that is faster.

I also can’t comprehend the idea of pushing CX to stack for using nested-for loops. If you would give some suggestion about it I would be very happy.

sorting – how can I sort an email alphabetically in bash

I am trying to sort a list of emails in alphabetical order in bash to no avail

The emails involve numbers and periods

kori.flap10@flap.com

flap39@flap.com

flap.flap@flap.com

flap@flap.com

k.slick20@flap.uk

On using the basic sort command

cat text.txt | sort

it does not sort it alphabetically but instead outputs

flap39@flap.com

flap@flap.com

flap.flap@flap.com

kori.flap10@flap.com

k.slick20@flap.uk

How can I sort this to also consider the periods and numbers within the email addresses?

how can sort my column

How can I add order?

add_filter('manage_articles_posts_columns', 
function ( $columns ) 
{
    if( is_array( $columns ) && ! isset( $columns('post_views') ) )
        $columns('post_views') = __( 'views' );     
     if(current_user_can('administrator'))
    return $columns;
},  );

add_action( 'manage_articles_posts_custom_column', 
function ( $column_name, $post_id ) 
{
    if ( $column_name == 'post_views') {
        $post_view_count = get_post_meta($post_id, 'views', true);
        $count = $post_view_count ? $post_view_count : 0;
        if(current_user_can('administrator'))
            echo $count;
    }
 
}, 10, 2);

covid 19 – Does Indonesia require some sort of mandatory quarantine in a facility upon arrival?

I have finally managed to get a visa to visit Indonesia, which has closed all borders except for citizens.
However, I can’t find concrete information on the quarantine part.

Does Indonesia require some sort of quarantine in a facility? I have read that somewhere a while ago now I can’t find it. I am ok with self-quarantine as I have a house there.

homework – Build using merge sort the ordered string of bytes that contain all characters from s1 and s2

Being given two alphabetical ordered strings of characters, s1 and s2, build using merge sort the ordered string of bytes that contain all characters from s1 and s2.

I have issues with adding the last element in some cases.

bits 32

global start        

extern exit         
import exit msvcrt.dll
segment data use32 class=data
    ; ...
    s1 db 'acdefgwxyz' ; first string in alphabetical order
    len_s1 equ ($ - s1) ; length of first string
    s2 db 'bcdfhij' ; second string in alphabetical order
    len_s2 equ ($ - s2) ; length of second string
    rez times len_s1 + len_s2 db 0
    str_reminder dd 0

segment code use32 class=code
    start:
        cld ; set direction flag to 0 to go from left to right
        mov ESI, s1 ; s1 in source
        mov EDI, s2 ; s2 in destination
       
        mov ECX, len_s1 + len_s2 ; the max length (len_s1 + len_s2)
        mov EBX, 0 ; for s2, how many elements we went through
        mov EAX, 0 ; for s1, how many elements we went through
        mov EDX, 0 ; for the result string
        
        repeta:
            cmpsb ; comparing the elements of the two strings
            
            jng smaller_s1 ; s1(pos) < s2(pos)
            jg larger_s1 ; s1(pos) > s2(pos)
            je equals; s1(pos) = s2(pos)
            
            smaller_s1:
                dec ESI ; decrementing ESI
                dec EDI ; decrementing EDI
                mov (str_reminder), EAX ; save the value of EAX
                lodsb ; put current value from esi in al
                mov (rez + EDX), AL ; put in result on position edx the value from al
                mov EAX, (str_reminder)
                inc EDX ; incrementing EDX
                inc EAX ; incrementing EAX
                cmp EAX, len_s1 ; if we are done with elements from s1
                jge sf_prg ; jump to sf_prog
                loop repeta ; repeating the loop
                jecxz sf_prg ; if ecx = 00000000, we jump to sf_prog
            
            larger_s1:
                dec EDI
                dec ESI
                mov (str_reminder), EAX
                mov AL, (EDI)
                mov (rez + EDX), AL
                mov EAX, (str_reminder)
                inc EDI
                inc EDX
                inc EBX
                cmp EBX, len_s2
                jge sf_prg
                loop repeta
                jecxz sf_prg
            
            equals:
                dec ESI
                mov (str_reminder), EAX
                lodsb
                mov (rez + EDX), AL
                mov EAX, (str_reminder)
                inc EDX
                inc EBX
                cmp EBX, len_s2
                jge sf_prg
                inc EAX
                cmp EAX, len_s1
                jge sf_prg
                loop repeta
                jecxz sf_prg
        sf_prg:
        
        cmp EAX, len_s1 ; comparing EAX with the length of s1, if EAX = len_s1 then we are done with the terms of s1 
        je ebx_bigger; if we have to add terms from s2
        jne ebx_smaller ; if EAX is not equal to len_s1 we are done with the terms of s2
        
        ebx_bigger: ; the remaining terms of s1
            mov ECX, len_s2
            sbb ECX, EBX
            repeat_:
                mov AL, (EDI)
                mov (rez + EDX), AL
                inc EDX
                inc EDI
            loop repeat_
            jmp end_prg
        
        ebx_smaller:
            mov ECX, len_s1
            sbb ECX, EAX
            repeat__:
                lodsb
                mov (rez + EDX), AL
                inc EDX
            loop repeat__
        
        
        end_prg:
        push    dword 0      
        call    (exit)      
```

sql server – SQL 2019 – Sort operation taking most of the query cost

Please see below query and execution plan – Any advice on how to get rid of SORT operator cost (nothing coming on missing indexes recommendation)

SELECT  *
FROM    (
select top 5    convert(varchar,DayKeyId) + '|' + convert(varchar,DimCampaignId) + '|' + convert(varchar,DimLeadProviderId) + '|' + convert(varchar,fcd.DimCorpId) + '|' + convert(varchar,CASE when DimLocationId in ('149','3','147') then 39 when DimLocationId in ('148','146') then 38
              else DimVendorId end) + '|' + convert(varchar,DimLocationId) + '|' + convert(varchar,DimEmployeeId) + '|' + convert(varchar,DimRateTypeId) as LinkKey
        ,DayKeyId
        ,DimCampaignId
        ,DimLeadProviderId
        ,fcd.DimCorpId
        ,DimDispositionId
        ,CASE when DimLocationId in ('149','3','147') then 39

              when DimLocationId in ('148','146') then 38
              else DimVendorId end as DimVendorId
        ,DimLocationId
        ,DimEmployeeId
        ,DimRateTypeId
        ,sum(isnull(RecordCounter,0)) as RecordCounter
        ,sum(isnull(SalesCounter,0)) as SalesCounter
        ,sum(isnull(DialCounter,0)) as DialCounter
        ,sum(isnull(ContactCounter,0)) as ContactCounter
        ,sum(isnull(RefusalCounter,0)) as RefusalCounter
        ,sum(isnull(products_sold,0)) as products_sold
        ,sum(isnull(rgu_hsd,0)) as rgu_hsd
        ,sum(isnull(rgu_phone,0)) as rgu_phone
        ,sum(isnull(rgu_video,0)) as rgu_video
        ,sum(isnull(rgu_xh,0)) as rgu_xh
        ,sum(isnull(PremiumChannel,0)) as PremiumChannel
        ,sum(isnull(video_equipment,0)) as video_equipment
        ,sum(isnull(x_mobile,0)) as x_mobile
        ,sum(isnull(x_mobile_equipment,0)) as x_mobile_equipment
        ,sum(isnull(x_mobile_accessory,0)) as x_mobile_accessory
        ,sum(isnull(x_mobile_service,0)) as x_mobile_service
        ,sum(isnull(total_duration,0)) as total_duration
        ,sum(isnull(TalkTime,0)) as TalkTime
        ,sum(isnull(WrapTime,0)) as WrapTime
        ,sum(isnull(OtherTime,0)) as OtherTime
        ,sum(isnull(costs,0)) as costs
        ,sum(isnull(sph_num,0)) as sph_num
        ,sum(isnull(sph_dem,0)) as sph_dem
        ,sum(isnull(cph_num,0)) as cph_num
        ,sum(isnull(cph_dem,0)) as cph_dem
        ,sum(isnull(rgu_total,0)) as rgu_total
        ,sum(isnull(take_rate_num,0)) as take_rate_num
        ,sum(isnull(take_rate_dem,0)) as take_rate_dem
        ,sum(isnull(rgu_take_rate_dem,0)) as  rgu_take_rate_num
        ,sum(isnull(rgu_take_rate_num,0)) as rgu_take_rate_dem
        ,sum(isnull(rgu_xinfinity,0)) as rgu_xinfinity
        ,sum(case when DimDispositionId = 1 and (isnull(SalesCounter,0) > 0)
                  then isnull(RecordCounter,0) else 0 end) as HomesSold
        ,sum(case when DimDispositionId = 2 and (isnull(SalesCounter,0) > 0)
                  then isnull(RecordCounter,0) else 0 end) as HomesSaved
        ,sum(case when DimDispositionId = 3 and (isnull(SalesCounter,0) > 0)
                  then isnull(RecordCounter,0) else 0 end) as CustomerCare
        ,sum(case when DimDispositionId in (1,2,3) and (isnull(SalesCounter,0) > 0)
                  then isnull(RecordCounter,0) else 0 end) as HomesSoldSaved
        ,sum(case when DimDispositionId = 1 and ((isnull(rgu_video,0)+isnull(rgu_hsd,0)+isnull(rgu_phone,0)+isnull(rgu_xh,0)+isnull(rgu_xinfinity,0)) > 0)
                  then isnull(RecordCounter,0) else 0 end) as HomesSoldRGU
        ,sum(case when DimDispositionId = 2 and ((isnull(rgu_video,0)+isnull(rgu_hsd,0)+isnull(rgu_phone,0)+isnull(rgu_xh,0)+isnull(rgu_xinfinity,0)) > 0)
                  then isnull(RecordCounter,0) else 0 end) as HomesSavedRGU
        ,sum(case when DimDispositionId = 1 and (isnull(SalesCounter,0) > 0)
                  then isnull(rgu_total,0) else 0 end) as RGUSold
        ,sum(case when DimDispositionId = 2 and (isnull(SalesCounter,0) > 0)
                  then isnull(rgu_total,0) else 0 end) as RGUSaved
        ,sum(case when DimDispositionId not in (63,64,66,70,72,73,74,75,78,114,115,116,117) and isnull(ContactCounter,0) > 0
                  then isnull(RecordCounter,0) else 0 end) as EligibleContactCounter
        ,sum(case when DimDispositionId in (1,2) and (isnull(SMSConsent,0) > 0)
                  then isnull(SMSConsent,0) else 0 end) as SMSConsent
        ,sum(case when DimDispositionId in (1,2) and (isnull(AutoIvrConsent,0) > 0)
                  then isnull(AutoIvrConsent,0) else 0 end) as AutoIvrConsent
        ,sum(case when DimDispositionId in (1,2) and (isnull(IVRXMOnlyConsent,0) > 0)
              then isnull(IVRXMOnlyConsent,0) else 0 end )as IVRXMOnlyConsent
        ,sum(case when DimDispositionId in (1,2) and (isnull(EmailConsent,0) > 0)
                  then isnull(EmailConsent,0) else 0 end) as EmailConsent
        ,sum(case when DimDispositionId in (1,2) and (isnull(ManualConsent,0) > 0)
                  then isnull(ManualConsent,0) else 0 end) as ManualConsent
        ,sum(case when DimDispositionId in (1,2) and (isnull(OverrideConsent,0) > 0)
                  then isnull(OverrideConsent,0) else 0 end) as OverrideConsent
        ,sum(case when DimDispositionId in (1,2) and (isnull(NAConsent,0) > 0)
                  then isnull(NAConsent,0) else 0 end) as NAConsent
        ,sum(isnull(PayPerPerformanceCosts,0)) as PayPerPerformanceCosts
        ,sum(isnull(TermQty,0)) as TermQty
        ,sum(isnull(rgusoldwosave,0)) as rgusoldwosave
        ,sum(isnull(rgusoldwsave,0)) as rgusoldwsave
        ,sum(isnull(videorgusoldwosave,0)) as videorgusoldwosave
        ,sum(isnull(videorgusoldwsave,0)) as videorgusoldwsave
        ,sum(isnull(hsdrgusoldwosave,0)) as hsdrgusoldwosave
        ,sum(isnull(hsdrgusoldwsave,0)) as hsdrgusoldwsave
        ,sum(isnull(phonergusoldwosave,0)) as phonergusoldwosave
        ,sum(isnull(phonergusoldwsave,0)) as phonergusoldwsave
        ,sum(isnull(xhrgusoldwosave,0)) as xhrgusoldwosave
        ,sum(isnull(xhrgusoldwsave,0)) as xhrgusoldwsave
        ,sum(isnull(xmrgusoldwosave,0)) as xmrgusoldwosave
        ,sum(isnull(xmrgusoldwsave,0)) as xmrgusoldwsave
        ,sum(case when DimDispositionId not in (63,64,66,70,72,73,74,75,78,114,115,116,117) and isnull(ContactCounter,0) > 0
                  then 1 else 0 end) as dinacontactpct_num
        ,sum(isnull(DialCounter,0)) as dinacontactpct_dem
        ,sum(case when DimDispositionId = 2 and (isnull(SalesCounter,0) > 0)
                  then 1 else 0 end) as dinasaved_take_rate_num
        ,sum(case when DimDispositionId not in (63,64,66,70,72,73,74,75,78,114,115,116,117) and isnull(ContactCounter,0) > 0
                  then 1 else 0 end) as dinasaved_take_rate_dem
        ,sum(isnull(SalesCounter,0)) as dinasold_take_rate_num
        ,sum(case when DimDispositionId not in (63,64,66,70,72,73,74,75,78,114,115,116,117) and isnull(ContactCounter,0) > 0
                  then 1 else 0 end) as dinasold_take_rate_dem
        ,sum(case when DimDispositionId in (1,2) and (isnull(SalesCounter,0) > 0)
                  then 1 else 0 end) as dinatotal_take_rate_num
        ,sum(case when DimDispositionId not in (63,64,66,70,72,73,74,75,78,114,115,116,117) and isnull(ContactCounter,0) > 0
                  then 1 else 0 end) as dinatotal_take_rate_dem
        ,sum(isnull(NoIbContact,0)) as NoIbContact  
        ,sum(isnull(RevenueAmount,0)) as RevenueAmount
        ,fcd.LastUpdateDate
from    FactCallDetail (nolock) fcd
inner join DimCorp
 dc on fcd.DimCorpId = dc.DimCorpId
where 1=1
group by convert(varchar,DayKeyId) + '|' + convert(varchar,DimCampaignId) + '|' + convert(varchar,DimLeadProviderId) + '|' + convert(varchar,fcd.DimCorpId) + '|' + 
         convert(varchar,CASE when DimLocationId in ('149','3','147') then 39
                              when DimLocationId in ('148','146') then 38
                              else DimVendorId end) + '|' + 
         convert(varchar,DimLocationId) + '|' + convert(varchar,DimEmployeeId) + '|' + convert(varchar,DimRateTypeId)
        ,DayKeyId
        ,DimCampaignId
        ,DimLeadProviderId
        ,fcd.DimCorpId
        ,CASE when DimLocationId in ('149','3','147') then 39
              when DimLocationId in ('148','146') then 38
              else DimVendorId end
        ,DimLocationId
        ,DimEmployeeId
        ,DimRateTypeId
        ,DimDispositionId
        ,fcd.LastUpdateDate

) AS ZZ
Where   DayKeyId in (
            Select  DayKeyId
            From    vw_dim_calendar
            Where   CurrentFiscalYear = 'Fiscal YTD'
            )
GO

Execution Plan

javascript – Recursive function to sort comments

I’ve got an array of comments with 4 properties: id, parent, content and comments. If a comment has a parent value of 0 it means that it is a top level comment and if it contains a number larger than 0 it will be the parents’ id and I’d like for the comment to be placed in the comments’ property of the parent. I’ve attempted to write a recursive TypeScript function to handle this but it duplicates certain comments as you can see in this screen shot:

Picture of the wrongly sorted comments

This is an example data-set and you can see my source code on thiscodesandbox.io:

[
  {
    id: 5819,
    parent: 0,
    content: "Waar vind ik meer?",
    comments: []
  },
  {
    id: 5820,
    parent: 5819,
    content: "Epic site!",
    comments: []
  },
  {
    id: 5821,
    parent: 5819,
    content: "Stoinks.",
    comments: []
  },
  {
    id: 5822,
    parent: 5821,
    content: "Can I get a what now?",
    comments: []
  },
  {
    id: 5823,
    parent: 0,
    content: "Yeeeee",
    comments: []
  }
];