Performance – Visual Basic for Applications – Array – Push | Pop | Shift | shift

I want to procedurally write my snake game and use as many windows as possible to practice. GetAsyncKeyState lets you capture keystrokes and play sound features. Also create a cute UI. Fun!

Shout to Bytecomb too, to give an example of how to traverse the array structure, and uses its code function to find ptr by element in array !!

Wrote that to practice!

DECLARATIONS AND FUNCTIONS

Option explicitly

Private Declare PtrSafe function VarPtrArray Lib "VBE7" Alias ​​"VarPtr" _
(ByRef Var () As Any) As LongPtr

Private Declare PtrSafe Sub CopyMemoryI Lib "kernel32.dll" Alias ​​"RtlMoveMemory" _
(ByVal dst as LongPtr, ByVal source as LongPtr, ByVal length as length)

Private Declare PtrSafe Sub CopyMemoryII Lib "kernel32.dll" Alias ​​"RtlMoveMemory" _
(ByRef dst As SAFEARRAY, ByVal src As LongPtr, ByVal length so long)

Private type SAFEARRAY_BOUND
cElements for so long
Tied so long
End Type

Private type SAFETY
cDims As Integer
fFeatures as an integer
cbElements so long
cLocks for so long
pvData As LongPtr
rgsabound (0) As SAFEARRAY_BOUND
End Type

Private Type Snake Party
Column so long
Line as long
End Type

Private Const SNAKEPART_BYTELENGTH = 8
Private SnakeParts () as SnakePart

Private Function ArrayPush (ByRef ArrayOriginal () as SnakePart, ByRef ElementToAdd as SnakePart) as SnakePart ()
Dim NewLength So long
Dim Copied Bytes As Long
Dim NewBytes so long

NewLength = UBound (ArrayOriginal) + 1
ReDim ArrayPush (NewLength)

CopiedBytes = UBound (ArrayOriginal) * SNAKEPART_BYTELENGTH
NewBytes = SNAKEPART_BYTELENGTH

CopyMemoryI ArrayElementGetPointer (ArrayPush, 0, SNAKEPART_BYTELENGTH), ArrayElementGetPointer (ArrayOriginal, 0, SNAKEPART_BYTELENGTH), CopiedBytes
CopyMemoryI ArrayElementGetPointer (ArrayPush, UBound (ArrayPush) - 1, SNAKEPART_BYTELENGTH), VarPtr (ElementToAdd), NewBytes
End function

Private Function ArrayPop (ByRef ArrayOriginal () As SnakePart) As SnakePart ()
Dim NewLength So long
Dim Copied Bytes As Long

NewLength = UBound (ArrayOriginal) - 1
ReDim ArrayPop (NewLength)

CopiedBytes = NewLength * SNAKEPART_BYTELENGTH

CopyMemoryI ArrayElementGetPointer (ArrayPop, 0, SNAKEPART_BYTELENGTH), ArrayElementGetPointer (ArrayOriginal (), 0, SNAKEPART_BYTELENGTH), CopiedBytes
End function

Private Function ArrayShift (ByRef ArrayOriginal () as SnakePart, ByRef ElementToAdd as SnakePart) as SnakePart ()
Dim NewLength So long
Dim Copied Bytes As Long
Dim NewBytes so long

NewLength = UBound (ArrayOriginal) + 1
ReDim ArrayShift (NewLength)

CopiedBytes = UBound (ArrayOriginal) * SNAKEPART_BYTELENGTH
NewBytes = SNAKEPART_BYTELENGTH

CopyMemoryI ArrayElementGetPointer (ArrayShift, 1, SNAKEPART_BYTELENGTH), ArrayElementGetPointer (ArrayOriginal, 0, SNAKEPART_BYTELENGTH), CopiedBytes
CopyMemoryI ArrayElementGetPointer (ArrayShift, 0, SNAKEPART_BYTELENGTH), VarPtr (ElementToAdd), NewBytes
End function

Private Function ArrayUnshift (ByRef ArrayOriginal () As SnakePart) As SnakePart ()
Dim NewLength So long
Dim Copied Bytes As Long

NewLength = UBound (ArrayOriginal) - 1
ReDim ArrayUnshift (NewLength)

CopiedBytes = NewLength * SNAKEPART_BYTELENGTH

CopyMemoryI ArrayElementGetPointer (ArrayUnshift, 0, SNAKEPART_BYTELENGTH), ArrayElementGetPointer (ArrayOriginal, 1, SNAKEPART_BYTELENGTH), CopiedBytes
End function

