Posts

Building A Great Dashboard App In WPF -- What Are The Controls Available Out There?

Answer : Check out the WPF Dashboard demo. It comes with source code. Also the WPF Dashboard project on codeplex. The Infragistics Dashboard demo is nice as well. My decision was to take the DragDockPanel from the Blacklight project. It's both WPF and Silverlight-enabled.

Combine Calc() With Attr() In CSS

Answer : Right now attr() is not supported by default in any major browser for any attributes other then "content". Read more about it here: https://developer.mozilla.org/en-US/docs/Web/CSS/attr There appears to be a way around it using var s .content{ --x: 1; width: calc(100px * var(--x)); background: #f00; } [data-x="1"] { --x: 1; } [data-x="2"] { --x: 2; } [data-x="3"] { --x: 3; } /*doesn't look like this works unfortunately [data-x] { --x: attr(data-x); } seems to set all the widths to some really large number*/ The commented out section would have been perfect, and this may be the very same reason your idea didn't work, but it seems css doesn't perform the nice automatic casting that you might be used to in javascript ( '2' * 3 //=6 ). attr() returns a string, not a number, and this can be seen by adding .content:after { content:var(--x) } ; nothing gets printed, --x is a number, content accepts s...

Advantages Of Binary Search Trees Over Hash Tables

Answer : One advantage that no one else has pointed out is that binary search tree allows you to do range searches efficiently. In order to illustrate my idea, I want to make an extreme case. Say you want to get all the elements whose keys are between 0 to 5000. And actually there is only one such element and 10000 other elements whose keys are not in the range. BST can do range searches quite efficiently since it does not search a subtree which is impossible to have the answer. While, how can you do range searches in a hash table? You either need to iterate every bucket space, which is O(n), or you have to look for whether each of 1,2,3,4... up to 5000 exists. (what about the keys between 0 and 5000 are an infinite set? for example keys can be decimals) Remember that Binary Search Trees (reference-based) are memory-efficient. They do not reserve more memory than they need to. For instance, if a hash function has a range R(h) = 0...100 , then you need to allocate an array of...

Accessing The Web Page's HTTP Headers In JavaScript

Answer : It's not possible to read the current headers. You could make another request to the same URL and read its headers, but there is no guarantee that the headers are exactly equal to the current. Use the following JavaScript code to get all the HTTP headers by performing a get request: var req = new XMLHttpRequest(); req.open('GET', document.location, false); req.send(null); var headers = req.getAllResponseHeaders().toLowerCase(); alert(headers); Unfortunately, there isn't an API to give you the HTTP response headers for your initial page request. That was the original question posted here. It has been repeatedly asked, too, because some people would like to get the actual response headers of the original page request without issuing another one. For AJAX Requests: If an HTTP request is made over AJAX, it is possible to get the response headers with the getAllResponseHeaders() method. It's part of the XMLHttpRequest API. To see how this can be ap...

ASN.1 Vs JSON When Is Is Appropriate To Use Them?

Answer : ASN.1 and JSON aren't strictly comparable. JSON is a data format. ASN.1 is a schema language plus multiple sets of encoding rules, each of which produces different data formats for a given schema. So, the original question somewhat parallels the question "XML Schema vs. XML: when is it appropriate to use them?" A fairer comparison would be between ASN.1 and JSON Schema. That said, a few points to consider: ASN.1 has binary encoding rules. Consider whether binary or text encoding is preferable for your application. ASN.1 also has XML and JSON encoding rules. You can opt to go with a text-based encoding using ASN.1, if you like. ASN.1 allows other encoding rules to be developed. Before ITU-T specified encoding rules for JSON, we specified our own rules to encode ASN.1 to JSON. I blogged about this on our company website here As with XML Schema, tools exist for compiling ASN.1. These are commonly referred to as data binding tools. The compiler ...

Code Folding In Bookdown

