Posts

Showing posts from June, 2009

Check Npm Version Code Example

Example 1: npm version npm install -g npm@latest Example 2: npm check package version local packages: ~$ npm list globally installed packages: ~$ npm list -g specific package: ~$ npm list < package >

Leave Horizontal Space Latex Code Example

Example: give space in latex Horizontal \hspace { 1 cm } spaces can be inserted manually . Useful to control the fine - tuning in the layout of pictures . Left Side \hfill Right Side

Checkout Part Of A Branch In Azure DevOps Pipelines (GetSources)

Answer : In Azure DevOps you don't have option to get only part of the repository, but there is a workaround: Disable the "Get sources" step and get only the source you want by manually executing the according git commands in a script. To disable the default "Get Sources" just specify none in the checkout statement: - checkout: none In the pipeline add a CMD/PowerShell task to get the sources manually with one of the following 2 options: 1. Get only part of the repo with git sparse-checkout. For example, get only the directories src_1 and src_2 within the test folder (lines starting with REM ### are just the usual batch comments): - script: | REM ### this will create a 'root' directory for your repo and cd into it mkdir myRepo cd myRepo REM ### initialize Git in the current directory git init REM ### set Git sparsecheckout to TRUE git config core.sparsecheckout true REM ### write the directories that y

Case Insensitive Argparse Choices

Answer : Transform the argument into lowercase by using type = str.lower for the -p switch. This solution was pointed out by chepner in a comment. The solution I proposed earlier was type = lambda s : s.lower() which is also valid, but it's simpler to just use str.lower . Using lower in the type is nice way of doing this, if you don't mind loosing the case information. If you want to retain the case, you could define a custom choices class. The choices needs two methods, __contains__ (for testing in ), and iteration (to list the choices). class mylist(list): # list subclass that uses lower() when testing for 'in' def __contains__(self, other): return super(mylist,self).__contains__(other.lower()) choices=mylist(['win64','win32']) parser = argparse.ArgumentParser() parser.add_argument("-p", choices=choices) print(parser.parse_args(["-p", "Win32"])) # Namespace(p='Win32') The

Change Bootstrap 4 Checkbox Background Color