Private Function ArrayElementGetPointer (ByRef Arr () As SnakePart, ByVal ElementIndex As Long, ByVal ElementByteLength As Long) As LongPtr
Dim ptrToArrayVar As LongPtr
Dim ptrToSafeArray As LongPtr
Dim ptrToArrayData As LongPtr
Dim ptrCursor As LongPtr
Dim the SAFEARRAY as SAFEARRAY

# Retrieve pointer in array * variable *
ptrToArrayVar = VarPtrArray (Arr)
& # 39; retrieve pointer to array variable * SAFEARRAY * By directly reading array variable
CopyMemoryI VarPtr (ptrToSafeArray), ptrToArrayVar, 8
Read the SAFEARRAY structure
CopyMemoryII uSAFEARRAY, ptrToSafeArray, LenB (USA)
& # 39; Get pointer to array data
ptrToArrayData = uSAFEARRAY.pvData
Holen Get pointer to array element
ptrCursor = ptrToArrayData + (ElementIndex * ElementByteLength)
ArrayElementGetPointer = ptrCursor
End function

TESTING

Subtest functions ()

Dim Arr (10) As Snake Part
Eclipse SP as SnakePart
SP.Column = 4
SP.Row = 4
Arr (0) = SP
Debug.Print "Expect 4 x2"
Debug.Print Arr (0) .Column
Debug.Print Arr (0) .Row

Dim ArrTwo () as SnakePart

SP.Column = 8
SP.Row = 8
ArrTwo = ArrayPush (Arr, SP)

Debug.Print "Expect 4x2, followed by 8x2"
Debug.Print ArrTwo (0) .Column
Debug.Print ArrTwo (0) .Row
Debug.Print ArrTwo (10) .Column
Debug.Print ArrTwo (10) .Row

ArrTwo = ArrayPop (Arr)

Debug.Print "Expect 4x2, followed by 0x2"
Debug.Print ArrTwo (0) .Column
Debug.Print ArrTwo (0) .Row
Debug.Print ArrTwo (9) .Column
Debug.Print ArrTwo (9) .Row

SP.Column = 7
SP.Row = 7
ArrTwo = ArrayShift (ArrTwo, SP)

Debug.Print "Expect 7x2, followed by 4x2"
Debug.Print ArrTwo (0) .Column
Debug.Print ArrTwo (0) .Row
Debug.Print ArrTwo (1) .Column
Debug.Print ArrTwo (1) .Row

ArrTwo = ArrayUnshift (ArrTwo)

Debug.Print "Expect 4x2, followed by 0x2"
Debug.Print ArrTwo (0) .Column
Debug.Print ArrTwo (0) .Row
Debug.Print ArrTwo (1) .Column
Debug.Print ArrTwo (1) .Row

End Sub

history – Which developer has set the precedent for using the shift key for security (or skip) at startup?

Which developer created the precedent?

I started asking myself after I had reminded that Mozilla Firefox will start in safe mode when shift is held at application Start time. Predecessor … I am sure that Netscape Communications Corp. did not set the precedent since the first version of Netscape Navigator was released in 1994.

For Apple Computer, Inc. and uses of shift at or after system Startup, the first references I can find come from November 1991 and August 1992 (I started using Macs in January 1993). or:

… Peter Crownfiefd (about Zmac). …

… Found that holding the Shift key during startup not only bypasses the system extensions, but also bypasses items in the Start Items folder. If you want to load your extensions, but not the files in the Start Items folder, wait for all of your extensions to load and you will see the message "Welcome to Macintosh" and press the Shift key. Hold down the Shift key until the desktop appears. …

– https://archive.org/stream/MacUser9111November1991/MacUser_9111_November_1991_djvu.txt

… To block the opening of items in the System Startup Items folder of System 7, press the Shift key when the Finder menu headings appear for the first time in the menu bar during startup. To prevent additional loading of extensions from the Extensions folder. Press the SHIFT key and press Shift when the smiling Mac icon appears at the top of the startup sequence. You can release the Shift key after the message "Welcome to Macintosh" appears. …

– https://archive.org/stream/MacWorld_9208_August_1992/MacWorld_9208_August_1992_djvu.txt

Has Apple set the precedent?

Shortcuts – Google Docs Ctrl + Shift + L does not work

So Ctrl + shift + L does nothing in Google Docs, where Ctrl + shift + R and Ctrl + shift + e Job. I tried this on the same Google Doc but on my Chromebook, and it works. My laptop is Windows 10, so I thought something must be shortcut Ctrl + shift + L on my laptop overwriting the Google document, except that nothing happens. Is there a way to solve it?

Enabling Ctrl + Shift + V in the Windows Subsystem for Linux (WSL) / Command Prompt (cmd)

To enable Ctrl + Shift + V in Windows 10 Pro (version 1803, operating system build 17134.619)?

