Posts

Showing posts from May, 2004

Amenable Sentence Code Example

Example: dissuade sentence She said nothing to dissuade him.

Convert Absolute Path To Relative Path In Batch File

Answer : @echo off setlocal EnableDelayedExpansion set Path_to_convert=c:\documents\mynicefiles\afile.txt set Reference_path=c:\documents set Result=!Path_to_convert:*%Reference_path%\=! echo Result: %Result%

Jquery If Else Statement Code Example

Example 1: javascript if else var age = 20 ; if ( age < 18 ) { console . log ( "underage" ) ; } else { console . log ( "let em in!" ) ; } Example 2: if statements javascript if ( pros < 10 ) { console . log ( "LESS THAN 10 PROS!" ) ; } else if ( pros < 5 ) { console . log ( "LESS THAN 5 PROS!" ) ; } else { console . log ( "How many pros are there?" ) ; }

Button Disabled Javascript Code Example

Example 1: javascript disable button //disable the button document . getElementById ( BUTTON_ID ) . disabled = true ; //reable the button document . getElementById ( BUTTON_ID ) . removeAttribute ( 'disabled' ) ; Example 2: javascript how to disable a button //Using Javascript //Disabling a html button document . getElementById ( "Button" ) . disabled = true ; //Enabling a html button document . getElementById ( "Button" ) . disabled = false ; //Using jQuery //Disabling a html button $ ( '#Button' ) . attr ( 'disabled' , 'disabled' ) ; //Enabling a html button $ ( '#Button' ) . removeAttr ( 'disabled' ) ; Example 3: html button disabled < button type = "button" disabled > This button is disabled < / button > Example 4: javascript disable button document . getElementById ( BUTTON_ID ) . disabled = true ; Example 5: enable html button $ ( '#Button' ) .

Text Centre Html Code Example

Example 1: html center text <div style= "text-align:center" >Dieser Text wird zentriert. <p>Ebenso dieser Paragraph.</p></div> Example 2: html how to center text <p style= "text-align:center;" >Centered paragraph.</p> Example 3: how to center text in html text-align : center ;

Adding L1/L2 Regularization In PyTorch?

Answer : Following should help for L2 regularization: optimizer = torch.optim.Adam(model.parameters(), lr=1e-4, weight_decay=1e-5) This is presented in the documentation for PyTorch. Have a look at http://pytorch.org/docs/optim.html#torch.optim.Adagrad. You can add L2 loss using the weight decay parameter to the Optimization function. For L2 regularization, l2_lambda = 0.01 l2_reg = torch.tensor(0.) for param in model.parameters(): l2_reg += torch.norm(param) loss += l2_lambda * l2_reg References: https://discuss.pytorch.org/t/how-does-one-implement-weight-regularization-l1-or-l2-manually-without-optimum/7951. http://pytorch.org/docs/master/torch.html?highlight=norm#torch.norm.

C++ - Does Resetting Stringstream Not Reset The Get Position Or Clear Flags?