Answer : you can use the following css to make it red when it is not checked, and black when it is checked .custom-control-label:before{ background-color:red; } .custom-checkbox .custom-control-input:checked~.custom-control-label::before{ background-color:black; } The color of the arrow can be changed by the following code .custom-checkbox .custom-control-input:checked~.custom-control-label::after{ background-image:url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'%3E%3Cpath fill='red' d='M6.564.75l-3.59 3.612-1.538-1.55L0 4.26 2.974 7.25 8 2.193z'/%3E%3C/svg%3E"); } this code will make the tick red, you can change the color by changing the fill='red' value to a color of your choice. Edit: Note, if specifying RGB color, eg. #444444 use %23 for the hash, eg. %23444444 Or you could use any image you like instead. <link rel="stylesheet" href="https://

Calculate Time Difference In Seconds Python Code Example

Example: python datetime difference in seconds import datetime as dt a = dt . datetime ( 2013 , 12 , 30 , 23 , 59 , 59 ) b = dt . datetime ( 2013 , 12 , 31 , 23 , 59 , 59 ) ( b - a ) . total_seconds ( )

AWS Lambda Api Gateway Error "Malformed Lambda Proxy Response"

Answer : Usually, when you see Malformed Lambda proxy response , it means your response from your Lambda function doesn't match the format API Gateway is expecting, like this { "isBase64Encoded": true|false, "statusCode": httpStatusCode, "headers": { "headerName": "headerValue", ... }, "body": "..." } If you are not using Lambda proxy integration, you can login to API Gateway console and uncheck the Lambda proxy integration checkbox. Also, if you are seeing intermittent Malformed Lambda proxy response , it might mean the request to your Lambda function has been throttled by Lambda, and you need to request a concurrent execution limit increase on the Lambda function. If lambda is used as a proxy then the response format should be { "isBase64Encoded": true|false, "statusCode": httpStatusCode, "headers": { "headerName": "headerValue", ...

Apache2 And Logrotate: Delaycompress Needed?

Answer : If you're doing an Apache restart (or even 'graceful') it will close open file handles and open them again. You shouldn't need delaycompress because the file will have been closed and re-opened as part of your postrotate restart. rotate access_log -> access_log.1 (rename action, no INODE change) apache still writing to access_log.1 (same open FD on same INODE) apache restart (close FD, release INODE writing) apache writing to access_log (new FD to a new INODE) A restart is kind of a bad idea - what if the config file accidentally changed and is no longer valid? Your apache won't start back up. Instead send a HUP to the parent process which tells it to close/re-open file handles. postrotate /bin/kill -HUP `cat /var/run/apache2.pid 2>/dev/null` 2>/dev/null || true endscript cat will fail if the PID is missing (or empty, or invalid) causing kill to also fail so you don't need the if..then block around it.

Check If File Exists Groovy Code Example

Example: groovy check if file exists def filePath = "/tmp/file.json" def file = new File(filePath) assert file.exists() : "file not found"

Addcomponent Unity Code Example

Example 1: unity requirecomponent using UnityEngine ; // PlayerScript requires the GameObject to have a Rigidbody component [ RequireComponent ( typeof ( Rigidbody ) ) ] public class PlayerScript : MonoBehaviour { Rigidbody rb ; void Start ( ) { rb = GetComponent < Rigidbody > ( ) ; } void FixedUpdate ( ) { rb . AddForce ( Vector3 . up ) ; } } Example 2: Add component object to gameobject unity //to add a new ridgidbody gameobject . AddComponent < Rigidbody > ( ) ; //to add a new meshCollider gameobject . AddComponent < MeshCollider > ( ) ; //Original answer by MakerBenjammin6, cleanup by me. Example 3: unity add component //Use the AddComponent<T>() Method to add a component to your gameobject GameObject gameObject ; gameObject . AddComponent < BoxCollider > ( ) ; //Component has to be an actual Unity component Example 4: c# addcomponent // Consider an existing GameObject,

Can Google.com And Other Heavily Trafficked Websites Get A "fast" Rank Using Google's PSI API?

Image
Answer : To directly answer the question, no it's not impossible to get a fast FCP label. There's more to the question so I'll try to elaborate. Another way to phrase the "fast" criteria is: "Do at least 90% of user experiences have an FCP less than 1 second ?" Why 90%? Because it's inclusive of a huge proportion of user experiences. As the PSI docs say: Our goal is to make sure that pages work well for the majority of users. By focusing on 90th and 95th percentile values for our metrics, this ensures that pages meet a minimum standard of performance under the most difficult device and network conditions. Why 1 second? It's a subjective value for how quickly users expect the page to start showing meaningful progress. After 1 second, users may become distracted or even frustrated. Of course the holy grail is to have instant loading, but this is chosen as a realistic benchmark to strive towards. So at worst 10% of the FCP experien

Array Extract Php Code Example

Example 1: php extract array extract ( $array ) ; Example 2: php array extract value <?php $array = array ( "size" => "XL" , "color" => "gold" ) ; print_r ( array_values ( $array ) ) ; ?>

Arduino: Better Microsecond Resolution Than Micros()?

Answer : Yes, depending your Arduino's basic clock rate. For example here are the counter-timer input frequencies and periods after pre-scaling, for an ATMega2560's counter-timer 2, and a basic clock rate of 16MHz. The timer has built in "prescaler" value options which determine frequency/period, shown in this table: TCCR2B bits 2-0 Prescaler Freq [KHz], Period [usec] after prescale 0x0 (TC stopped) -- -- 0x1 1 16000. 0.0625 0x2 8 2000. 0.500 0x3 32 500. 2.000 0x4 64 250. 4.000 0x5 128 125. 8.000 0x6 256 62.5 16.000 0x7 1024 15.625 64.000 For better timing resolution, you use a value called TCNT2. There is build in counter that goes from 0 to 255 becaus

Ado Stands For Code Example

Example: ado stands for ActiveX Data Objects

22 Inch In Cm Code Example

Example 1: inch to cm 1 inch = 2.54 cm Example 2: cm to inch 1 cm = 0.3937 inch