## c # – API Layer ClientId and security style

I am at the point where I am designing my API security and I was using a custom attribute. I don't want to use third party systems as they cost money.

I was going to use the customer id and secret id approach and ask him if it is a secure enough way to do it. I am interacting with my API through a database layer.

So the first thing to be called is this bit of code that comes out to find a match to the db and then it is called by the controller

``````public bool FindKeysByClientIdByApiKey(Guid apiKey, Guid clientId)

{

ApiKeys results = new ApiKeys();

using (var connection = new SqlConnection(constr))

{

return connection.Query(\$"SELECT * FROM {schemaDefination}.(ApiKeys) where ClientId= @ClientId and ApiKey=@ApiKey and isActive=1 and isDeleted!=1",

new { ApiKey = apiKey, ClientId = clientId }).Any();

}

}
``````

Controller code

``````public class ApiKeysController : ControllerBase

{

DBContext db = new DBContext();

(HttpGet)

public int Get(Guid ApiKey, Guid ClientdId)

{

if (!db.FindKeysByClientIdByApiKey(ApiKey, ClientdId))  {

return StatusCodes.Status401Unauthorized;

}else

return StatusCodes.Status200OK;

}

}
``````

To enable or disable this at will, I am creating a custom attribute that will have the following.

``````public async  Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)

{

//before

{

context.Result = new UnauthorizedResult();

return;

}

// before

{

context.Result = new UnauthorizedResult();

return;

}

var getConfigurationResult = Do Stuff here

await next();

//after

}
``````

This should mean that I can simply call the attribute on my controller if this method works fine. I'm assuming this method will also allow me to decorate my Gets and Puts to make sure they are also authorized to get what I need to return in ApiControllers so I can make it more generic

(API key)

## style guide – Style guides: In which category are breadcrumb menus included?

I would put breadcrumbs as part of interactive user interface design in category Interactionor even deeper into navigation. See the rational and example scheme explained below:

### Taxonomy for elements

All the elements contained in the style guide have their characteristics and purpose. Some are characterized by static properties such as font and color. They serve a broad common purpose, such as corporate identity. Others are dynamic in nature and serve a dedicated use case, such as navigating menus or entering data through forms.

They range in scope from common applicability to specific use cases. Size and font can be commonly used on specific elements like buttons and headers.

Therefore, a taxonomy or schematic separation into categories depends on important characteristics or scope of use that is unique to its context.

### An example scheme

• Visual styles: colors, fonts, sizes, spaces, logos, icons
• Content elements:
• media (image, video, sound)
• Interaction elements:
• Input elements: forms, fields, buttons.

These taxonomies can be interleaved, as content elements can use a defined visual style (font, spacing) or buttons or links (to display, jump).
On the other hand, different styles can be applied to the interaction elements. For example, a breadcrumb path that has less space or a differently shaped border than that defined in the general visual style.

It is important to note: interactive elements are characterized not only by their visual style, but also by consistent behavior and visual changes depending on their state (for example, by hovering, clicking) This dynamic should also be covered by a style guide.

### The structure depends on the use

There is no golden rule on how to outline or organize UI elements within a style guide. Rather, the structure depends on the target readers and their requirements for using it:

As stated in Toptal's post:

It is important to understand that there is no one-size-fits-all approach.

This tip suggests asking users of the style guide about their tasks and needs. What do they seek? How do they expect to be guided? What questions do you ask if it's about UI style and design?

## c ++ – Create OpenGL 4 context for WinAPI (Core and new – style context)

I'm trying to create a new style context OpenGL 4.2 in kernel mode for Windows OS (using WinAPI). My code is work:

``````#include
#include
#include
#include

using GLchar = char;
using DEBUGPROC = void (APIENTRY*)(GLenum source,
GLenum type,
GLuint id,
GLenum severity,
GLsizei length,
const GLchar * message,
const void* userParam);
using GlDebugMessageCallback = void(APIENTRY*)(DEBUGPROC callback,
const void* userParam);
using WglCreateContextAttribsARB = HGLRC(APIENTRY*)(HDC, HGLRC, const int*);
using WglSwapIntervalEXT = BOOL(WINAPI*)(int interval);