You are running the wrong version of Windows 10. The function in question is only a function of the update for October 2018 (1809). You are currently installing the update for April 2018.

You must upgrade to 1809 to enable the option in question

These keyboard shortcuts are available in the October 2018 update, which was originally codenamed Redstone 5.

Source: To enable copying and pasting shortcut keys in the Bash shell of Windows 10

Photoshop – Easy way to precisely align images with a slight shift in the node paths

There is no way to get up the pictures you have taken / posted, However, there is absolutely one way to set the camera and tripod so that you can take perfectly aligned pictures for panoramas.

What you experience is known as parallaxand the technique involves finding the no parallax point the lens. At a minimum, you'll need a camera mount that can be rotated and a way to position a camera arbitrarily forward or backward on the rotation mount. A tripod with swivel function or a ball head with swivel axis is sufficient for mounting. Ideally, use a stapling mechanism to slide forward, with the camera mounted on a rail that can be positioned forward / backward in the bracket.

The setup looks like this:

Enter the image description here
Setup for a single-row panorama. From ReallyRightStuff.com

A note about terminology:

The position of the point without parallax is the center of the point admission students the lens. Often the NPP is referred to as a "node", or in your case there is a "nodal misalignment". This is not absolutely correct. The nodal points of a lens do not match the entrance pupil. Nevertheless, the wrong names (especially for the brand "Nodal Ninja") of Panorama tools remain on the market.

The technique for finding the parallax zero has been well documented here and in various places on the Internet.

Large descriptions of the technique (s) for locating the NPP:

Here's a handy cheat sheet for adjustments to find the point without parallax:

Enter the image description here
No parallax point: NPP investigation, by Henrik Fessler. CC BY-NC-SA 3.0

Device Recommendation – With which rail can I build a center camera with a tilt shift?

I'm building a medium format camera that uses 120 movies and contains several digital and video parts. The final picture format is 6×45 cm.
I would like to mount the lens on a rail that allows tilting and shifting, allowing me to focus from macro to infinity, and fitting their brackets to the body and lens I want to use.
Many commercial bellows (Canon Auto Bellows, etc.) are a good start, but do not allow tilting / shifting.

What is a good rail with bellows, with which I could build the camera like this?

c – Change the arithmetic right shift to the logical right shift

