Posts

Showing posts from August, 2018

Bash "set -e" Example

Example: bash "set -e" set -e causes the shell to exit if any subcommand or pipeline returns a non-zero status. The answer the interviewer was probably looking for is: It would be dangerous to use "set -e" when creating init.d scripts: From http://www.debian.org/doc/debian-policy/ch-opersys.html 9.3.2 -- Be careful of using set -e in init.d scripts. Writing correct init.d scripts requires accepting various error exit statuses when daemons are already running or already stopped without aborting the init.d script, and common init.d function libraries are not safe to call with set -e in effect. For init.d scripts, it's often easier to not use set -e and instead check the result of each command separately. This is a valid question from an interviewer standpoint because it gauges a candidates working knowledge of server-level scripting and automation

AWS Log Insights Query With String Contains

Answer : I think you need to select them as fields and then filter on their value. e.g: fields @timestamp, @message, strcontains(@message, "user not found") AS unf | filter unf=1 | sort @timestamp desc | limit 20 Or use regex fields @timestamp, @message | filter @message like /User\snot\sfound/ | ... (haven't tested them) This should work fine fields @timestamp, @message | filter @message like /user not found/ | sort @timestamp desc | limit 20

Automate Process Of Disk Cleanup Cleanmgr.exe Without User Intervention

Answer : The following Powershell script automates CleanMgr.exe. In this case, it removes temporary files and runs the Update Cleanup extension to purge superseded Service Pack Backup files (Windows 10 now does this automatically via a scheduled task). To automate other extensions, create a "StateFlags0001" property in the corresponding Registry key, as done in the New-ItemProperty lines. You will find the Registry key names in the "VolumeCaches" branch. As far as being silent, this script attempts to start CleanMgr.exe in a hidden window. However, at some point CleanMgr spawns new processes which are visible and must be waited on separately. Write-Host 'Clearing CleanMgr.exe automation settings.' Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\*' -Name StateFlags0001 -ErrorAction SilentlyContinue | Remove-ItemProperty -Name StateFlags0001 -ErrorAction SilentlyContinue Write-Host 'Enabling Upd

Android Studio Button Icon Center Code Example

Example: center icon material button android < com.google.android.material.button.MaterialButton android: layout_width = " 50dp " android: layout_height = " 50dp " android: layout_marginTop = " 16dp " android: insetLeft = " 0dp " android: insetTop = " 0dp " android: insetRight = " 0dp " android: insetBottom = " 0dp " app: icon = " @drawable/ic_add " app: iconGravity = " textStart " app: iconPadding = " 0dp " android: paddingStart = " 4dp " android: paddingEnd = " 4dp " />

Coalesce Function For PHP?

Answer : There is a new operator in php 5.3 which does this: ?: // A echo 'A' ?: 'B'; // B echo '' ?: 'B'; // B echo false ?: 'B'; // B echo null ?: 'B'; Source: http://www.php.net/ChangeLog-5.php#5.3.0 PHP 7 introduced a real coalesce operator: echo $_GET['doesNotExist'] ?? 'fallback'; // prints 'fallback' If the value before the ?? does not exists or is null the value after the ?? is taken. The improvement over the mentioned ?: operator is, that the ?? also handles undefined variables without throwing an E_NOTICE . First hit for "php coalesce" on google. function coalesce() { $args = func_get_args(); foreach ($args as $arg) { if (!empty($arg)) { return $arg; } } return NULL; } http://drupial.com/content/php-coalesce

Adblock Extension For Chrome Android Code Example

Example: adblocker extension chrome Good Choice

Button Onclick Href Code Example

Example 1: href on a button < button onclick = "window.location.href='/page2'" > Continue < / button > Example 2: html button link < button > < a href = 'https://google.com' alt = 'Broken Link' > This is a button < / a > < / button > Example 3: buton html href < ! -- if you are on Window : -- > < button onclick = "window.location.href='page2.html'" > Button < / button > < ! -- if you are on linux or macOS : -- > < button onclick = "location.href='page2.html'" > Button < / button > Example 4: onclick href onclick = "location.href='http://www.hyperlinkcode.com/button-links.php'" Example 5: add link behind a button in html < ! DOCTYPE html > < html > < head > < title > Title of the document < / title > < / head > < body > < for

Bootstrap Css Cdn Link Code Example

Example 1: bootstrap cdn < link rel = "stylesheet" href = "https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" > Example 2: bootstrap link < link rel = "stylesheet" href = "https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity = "sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin = "anonymous" > Example 3: bootstrap cdn link < ! - - Latest compiled and minified CSS - -> < link rel = "stylesheet" href = "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity = "sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin = "anonymous" > < ! - - Optional theme - -> < link rel = "stylesheet" href = "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integri

Android Material Design Inline Datepicker Issue

Answer : The calendarViewShown attribute is deprecated in the calendar-style date picker. If you want the spinner-style date picker back, you can set the datePickerMode attribute to spinner . <DatePicker ... android:datePickerMode="spinner" /> As for the scrolling issue, the calendar-style date picker doesn't support nested scrolling.

Azure Table Storage Vs CosmosDB With Python

Answer : The Azure CosmosDB Table SDK IS Azure Storage Tables SDK. Re-branding is part of some re-org inside Microsoft, but this is the same code and same endpoint, same everything. Storage SDK was one big client, it was split into Table/Queue/Blog/Files packages, in order to give ownership of Table to CosmosDB team. https://docs.microsoft.com/en-us/azure/cosmos-db/table-support The new Azure Cosmos DB Python SDK is the only SDK that supports Azure Table storage in Python. This SDK connects with both Azure Table storage and Azure Cosmos DB Table API. You can also compare the code, you'll see: https://github.com/Azure/azure-storage-python/tree/v0.36.0/azure/storage/table https://github.com/Azure/azure-cosmosdb-python/tree/master/azure-cosmosdb-table/azure/cosmosdb/table (I work at MS in the Azure SDK for Python team) Azure Table Storage has a new python library in preview release that is available for installation via pip. To install use the following pip

Bootstrap 3 Margin Top Class Name Code Example

Example 1: bootstrap Margin and padding Use the margin and padding spacing utilities to control how elements and components are spaced and sized. Bootstrap 4 includes a five-level scale for spacing utilities, based on a 1rem value default $spacer variable. Choose values for all viewports (e.g., .mr-3 for margin-right: 1rem), or pick responsive variants to target specific viewports (e.g., .mr-md-3 for margin-right: 1rem starting at the md breakpoint). < div class = " my-0 bg-warning " > Margin Y 0 </ div > < div class = " my-1 bg-warning " > Margin Y 1 </ div > < div class = " my-2 bg-warning " > Margin Y 2 </ div > < div class = " my-3 bg-warning " > Margin Y 3 </ div > < div class = " my-4 bg-warning " > Margin Y 4 </ div > < div class = " my-5 bg-warning " > Margin Y 5 </ div > < div class = " my-auto bg-warning &q

Apple - Change Equation Font In Pages

Image
Answer : Pages uses blahtex to generate PNGs from the rudimentary maths environments. The following fonts are available out of the box with blahtex: 2.12 Fonts \mathbf \mathbb \mathrm \mathit \mathcal \mathfrak \mathsf \mathtt \boldsymbol \rm \bf \it \cal \tt \sf \Bbb \bold Unfortunately, Pages does not support all of these fonts, most notably mathcal. Pages does support: …and their shorthands: This very point has bothered me - I detest the fact that the font in my equations is so different to the rest of my doc. I explored various methods for changing font but none worked. Yesterday I stumbled across a brilliant hack for this (though not entirely fullproof). Pages supports the /text{} command, which can be embedded anywhere. The command is meant for including full words around equations so they don't look so odd. How to use it within equations? Surround characters, or groups of characters with the /text{} command. Here are some example

Std Map Find Code Example

Example: c++ map find // map::find # include <iostream> # include <map> int main ( ) { std :: map < char , int > mymap ; std :: map < char , int > :: iterator it ; mymap [ 'a' ] = 50 ; mymap [ 'b' ] = 100 ; mymap [ 'c' ] = 150 ; mymap [ 'd' ] = 200 ; it = mymap . find ( 'b' ) ; if ( it != mymap . end ( ) ) mymap . erase ( it ) ; // print content: std :: cout << "elements in mymap:" << '\n' ; std :: cout << "a => " << mymap . find ( 'a' ) -> second << '\n' ; std :: cout << "c => " << mymap . find ( 'c' ) -> second << '\n' ; std :: cout << "d => " << mymap . find ( 'd' ) -> second << '\n' ; return 0 ; }

Bellman-Ford Vs Dijkstra: Under What Circumstances Is Bellman-Ford Better?

Answer : Bellman-Ford algorithm is a single-source shortest path algorithm, so when you have negative edge weight then it can detect negative cycles in a graph. The only difference between the two is that Bellman-Ford is also capable of handling negative weights whereas Dijkstra Algorithm can only handle positives. From wiki However, Dijkstra's algorithm greedily selects the minimum-weight node that has not yet been processed, and performs this relaxation process on all of its outgoing edges; in contrast, the Bellman–Ford algorithm simply relaxes all the edges, and does this |V | − 1 times, where |V | is the number of vertices in the graph. In each of these repetitions, the number of vertices with correctly calculated distances grows, from which it follows that eventually all vertices will have their correct distances. This method allows the Bellman–Ford algorithm to be applied to a wider class of inputs than Dijkstra. Dijkstra is however generally co

Apeejay Ecourse Code Example

Example: ecourse apeejay ecourse.asu.apeejay.edu

Cant Cancel Axios Post Request Via CancelToken

Answer : I have found out that you can cancel post request this way,i missunderstand this documentation part. In previous code,i have passed cancelToken to the POST data request not as a axios setting. import axios from 'axios' var CancelToken = axios.CancelToken; var cancel; axios({ method: 'post', url: '/test', data: { firstName: 'Fred', lastName: 'Flintstone' }, cancelToken: new CancelToken(function executor(c) { // An executor function receives a cancel function as a parameter cancel = c; }) }).then(()=>console.log('success')).catch(function(err){ if(axios.isCancel(err)){ console.log('im canceled'); } else{ console.log('im server response error'); } }); // this cancel the request cancel() Cancel previous Axios request on new request with cancelToken and source. https://github.com/axios/axios#cancellation // cancelToken and source declaration con