#define GL_DEBUG_SOURCE_API               0x8246
#define GL_DEBUG_SOURCE_WINDOW_SYSTEM     0x8247
#define GL_DEBUG_SOURCE_THIRD_PARTY       0x8249
#define GL_DEBUG_SOURCE_APPLICATION       0x824A
#define GL_DEBUG_SOURCE_OTHER             0x824B
#define GL_DEBUG_TYPE_ERROR               0x824C
#define GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR 0x824D
#define GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR  0x824E
#define GL_DEBUG_TYPE_PORTABILITY         0x824F
#define GL_DEBUG_TYPE_PERFORMANCE         0x8250
#define GL_DEBUG_TYPE_OTHER               0x8251
#define GL_DEBUG_TYPE_MARKER              0x8268
#define GL_DEBUG_TYPE_PUSH_GROUP          0x8269
#define GL_DEBUG_TYPE_POP_GROUP           0x826A
#define GL_DEBUG_LOGGED_MESSAGES          0x9145
#define GL_DEBUG_SEVERITY_HIGH            0x9146
#define GL_DEBUG_SEVERITY_MEDIUM          0x9147
#define GL_DEBUG_SEVERITY_LOW             0x9148
#define GL_DEBUG_OUTPUT                   0x92E0
#define WGL_CONTEXT_CORE_PROFILE_BIT_ARB            0x00000001
#define WGL_CONTEXT_DEBUG_BIT_ARB                   0x0001
#define WGL_CONTEXT_FLAGS_ARB                       0x2094
#define WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB      0x0002
#define WGL_CONTEXT_LAYER_PLANE_ARB                 0x2093
#define WGL_CONTEXT_MAJOR_VERSION_ARB               0x2091
#define WGL_CONTEXT_MINOR_VERSION_ARB               0x2092

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
void APIENTRY glDebugOutput(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message, const void* userParam);

int width = 750;
int height = 500;

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
// init window
WNDCLASSEX wc;
HWND hwnd;
MSG msg;
ZeroMemory(&wc, sizeof(WNDCLASSEX));
wc.cbSize = sizeof(WNDCLASSEX);
wc.lpfnWndProc = WndProc;
wc.hInstance = hInstance;
wc.hbrBackground = (HBRUSH)(COLOR_GRAYTEXT);
wc.lpszClassName = "windowGL";
if (!RegisterClassEx(&wc))
return 0;
hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
"windowGL",
"The title Win32GL",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, width, height,
NULL, NULL, hInstance, NULL);

// init gl
HGLRC hRC;
HDC hDC = GetDC(hwnd);
int pf = 0;
PIXELFORMATDESCRIPTOR pfd = { 0 };
pfd.nSize = sizeof(pfd);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 24;
pfd.cDepthBits = 16;
pfd.iLayerType = PFD_MAIN_PLANE;
pf = ChoosePixelFormat(hDC, &pfd);
SetPixelFormat(hDC, pf, &pfd);

int flags() = { WGL_CONTEXT_MAJOR_VERSION_ARB, 4,
WGL_CONTEXT_MINOR_VERSION_ARB, 4,
WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB | WGL_CONTEXT_DEBUG_BIT_ARB,
0 };

// make context
HGLRC TempRC = wglCreateContext(hDC);
wglMakeCurrent(hDC, TempRC);
hRC = wglCreateContextAttribsARB(hDC, 0, flags);
wglMakeCurrent(hDC, hRC);
wglDeleteContext(TempRC);

// vsync
wglSwapIntervalEXT(0);

// gl debug
glEnable(GL_DEBUG_OUTPUT);
glDebugMessageCallback(glDebugOutput, 0);

ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
try
{
while (true)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if (msg.message == WM_QUIT)
break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
glClearColor(0.8f, 0.5f, 0.9f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
SwapBuffers(hDC);
}
}
}
catch (const std::exception & e)
{
MessageBox(NULL, e.what(), "Error!", MB_ICONERROR);
return -1;
}
return 0;
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_SIZE:
width = LOWORD(lParam);
height = HIWORD(lParam);
glViewport(0, 0, width, height);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}