The following is a solution to a textbook problem (Bryant & O & # 39; Hallaron: Computer Systems Perspectives 2 Ed. Ed.) In bit-level data manipulation (trying for the challenge, not a class). The function srl is not necessarily written in a practical way, but within the constraints required by the problem.

ask

Is there a clearer, easier way to write this? within the required limitations of the problem (maybe with fewer operations)?

It is necessary to avoid undefined behavior of the left shift if k = 0. In this case, int_bits – k = int_bits, causing the shift to be unpredictable. Is there a better way to handle the undefined behavior of the shift operations when the shift is greater than the number of bits in the interger?

It seems to work properly, but I do not have an answer, so I would appreciate feedback on the solution.

requirement

  • In addition to the specified expression, no additional right shifts or type conversions may be used

            / * Perform arithmetic shift * /
    unsigned xsra = (int) x >> k;
    
  • Only addition or subtraction may be used, no multiplication, division or modulus

  • No comparison operators and no conditions

  • Only bitwise operations (other than right-shift) and logical operators can be used

code

unsigned srl (unsigned x, int k) {
/ * Perform arithmetic shift * /
unsigned xsra = (int) x >> k;

unsigned int_bits = sizeof (int) << 3; // computes the number of bits in int (assumes an 8-bit byte)

unsigned zero_or_all_bits = ~ 0 +! k; // for k = 0 corrects the undefined behavior in
// the left shift of int_bits - k = int_bits
// if k! = 0 ,! k == 0 and zero_or_all_bits == ~ 0
// if k == 0, zero_or_all_bits == 0

unsigned high_bit_mask = ~ (zero_or_all_bits << (zero_or_all_bits & (int_bits - k)));
/ ***************************************************************
// creates a mask of all bits set in an unsigned int (UINT_MAX)
// or a mask whose k high bits are cleared.
// if k == 0, then high_bit_mask = ~ (0 << 0) = ~ 0.
// if k! = 0, then high_bit_mask = ~ (~ 0 << (~ 0 & (int_bits - k)))
//Ex. k = 3, high_bit_mask == 0x1FFFFFFF
//Ex. k == 0, high_bit_mask == 0xFFFFFFFF
//Ex. k = 31, high_bit_mask = 0xFFFFFFFE
/ ***************************************************************

Return xsra & high_bit_mask;

}


test code

printf ("Test srl:  n");
printf ("srl (-1, 1): 0x% .8x  n", srl (-1, 1));
printf ("srl (-1, 4): 0x% .8x  n", srl (-1, 4));
printf ("srl (-1, 5): 0x% .8x  n", srl (-1, 5));
printf ("srl (-1, 31): 0x% .8x  n", srl (-1, 31));
printf ("srl (-1, 0): 0x% .8x  n", srl (-1, 0));

printf ("srl (0x7FFFFFFF, 1): 0x% .8x  n", srl (0x7FFFFFFF, 1));
printf ("srl (0x7FFFFFFF, 4): 0x% .8x  n", srl (0x7FFFFFFF, 4));
printf ("srl (0x7FFFFFFF, 5): 0x% .8x  n", srl (0x7FFFFFFF, 5));
printf ("srl (0x7FFFFFFF, 31): 0x% .8x  n", srl (0x7FFFFFFF, 31));
printf ("srl (0x7FFFFFFF, 0): 0x% .8x  n", srl (0x7FFFFFFF, 0));

printf ("srl (0x80000000, 1): 0x% .8x  n", srl (0x80000000, 1));
printf ("srl (0x80000000, 4): 0x% .8x  n", srl (0x80000000, 4));
printf ("srl (0x80000000, 5): 0x% .8x  n", srl (0x80000000, 5));
printf ("srl (0x80000000, 31): 0x% .8x  n", srl (0x80000000, 31));
printf ("srl (0x80000000, 0): 0x% .8x  n", srl (0x80000000, 0));

printf ("srl (0, 1): 0x% .8x  n", srl (0, 1));
printf ("srl (0, 4): 0x% .8x  n", srl (0, 4));
printf ("srl (0, 5): 0x% .8x  n", srl (0, 5));
printf ("srl (0, 31): 0x% .8x  n", srl (0, 31));
printf ("srl (0, 0): 0x% .8x  n", srl (0, 0));

printf ("srl (1, 1): 0x% .8x  n", srl (1, 1));
printf ("srl (1, 4): 0x% .8x  n", srl (1, 4));
printf ("srl (1, 5): 0x% .8x  n", srl (1, 5));
printf ("srl (1, 31): 0x% .8x  n", srl (1, 31));
printf ("srl (1, 0): 0x% .8x  n", srl (1, 0));

output

Test srl:
srl (-1, 1): 0x7fffffff
srl (-1, 4): 0x0fffffff
srl (-1, 5): 0x07ffffff
srl (-1, 31): 0x00000001
srl (-1, 0): 0xffffffff
srl (0x7FFFFFFF, 1): 0x3fffffff
srl (0x7FFFFFFF, 4): 0x07ffffff
srl (0x7FFFFFFF, 5): 0x03ffffff
srl (0x7FFFFFFF, 31): 0x00000000
srl (0x7FFFFFFF, 0): 0x7fffffff
srl (0x80000000, 1): 0x40000000
srl (0x80000000, 4): 0x08000000
srl (0x80000000, 5): 0x04000000
srl (0x80000000, 31): 0x00000001
srl (0x80000000, 0): 0x80000000
srl (0, 1): 0x00000000
srl (0, 4): 0x00000000
srl (0, 5): 0x00000000
srl (0, 31): 0x00000000
srl (0, 0): 0x00000000
srl (1, 1): 0x00000000
srl (1, 4): 0x00000000
srl (1, 5): 0x00000000
srl (1, 31): 0x00000000
srl (1, 0): 0x00000001

SQL Server – Employee Shift Check – Nested cursor

I have a query that returns the availability of an employee (only on days when they are available).

SELECT emp_id, emp_number, area, day_date, shift_type, start_time, finish_time FROM employee availability

I also have a query that gives me all available workdays between two appointments that I have written as CTE.

WITH AvailableDates

AS (SELECT DATETIMEFROMPARTS (DATEPART (YEAR, Available Date))
, DATEPART (MM, available date)
, DATEPART (DAY, AvailableDate)
, 0,0,0,0) as available date
FROM (
SELECT TOP (DATEDIFF (DAY, & # 39; 2019-01-14 00: 00: 00.000 & # 39 ;, & # 39; 2019-01-21 00: 00: 00.000 & # 39;) + 1)
AvailableDate = DATEADD (DAY, ROW_NUMBER () OVER (ORDER BY a.object_id) - 1, & # 39; 2019-01-14 00: 00: 00.000 & # 39;)
FROM sys.all_objects a
CROSS JOIN sys.all_objects b) Availability data

)

I need to check staff availability against available data and create an unavailable record for the days they do not have a scheduled shift

But when I join these dates, I get the following.

Returned records

My thoughts are to write a nested cursor to check the date and the employee. Is there a better way to create a record using emp_id, emp_Number, area, and availableDate?

thank you in advance