Answer : Global Hide/Show button for the entire page To use @Yihui's hint for a button that fold all code in the html output, you need to paste the following code in an external file (I named it header.html here): Edit: I modified function toggle_R so that the button shows Hide Global or Show Global when clicking on it. <script type="text/javascript"> // toggle visibility of R source blocks in R Markdown output function toggle_R() { var x = document.getElementsByClassName('r'); if (x.length == 0) return; function toggle_vis(o) { var d = o.style.display; o.style.display = (d == 'block' || d == '') ? 'none':'block'; } for (i = 0; i < x.length; i++) { var y = x[i]; if (y.tagName.toLowerCase() === 'pre') toggle_vis(y); } var elem = document.getElementById("myButton1"); if (elem.value === "Hide Global") elem.value = "Show Global"; else ...

How To Make A Sleep Function In C Code Example

Example 1: sleep in c programming //sleep function provided by <unistd.h> # include <stdio.h> # include <stdlib.h> # include <unistd.h> int main ( ) { printf ( "Sleeping for 5 seconds \n" ) ; sleep ( 5 ) ; printf ( "Wake up \n" ) ; } Example 2: how to sleep in c # include <stdio.h> # include <stdlib.h> # include <unistd.h> int main ( ) { printf ( "Sleeping for 5 seconds \n" ) ; sleep ( 5 ) ; printf ( "Sleep is now over \n" ) ; } Example 3: use sleep in c in windows # include <Windows.h> int main ( ) { Sleep ( 500 ) ; }

Install Prettier Vscode Code Example

Example 1: prettier config vscode npm install -- save - dev -- save - exact prettier Example 2: prettier on save vscode // Set the default"editor.formatOnSave": false,// Enable per-language"[javascript]": { "editor.formatOnSave": true} Example 3: enable prettier vscode ext install esbenp . prettier - vscode Example 4: prettier install in vscode Install node . js first

"Cannot Drop Database Because It Is Currently In Use". How To Fix?

Answer : The problem is that your application probably still holds some connection to the database (or another application holds connection as well). Database cannot be deleted where there is any other opened connection. The first problem can be probably solved by turning connection pooling off (add Pooling=false to your connection string) or clear the pool before you delete the database (by calling SqlConnection.ClearAllPools() ). Both problems can be solved by forcing database to delete but for that you need custom database initializer where you switch the database to single user mode and after that delete it. Here is some example how to achieve that. I was going crazy with this! I have an open database connection inside SQL Server Management Studio (SSMS) and a table query open to see the result of some unit tests. When re-running the tests inside Visual Studio I want it to drop the database always EVEN IF the connection is open in SSMS. Here's the definitive way to ...

Android SetVisibility Does Not Display If Initially Set To Invisble

Answer : Had similar error but it was due to my silly mistake of not using the UiThread. Activity act = (Activity)context; act.runOnUiThread(new Runnable(){ @Override public void run() { mLayoutLights.setVisibility(View.VISIBLE); } }); Got it. You have to set the visibility of all the items in the layout, not just the layout. So this code worked: if (mLayoutLights.getVisibility() == View.VISIBLE) { ((Button) findViewById(R.id.btnLightsOK)).setVisibility(View.GONE); ((Button) findViewById(R.id.btnLightsCnc)).setVisibility(View.GONE); mLayoutLights.setVisibility(View.GONE); } else { mLayoutLights.setVisibility(View.VISIBLE); ((Button) findViewById(R.id.btnLightsOK)).setVisibility(View.VISIBLE); ((Button) findViewById(R.id.btnLightsCnc)).setVisibility(View.VISIBLE); } In my case, with a plain SurfaceView, I just set the View to GONE in xml, not INVISIBLE. Then I can set VISIBILITY correctly after that.

Add Border To A Container With BorderRadius In Flutter