void APIENTRY glDebugOutput(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message, const void* userParam)
{
if (id == 131169 || id == 131185 || id == 131218 || id == 131204)
return;

std::stringstream error;
error << "---------------" << std::endl;
error << "Debug message (" << id << "): " << message << std::endl;

switch (source)
{
case GL_DEBUG_SOURCE_API:
error << "Source: API";
break;
case GL_DEBUG_SOURCE_WINDOW_SYSTEM:
error << "Source: Window System";
break;
break;
case GL_DEBUG_SOURCE_THIRD_PARTY:
error << "Source: Third Party";
break;
case GL_DEBUG_SOURCE_APPLICATION:
error << "Source: Application";
break;
case GL_DEBUG_SOURCE_OTHER:
error << "Source: Other";
break;
}
error << std::endl;

switch (type)
{
case GL_DEBUG_TYPE_ERROR:
error << "Type: Error";
break;
case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR:
error << "Type: Deprecated Behaviour";
break;
case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR:
error << "Type: Undefined Behaviour";
break;
case GL_DEBUG_TYPE_PORTABILITY:
error << "Type: Portability";
break;
case GL_DEBUG_TYPE_PERFORMANCE:
error << "Type: Performance";
break;
case GL_DEBUG_TYPE_MARKER:
error << "Type: Marker";
break;
case GL_DEBUG_TYPE_PUSH_GROUP:
error << "Type: Push Group";
break;
case GL_DEBUG_TYPE_POP_GROUP:
error << "Type: Pop Group";
break;
case GL_DEBUG_TYPE_OTHER:
error << "Type: Other";
break;
}
error << std::endl;

switch (severity)
{
case GL_DEBUG_SEVERITY_HIGH:
error << "Severity: high";
break;
case GL_DEBUG_SEVERITY_MEDIUM:
error << "Severity: medium";
break;
case GL_DEBUG_SEVERITY_LOW:
error << "Severity: low";
break;
break;
}
error << std::endl;
error << std::endl;

throw std::runtime_error("Error render OpenGL: n" + error.str());
}
``````

All error handling was skipped. The application works and renders the image. Questions:

1) Am I creating the context in the new style correctly?

2) if I start the bandicam and msi afterburner application, with my application blocked. Error:

``````Debug message (1282): Error has been generated. GL error GL_INVALID_OPERATION in PushAttrib: (ID: 3950967337) Generic error
Source: API
Type: Error
Severity: high
``````

3) If I try to enable wireframe mode, with my app locked

``````glPolygonMode(GL_FRONT, GL_LINE);
glPolygonMode(GL_BACK, GL_LINE);
``````

Error:

``````Debug message (1280): Error has been generated. GL error GL_INVALID_ENUM in PolygonMode: (ID: 213353305) Generic error
Source: API
Type: Error
Severity: high
``````

Why?

Thank you

## 2016: can we add style library resources (CSS, JS, images) on SharePoint anonymous app page?

I have created a SharePoint app page in SharePoint 2016. This page is anonymous.

I have used some style library resources on this page, but when I open this page it is redirecting me to the login page. I'm assuming this behavior is because you can't access the resources of the style library I'm using on the app page.

Remember that the site does not have anonymous access.

## ux integration: how to collaborate and define a new style guide for an existing corporate design?

As a naive ux designer, I am having trouble defining a style guide. There is an existing style guide made with Adobe XD. As a team effort, we would like to improve and manage the style guide. A reasonable and productive solution is to use Frontify. Unfortunately, the company runs out of budget and we need to look for an alternative that can provide the same features as Frontify.

Does anyone face the same problem?

## Microsoft Word: how to create a paragraph style that only affects certain properties

Using MSWord 2010.
I want to apply the character font, italics, and background across the edges to the entire paragraph without having to select all the characters in the paragraph.
In other words, I want to place my cursor anywhere in the paragraph and assign the style and the paragraph reacts and follows through.

I can't seem to use MS-Word Paragraph style for this purpose, since you want to impact everything, such as the current level of bullet / number indentation …
I want the paragraph style to be as "additive" to the current paragraph style, which may already be numbered and indented level 2.

Currently, the behavior is that the custom "To Style" causes the current paragraph to return to Normal if I base it on Normal. It is as if I wanted to say that the custom style is based on the current style and not on a specific style (normal or not).

Hopefully you've made it clear to me. Thanks for any pointers.

NOTE: We could write a macro to first select all the characters in para and assign a "Character Style" but it sounds ugly. New inserted / pasted characters will probably not adopt the style.

## typescript – Opinion on the encoding style for the method that performs the action of creating a Json Object

So I had a discussion with my superior about a code saying that the code could have `switch` Logic within put in another method to increase its readability.

Now I have a hard time understanding how readability increases if you change the `switch` log into that method to another method. I mentioned that this code has a single purpose.

What I'd like to know is if there is a better way to accomplish the purpose, and the reasoning behind it, and how can you help other developers on the team.

Below are two sets of codes that he had originally written and modified after having a discussion with the senior. I have do not did the separating code `switch` logic in another method.

Original code