Answer : As @Someprogrammerdude suggests: simply move your istringstream inside your while loop (which you can change to a for loop to keep in in the loop as well): for (string in; cin >> in;) { istringstream word(in); int number; if (!(word >> number)) { cerr << "Failed to read int" << endl; return 1; } cout << in << ' ' << number << endl; } that way it's re-created each loop. While you're at it, move number in there too (unless you use it outside the loop, of course). If you look at the state of the stream, this should be a bit clearer. int main() { std::vector<std::string> words = { "10", "55", "65" }; std::istringstream word; for (const auto &in : words) { word.str(in); std::cout << "stream state:" << (word.rdstate() & std::ios::badbit ? "

C Wlie Loop Examples

Example: WHILE loop in c while( a < 20 ) { printf("value of a: %d\n", a); a++; }

Python Math.inf Code Example

Example 1: python math negative infinity # Import math Library import math # Print the positive infinity print ( math.inf ) # Print the negative infinity print ( -math.inf ) Example 2: math pyhon ? Arithmetic : operator | name | example | + Addition x + y - Subtraction x - y * Multiplication x * y / Division x / y % Modulus x % y ** Exponentiation x ** y // Floor division x // y Comparison : Operator | Name | Example | == Equal x == y != Not equal x != y > Greater than x > y < Less than x < y >= Greater than or equal to x >= y <= Less than or equal to x <= y Assignment : Operator | Example | = x = 5 += x += 3 -= x -= 3 *= x *= 3 /= x /= 3 %= x %= 3 //= x //= 3 **= x **= 3 &= x &= 3 |= x |= 3 ^= x ^= 3 >>= x >>= 3 <

Can I Programmatically Move The Steps Of A Mat-horizontal-stepper In Angular / Angular Material

Answer : Yes. It is possible to jump to a specific stepper by using selectedIndex property of the MatStepper . Also, MatStepper exposes public methods next() and previous() . You can use them to move back and forth. In your template: Add an id to your stepper e.g. #stepper . Then in your goBack() and goForward() methods, pass the stepper id: <mat-horizontal-stepper #stepper> <!-- Steps --> </mat-horizontal-stepper> <!-- second option --> <div> <button (click)="goBack(stepper)" type="button">Back</button> <button (click)="goForward(stepper)" type="button">Next</button> </div> .. and in your typescript: import { MatStepper } from '@angular/material/stepper'; goBack(stepper: MatStepper){ stepper.previous(); } goForward(stepper: MatStepper){ stepper.next(); } Link to stackblitz demo . You can also use ViewChild to get a reference to

Modulenotfounderror No Module Named 'cv2' Spyder Code Example

Example 1: ModuleNotFoundError: No module named 'cv2' To solve this run the following # main opencv pip install opencv - python # contrib package for the extra features pip install opencv - contrib - python The official installation instructions are on the opencv website . More info can be found here : https : //www.pyimagesearch.com/opencv-tutorials-resources-guides/ Example 2: ModuleNotFoundError: No module named 'cv2' sudo apt - get install python - opencv libopencv - dev python - numpy python - dev

Connection To FileZilla FTP Server Works, But Directory Listing Fails

Image
Answer : While this question is old, there's no really comprehensive answer. So I'm adding one. In the passive FTP mode (the most common mode nowadays), the FTP server listens on port 21 for an FTP control connection. But for all data transfers, including directory listings, it listens on an additional port. The port is picked out of a configured port range. If you open only the 21 control port on the firewall, you get the described behavior. You can connect, but you cannot list directories or transfer files. For details, see my article on Network configuration for passive FTP mode. You have to go to Control Panel > System and Security > Windows Firewall > Advanced Settings > Inbound Rules > New Rule and add a new inbound rule for data port range your FTP server is using. The port range that the FileZilla FTP server is using, is configured in Edit > Settings > Passive mode settings > Use custom port rage . You can configure a narrow range (like 10 p

BootStrap : Uncaught TypeError: $(...).datetimepicker Is Not A Function

Answer : You are using datetimepicker when it should be datepicker . As per the docs. Try this and it should work. <script type="text/javascript"> $(function () { $('#datetimepicker9').datepicker({ viewMode: 'years' }); }); </script> I had the same problem, you have to load first the Moment.js file! <script src="path/moment.js"></script> <script src="path/bootstrap-datetimepicker.js"></script> This is a bit late but I know it will help someone: If you are using datetimepicker make sure you include the right CSS and JS files. datetimepicker uses(Take note of their names); https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/css/bootstrap-datetimepicker.css and https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/js/bootstrap-datetimepicker.min.js On the above question asked by @mindfreak,The main problem is due to the impor

Css Text Animation Generator Code Example

Example: animation generator css <div id= "animated-example" class= "animated zoomIn" ></div>

Html For Numbered List Code Example

Example 1: html number list <ol type= "1" > <li>Item 1 </li> <li>Item 2 </li> <li>Item 3 </li> </ol> <ol type= "A" > <li>Item 1 </li> <li>Item 2 </li> <li>Item 3 </li> </ol> <ol type= "a" > <li>Item 1 </li> <li>Item 2 </li> <li>Item 3 </li> </ol> <ol type= "I" > <li>Item 1 </li> <li>Item 2 </li> <li>Item 3 </li> </ol> <ol type= "i" > <li>Item 1 </li> <li>Item 2 </li> <li>Item 3 </li> </ol> Example 2: bullet list html <ul> <li>Eggs</li> <li>Pancakes</li> <li>Jelly</li> </ul>

C#: Looping Through Lines Of Multiline String

Answer : I suggest using a combination of StringReader and my LineReader class, which is part of MiscUtil but also available in this StackOverflow answer - you can easily copy just that class into your own utility project. You'd use it like this: string text = @"First line second line third line"; foreach (string line in new LineReader(() => new StringReader(text))) { Console.WriteLine(line); } Looping over all the lines in a body of string data (whether that's a file or whatever) is so common that it shouldn't require the calling code to be testing for null etc :) Having said that, if you do want to do a manual loop, this is the form that I typically prefer over Fredrik's: using (StringReader reader = new StringReader(input)) { string line; while ((line = reader.ReadLine()) != null) { // Do something with the line } } This way you only have to test for nullity once, and you don't have to think about a do/while

Creative Tim Icons Argon Code Example

Example: ni ni-pin-3 class="ni ni-pin-3 text-primary"

2048x1152 Pixels In Inches Code Example

Example 1: 1000x1000 in inches 1000x1000 = 10.416666667 Example 2: pixel to inches Assuming the pixel density is 96 dpi, there are 96 pixels per inch. Than 1 pixel = (1 / 96) inches.

: Error: Dereferencing Pointer To Incomplete Type Code Example

Example 1: error: dereferencing pointer to incomplete type The “dereferencing pointer to incomplete type” error commonly occurs in C when one tries to dereference a type ( usually a struct ) that is : not declared at all . declared , but not defined . Example 2: dereferencing pointer to incomplete type ‘struct dirent dereferencing pointer to incomplete type ‘ struct dirent