Image
Answer : It's not possible to add border: and borderRadius: at the same time, you'll get this error: A borderRadius can only be given for uniform borders. You can achieve what you want using the borderRadius: and a boxShadow: instead of border: like this: boxShadow: [ BoxShadow(color: Colors.green, spreadRadius: 3) ] Your sample code would be like this: Container( child: Text( 'This is a Container', textScaleFactor: 2, style: TextStyle(color: Colors.black), ), decoration: BoxDecoration( borderRadius: BorderRadius.circular(10), color: Colors.white, boxShadow: [ BoxShadow(color: Colors.green, spreadRadius: 3), ], ), height: 50, ), Edit: To achieve the example you now provided, you could do this: Container( padding: EdgeInsets.only(left: 12.0), decoration: BoxDecoration( borderRadius: BorderRadius.circular(10.0), color: Colors.green, ), height: 50, child: Container( decoration: BoxD...

Bootstrap Navbar Logout Right Side Code Example

Example 1: navbar right bootstrap 4 < nav class = " navbar navbar-expand-lg navbar-light bg-light " > < a class = " navbar-brand " href = " # " > Navbar </ a > < button class = " navbar-toggler " type = " button " data-toggle = " collapse " data-target = " #navbarSupportedContent " aria-controls = " navbarSupportedContent " aria-expanded = " false " aria-label = " Toggle navigation " > < span class = " navbar-toggler-icon " > </ span > </ button > < div class = " collapse navbar-collapse " id = " navbarSupportedContent " > < ul class = " navbar-nav mr-auto " > < li class = " nav-item active " > < a class = " nav-link " href = " # " > Home < span class = " sr-only " > (current) ...

Angularjs Directives Isolated Scope + One-way Data-binding Not Working For Objects?

Answer : passing text is one-way binding(@) and passing object is two-way binding(=) passing object as text <custom-directive config="{{config}}"></custom-directive> scope in directive scope: { config: "@" } converting the string back to object in link var config = angular.fromJson(scope.config); You are correct, the issue is that your JavaScript objects are being passed by reference. Using a one-way binding copies the reference, but the reference will still point to the same object. My impression from the Angular docs for directives has always been: The '@' binding is intended for interpolated strings The '=' binding is intended for structured data that should be shared between scopes The '&' binding is intended for repeatedly executing an expression that is bound to the parent scope If you want to treat the bound object from the parent as immutable, you can create a deep copy the objects inside y...

Bash Contains Substring Code Example

Example 1: checking if a substring exists in a string bash string='Haystack'; if [[ $string =~ "Needle" ]] then echo "It's there!" fi Example 2: bash substring test #!/bin/bash STR='GNU/Linux is an operating system' SUB='Linux' if [[ "$STR" == *"$SUB"* ]]; then echo "It's there." fi

Create New React Component Code Example

Example 1: create react component class class MyComponent extends React . Component { constructor ( props ) { super ( props ) ; } ; render ( ) { return ( < div > < h1 > My First React Component ! < / h1 > < / div > ) ; } } ; Example 2: how to create component in reactjs class Car extends React . Component { render ( ) { return < h2 > Hi , I am a Car ! < / h2 > ; } } Example 3: functional components react function Comment ( props ) { return ( < div className = "Comment" > < div className = "UserInfo" > < img className = "Avatar" src = { props . author . avatarUrl } alt = { props . author . name } / > < div className = "UserInfo-name" > { props . author . name } ...

Angular: 'Cannot Find A Differ Supporting Object '[object Object]' Of Type 'object'. NgFor Only Supports Binding To Iterables Such As Arrays'

Answer : As the error messages stated, ngFor only supports Iterables such as Array , so you cannot use it for Object . change private extractData(res: Response) { let body = <Afdelingen[]>res.json(); return body || {}; // here you are return an object } to private extractData(res: Response) { let body = <Afdelingen[]>res.json().afdelingen; // return array from json file return body || []; // also return empty array if there is no data } Remember to pipe Observables to async, like *ngFor item of items$ | async , where you are trying to *ngFor item of items$ where items$ is obviously an Observable because you notated it with the $ similar to items$: Observable<IValuePair> , and your assignment may be something like this.items$ = this.someDataService.someMethod<IValuePair>() which returns an Observable of type T. Adding to this... I believe I have used notation like *ngFor item of (items$ | async)?.someProperty You only nee...