``````  createGoalObj() {
let obj = {
"clientId": this.clientId,
"goalName": this.singleYearGoalForm.get('field4').value,
"notes": this.singleYearGoalForm.get('field5').value,
"imageUrl": this.logoImg
}
/**
* goal ids
* 2 - house
* 3 - car
* 4 - marriage
* 7 - emergency
* 8 - wealth creation
* 9 - big spend
* 10 - others
*/
if((2,4,8).includes(this.goalTypeData.id)) {
obj('planningThisForId') = this.singleYearGoalForm.get('field1').value.id;
obj('clientOrFamilyMember') = (this.singleYearGoalForm.get('field1').value.relationshipId === 0) ? 1 : 2;
}
if((2,3,4,8).includes(this.goalTypeData.id)) {
obj('currentAge') = this.singleYearGoalForm.get('field1').value.age;
}
if((2,3,4,9,10).includes(this.goalTypeData.id)) {
obj('goalPresentValue') = this.singleYearGoalForm.get('field3').value;
}
switch (this.goalTypeData.id) {
case 2: // House
break;
case 3: // Car
break;
case 4: // Marriage
obj('marryAtAge') = this.singleYearGoalForm.get('field2').value;
break;
case 7: // Emergency
obj('goalTargetInMonth') = this.singleYearGoalForm.get('field2').value;
obj('goalFV') = this.singleYearGoalForm.get('field3').value;
break;
case 8: // Wealth Creation
obj('goalTargetAge') = this.singleYearGoalForm.get('field2').value;
obj('goalFV') = this.singleYearGoalForm.get('field3').value;
break;
case 9: // Big Spends
obj('goalStartDate') = this.singleYearGoalForm.get('field2').value;
break;
case 10: // Others
obj('goalStartDate') = this.singleYearGoalForm.get('field2').value;
break;
default:
console.error('unknown goal id found')
}
return obj;
}
``````

