Posts

Showing posts from November, 2020

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 } &l

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

For Loop In C Hackerrank Solution Code Example

Example: for loop in c++ hackerrank solution # include <bits/stdc++.h> using namespace std ; int main ( ) { int a , b ; string c [ ] = { "" , "one" , "two" , "three" , "four" , "five" , "six" , "seven" , "eight" , "nine" } ; cin >> a >> b ; for ( int i = a ; i <= b ; i ++ ) cout << ( ( i <= 9 ) ? c [ i ] : ( ( i % 2 == 0 ) ? "even" : "odd" ) ) << endl ; }

Bootstrap Table Responsive Class Name Code Example

Example: bootstrap table < table class = " table " > < thead > < tr > < th scope = " col " > # </ th > < th scope = " col " > First </ th > < th scope = " col " > Last </ th > < th scope = " col " > Handle </ th > </ tr > </ thead > < tbody > < tr > < th scope = " row " > 1 </ th > < td > Mark </ td > < td > Otto </ td > < td > @mdo </ td > </ tr > < tr > < th scope = " row " > 2 </ th > < td > Jacob </ td > < td > Thornton </ td > < td > @fat </ td > </ tr > < tr > < th scope = " row " > 3 </ th > < td > Larry </ td >

Can I Use Ufw To Setup A Port Forward?

Answer : Solution 1: Let's say you want to forward requests going to 80 to a server listening on port 8080. Note that you will need to make sure port 8080 is allowed, otherwise ufw will block the requests that are redirected to 8080. sudo ufw allow 8080/tcp There are no ufw commands for setting up the port forwards, so it must be done via configuraton files. Add the lines below to /etc/ufw/before.rules , before the filter section, right at the top of the file: *nat :PREROUTING ACCEPT [0:0] -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080 COMMIT Then restart and enable ufw to start on boot: sudo ufw enable Solution 2: Since ufw 0.34 ufw supports forward rules. example: sudo ufw route allow in on eth0 out on eth1 to 10.0.0.0/8 port 8080 from 192.168.0.0/16 port 80 You also need to make sure you have the sysctl net.ipv4.ip_forward enabled. For most distributions, that's done by editing /etc/sysctl.conf and running sysctl -p or rebooting.

Chkdsk, SeaTools, And "does Not Have Enough Space To Replace Bad Clusters"

Answer : The free drive space and the drive space chkdisk uses are two different things. Each hard disk has some extra unallocated space which is used as replacement space for bad sectors. That space may not be used for anything else and as far as user (of a normally functioning drive) is concerned doesn't exist. The "free" space on your E: partition isn't free at all. It's taken up by the E: partition (and even if you deleted the partition it still isn't free in the meaning of "free" windows is using). Basically each sector on a hard disk has its own number. Usually at the end of the drive there are extra sectors which are not numbered. They are used when a sector goes bad. Bad sector's number is removed form the sector and assigned to one of the sectors without a number. This way the bad sector is "fixed". In the end, the only thing you can do i replace the drive. Each drive has a finite number of normal sectors and a finite

Angular Router Link Open New Tab To Url Code Example

Example: javascript open link in new tab function NewTab() { window.open( "https://www.yourURL.com", "_blank"); }