``````  createGoalObj() {
let obj = {
"clientId": this.clientId,
"goalName": this.singleYearGoalForm.get('field4').value,
"notes": this.singleYearGoalForm.get('field5').value,
"imageUrl": this.logoImg
}

switch (this.goalTypeData.id) {
case 2: // House
obj('currentAge') = this.singleYearGoalForm.get('field1').value.age;
obj('planningThisForId') = this.singleYearGoalForm.get('field1').value.id;
obj('clientOrFamilyMember') = (this.singleYearGoalForm.get('field1').value.relationshipId === 0) ? 1 : 2;
obj('goalPresentValue') = this.singleYearGoalForm.get('field3').value;
break;
case 3: // Car
obj('currentAge') = this.singleYearGoalForm.get('field1').value.age;
obj('goalPresentValue') = this.singleYearGoalForm.get('field3').value;
break;
case 4: // Marriage
obj('currentAge') = this.singleYearGoalForm.get('field1').value.age;
obj('planningThisForId') = this.singleYearGoalForm.get('field1').value.id;
obj('clientOrFamilyMember') = (this.singleYearGoalForm.get('field1').value.relationshipId === 0) ? 1 : 2;
obj('marryAtAge') = this.singleYearGoalForm.get('field2').value;
obj('goalPresentValue') = this.singleYearGoalForm.get('field3').value;
break;
case 7: // Emergency
obj('goalTargetInMonth') = this.singleYearGoalForm.get('field2').value;
obj('goalFV') = this.singleYearGoalForm.get('field3').value;
break;
case 8: // Wealth Creation
obj('currentAge') = this.singleYearGoalForm.get('field1').value.age;
obj('planningThisForId') = this.singleYearGoalForm.get('field1').value.id;
obj('clientOrFamilyMember') = (this.singleYearGoalForm.get('field1').value.relationshipId === 0) ? 1 : 2;
obj('goalTargetAge') = this.singleYearGoalForm.get('field2').value;
obj('goalFV') = this.singleYearGoalForm.get('field3').value;
break;
case 9: // Big Spends
obj('goalStartDate') = this.singleYearGoalForm.get('field2').value;
obj('goalPresentValue') = this.singleYearGoalForm.get('field3').value;
break;
case 10: // Others
obj('goalStartDate') = this.singleYearGoalForm.get('field2').value;
obj('goalPresentValue') = this.singleYearGoalForm.get('field3').value;
break;
default:
console.error('unknown goal id found');
}
return obj;
}
$$```$$
``````

## encoding style: is it wrong to get out of a tagged block in java?

Sometimes I write Java code that looks like:

``````success: {
fail: {
if (...) break fail;
// some code
if (...) break fail;
// some code
if (...) break fail;
// some code
break success;
}
// failure handling code
}
``````

Is this a bad practice? I could extract this to a method that returns a `Optional`, and then call that method from the main method, but I'm concerned that this is bad for performance.

## coding style: Python scripts: to use the class or not, what is the best practice?

I'm seeking feedback from the community (Python) on style and maintainability. Note the sample script below that declaratively solve a certain problem:

Script v1

``````def take_path_a(param_1, param_2):

# the full implementation is irrelevant
pass

def take_path_b(param_1, param_2):

# the full implementation is irrelevant
pass

def start(path_decision_factor_1, path_decision_factor_2):

path_a_is_optimal = path_decision_factor_1 is "whatever"

take_path_a(path_decision_factor_1, path_decision_factor_2) if path_a_is_optimal else take_path_b(path_decision_factor_1, path_decision_factor_2)

if __name__ == "__main__":

start("param_1", "param_2")
``````

The actual script modeled by the previous example will finally deploy cloud resources with variable characteristics depending on the path you take during the script runtime.

Questions:

1. Is the above script readable?

2. Where in fact there is no agreed style or paradigm, and considering that taxpayers have mentioned that there is no need to adhere to a particular style, I do sensation that the script would improve significantly if included in a class. Honestly, I generally feel comfortable working with classes, but I also see that designing `param_1` Y `param_2` since the object states that can be shared through potentially more methods of the prospective class make more sense or feel good, aren't these perceptions a valid ground to block public relations?

3. Python is an object-oriented language, is it a good practice to accept scripts that are out of the norms like above?

This is how I would prefer to accept the script:

Script v2

``````class ActionTaker:

def __init__(self, param_1, param_2):

self.param_1 = param_1
self.param_2 = param_2

def _take_path_a(self):

# the full implementation is irrelevant
pass

def _take_path_b(self):

# the full implementation is irrelevant
pass

def start(self):

if self.param_1 is "whatever":
self._take_path_a()
else:
self._take_path_b()

if __name__ == "__main__":

action_taker = new ActionTaker("param_1", "param_2")
action_taker.start()
``````

How can I convince a developer to stop writing with style in Script v1 since it doesn't seem standard?

## statistics – Writing style: how to distinguish between estimators as random variables and estimates calculated from ONE experimental result

In writing procedural hypothesis tests, I try to follow the convention that capital letters $$X, Y$$ represents random variables (RV) and lowercase letters $$x, y$$ represents the result of ONE experiment, that is, a sample. However, I find that I have some difficulty doing it due to lack of notation.

To give an example of two samples $$t$$-test:

From the data provided, the unbalanced estimators $$hat sigma ^ 2_1 = 56.4$$, $$hat sigma ^ 2_2 = 53.4$$. (Just one example, the numbers are given at random.) Therefore, the pooled estimate of the variance of the samples (assuming that both samples have the same variance) is
$$s_p ^ 2 = frac {(n_1-1) hat sigma ^ 2_1 + (n_2-1) hat sigma ^ 2_2} {n_1 + n_2-2} = 54.0$$
The test statistic is
$$t = frac { bar y- bar x} {s_p (1 / n_1 + 1 / n_2) ^ {1/2}} = 1.24$$
Now, $$(n_k-1) hat sigma ^ 2_k / sigma ^ 2$$ follow $$chi ^ 2$$ degree of freedom distribution $$n_k-1$$, … (to be continue)

Here I run into a problem. I already give $$sigma ^ 2_1$$ a specific value $$56.4$$so i can't really say that $$(n_k-1) hat sigma ^ 2_k / sigma ^ 2$$ follow $$chi ^ 2$$ distribution. I must replace $$sigma ^ 2_k$$ by a capital letter, $$Sigma ^ 2_k$$, to distinguish between the value obtained from an experiment and the RV itself. However, I never see $$Sigma ^ 2_k$$ before, it looks very strange.

Let's continue.

Leave $$sigma$$ be the common variance of $$X$$ Y $$Y$$. Now, $$(n_k-1) hat sigma ^ 2_k / sigma ^ 2$$ follow $$chi ^ 2$$ degree of freedom distribution $$n_k-1$$, so $$(n_1 + n_2-2) S_p ^ 2 / sigma ^ 2$$ follow $$chi ^ 2$$ degree of freedom distribution $$n_1 + n_2-2$$. Therefore, we can conclude that
$$T = frac { bar Y- bar X} {S_p (1 / n_1 + 1 / n_2) ^ {1/2}}$$
follows a student distribution of the degree of freedom $$nu = n_1 + n_2-2$$. Now we can check the critical value of the table …

The rest shouldn't be a problem. by $$X, Y, S_p$$, the capital letters are quite easy to use.

Question: What should I use for the "capital" $$hat sigma$$? If i use $$S$$, then it could be confused with the moments.