Posts

Showing posts from April, 2005

Behavior Of Return Statement In Bash Functions

Answer : In the date | while ... scenario, that while loop is executed in a subshell due to the presence of the pipe. Thus, the return statement breaks the loop and the subshell ends, leaving your function to carry on. You'll have to reconstruct the code to remove the pipeline so that no subshells are created: dostuff() { # redirect from a process substitution instead of a pipeline while true; do echo returning 0 return 0 echo really-notreached done < <(date) echo notreached return 3 } If you return inside a function, that function will stop executing but the overall program will not exit. If you exit inside a function, the overall program will exit. You cannot return in the main body of a bash script, you can only return inside a function or sourced script. For example: #!/usr/bin/env bash function doSomething { echo "a" return echo "b" # this will not execute because it is

3d Array Javascript Code Example

Example 1: how to declare 3d array in javascript var myArray = [ [ [ ] ] ] ; Example 2: javascript define multidimensional array var iMax = 20 ; var jMax = 10 ; var f = new Array ( ) ; for ( i = 0 ; i < iMax ; i ++ ) { f [ i ] = new Array ( ) ; for ( j = 0 ; j < jMax ; j ++ ) { f [ i ] [ j ] = 0 ; } } Example 3: multi-dimensional array js var array = [ [ "0, 0" , "1, 0" , "2, 0" , "3, 0" , "4, 0" ] , [ "0, 1" , "1, 1" , "2, 1" , "3, 1" , "4, 1" ] , [ "0, 2" , "1, 2" , "2, 2" , "3, 2" , "4, 2" ] , [ "0, 3" , "1, 3" , "2, 3" , "3, 3" , "4, 3" ] , [ "0, 4" , "1, 4" , "2, 4" , "3, 4" , "4, 4" ] , ] ; // Think of it as coordinates, array[x, y] x = 0; y = 0; is "0,

Bootstrap Shadows: Examples Example

Add or remove shadows to elements with box-shadow utilities. Examples While shadows on components are disabled by default in Bootstrap and can be enabled via $enable-shadows , you can also quickly add or remove a shadow with our box-shadow utility classes. Includes support for .shadow-none and three default sizes (which have associated variables to match). < div class = " shadow-none p-3 mb-5 bg-light rounded " > No shadow </ div > < div class = " shadow-sm p-3 mb-5 bg-body rounded " > Small shadow </ div > < div class = " shadow p-3 mb-5 bg-body rounded " > Regular shadow </ div > < div class = " shadow-lg p-3 mb-5 bg-body rounded " > Larger shadow </ div > Sass Variables $box-shadow : 0 .5rem 1rem rgba ( $black , .15 ) ; $box-shadow-sm : 0 .125rem .25rem rgba ( $black , .075 ) ; $box-shadow-lg : 0 1rem 3rem rgba ( $black ,

Alternative Solution To HostingEnvironment.QueueBackgroundWorkItem In .NET Core

Answer : Update December 2019: ASP.NET Core 3.0 supports an easy way to implement background tasks using Microsoft.NET.Sdk.Worker. It's excellent and works really well. As @axelheer mentioned IHostedService is the way to go in .NET Core 2.0 and above. I needed a lightweight like for like ASP.NET Core replacement for HostingEnvironment.QueueBackgroundWorkItem, so I wrote DalSoft.Hosting.BackgroundQueue which uses.NET Core's 2.0 IHostedService. PM> Install-Package DalSoft.Hosting.BackgroundQueue In your ASP.NET Core Startup.cs: public void ConfigureServices(IServiceCollection services) { services.AddBackgroundQueue(onException:exception => { }); } To queue a background Task just add BackgroundQueue to your controller's constructor and call Enqueue . public EmailController(BackgroundQueue backgroundQueue) { _backgroundQueue = backgroundQueue; } [HttpPost, Route("/")] public IActionResult SendEmail([FromBody]emailRequest) {

Bash If Variable Exists And Not Empty Code Example

Example 1: bash if variable is not empty VAR = ` echo Hello world ` if [ [ -n " $VAR " ] ] ; then echo "Variable is set" ; fi Example 2: bash check if variable is empty if [ -z " $var " ] #return true if $var is unset

Chart.js Line-Chart With Different Labels For Each Dataset

Answer : I had a battle with this today too. You need to get a bit more specific with your dataset. In a line chart "datasets" is an array with each element of the array representing a line on your chart. Chart.js is actually really flexible here once you work it out. You can tie a line (a dataset element) to an x-axis and/or a y-axis, each of which you can specify in detail. In your case if we stick with a single line on the chart and you want the "time" part of the entry to be along the bottom (the x-axis) then all your times could go into the "labels" array and your "number" would be pin-pointed on the y-axis. To keep it simple without specifying our own scales with x and y axes and given this data: var MyData = [{time:"10:00", number: "127"}, {time:"11:00", number: "140"}, {time:"12:00", number: "135"}, {time:"13:00", numbe

Arduino Split String Code Example

Example: arduino c string split by delimiter /* Original code on Stackoverflow https://stackoverflow.com/questions/29671455/how-to-split-a-string-using-a-specific-delimiter-in-arduino Example : String str = "1,2,3"; String part01 = getValue(str,';',0); // get 1 String part02 = getValue(str,';',1); // get 2 String part03 = getValue(str,';',2); // get 3 String part03 = getValue(str,';',4); // get empty string Documented by issa loubani, your average programmer :P */ // Happy coding O.O String getValue ( String data , char separator , int index ) { int found = 0 ; int strIndex [ ] = { 0 , - 1 } ; int maxIndex = data . length ( ) - 1 ; for ( int i = 0 ; i <= maxIndex && found <= index ; i ++ ) { if ( data . charAt ( i ) == separator || i == maxIndex ) { found ++ ; strIndex [ 0 ] = strIndex [ 1 ] + 1 ; strIndex [ 1 ] = ( i ==

Tb6600 Stepper Motor Driver Arduino Code Code Example

Example: tb6600 stepper motor driver arduino code int PUL = 7 ; //define Pulse pin int DIR = 6 ; //define Direction pin int ENA = 5 ; //define Enable Pin void setup ( ) { pinMode ( PUL , OUTPUT ) ; pinMode ( DIR , OUTPUT ) ; pinMode ( ENA , OUTPUT ) ; } void loop ( ) { for ( int i = 0 ; i < 6400 ; i ++ ) //Forward 5000 steps { digitalWrite ( DIR , LOW ) ; digitalWrite ( ENA , HIGH ) ; digitalWrite ( PUL , HIGH ) ; delayMicroseconds ( 50 ) ; digitalWrite ( PUL , LOW ) ; delayMicroseconds ( 50 ) ; } for ( int i = 0 ; i < 6400 ; i ++ ) //Backward 5000 steps { digitalWrite ( DIR , HIGH ) ; digitalWrite ( ENA , HIGH ) ; digitalWrite ( PUL , HIGH ) ; delayMicroseconds ( 50 ) ; digitalWrite ( PUL , LOW ) ; delayMicroseconds ( 50 ) ; } }

Angular Ngx-translate Usage In Typescript

Answer : To translate something in your typescript file, do the following constructor(private translate: TranslateService) {} then use like this wherever you need to translate this.translate.instant('my.i18n.key') From the doc on github: get(key: string|Array, interpolateParams?: Object): Observable: Gets the translated value of a key (or an array of keys) or the key if the value was not found try in your controller/class: constructor(private translate: TranslateService) { let foo:string = this.translate.get('myKey'); } To translate in Typscript file ,do follow code Import in header import { TranslateService } from '@ngx-translate/core'; In constructor declare as public translate: TranslateService Suppose the JSON file looks like this { "menu":{ "Home": "Accueil" } } Declare the below code in constructor. Note: Key stands for your main key value that used in language.json

Allow Multiple Run Time Permission

Answer : First parameter is android.app.Activity type, You can't pass context at this place so use this instead of context like below code :- if (ActivityCompat.shouldShowRequestPermissionRationale (this, READ_PHONE_STATE) ||ActivityCompat.shouldShowRequestPermissionRationale (this, WRITE_EXTERNAL_STORAGE)|| ActivityCompat.shouldShowRequestPermissionRationale (this, CAMERA) || ActivityCompat.shouldShowRequestPermissionRationale (this, READ_CONTACTS) || ActivityCompat.shouldShowRequestPermissionRationale (this, CALL_PHONE) || ActivityCompat.shouldShowRequestPermissionRationale (this, ACCESS_FINE_LOCATION) || ActivityCompat.shouldShowRequestPermissionRationale (this, READ_SMS))

30 Minute Timer Code Example

Example: 20 minute timer for good eyesight every 20 minutes look out the window at something 20 feet away for 20 seconds

Cannot Import .tsx File From .ts File (and Vice Versa)

Answer : When you write import WriteEditor from './write_editor'; Webpack will automatically look for ./write_editor ./write_editor.js ./write_editor.json (And a few others) Since you're using .ts and .tsx , you need to tell it to look for those too in your Webpack config using resolve.extensions : { resolve: { extensions: [".js", ".json", ".ts", ".tsx"], }, } In my case, I got same error when using typescript-eslint . It is an app created by create-react-app . The way is by adding this code in .eslintrc.js . module.exports = { // ... settings: { 'import/resolver': { 'node': { 'extensions': ['.js','.jsx','.ts','.tsx'] } } } };

Adding Options To A Using JQuery?

Answer : Personally, I prefer this syntax for appending options: $('#mySelect').append($('<option>', { value: 1, text: 'My option' })); If you're adding options from a collection of items, you can do the following: $.each(items, function (i, item) { $('#mySelect').append($('<option>', { value: item.value, text : item.text })); }); This did NOT work in IE8 (yet did in FF): $("#selectList").append(new Option("option text", "value")); This DID work: var o = new Option("option text", "value"); /// jquerify the DOM object 'o' so we can use the html method $(o).html("option text"); $("#selectList").append(o); You can add option using following syntax, Also you can visit to way handle option in jQuery for more details. $('#select').append($('<option>', {value:1, text:'One'}

Center Content Vertically In Div Bootstrap 4 Code Example

Example 1: bootstrap center align columns <!-- Center columns in a Row --> < div class = " row d-flex justify-content-center text-center " > < div class = " col-4 " > // Add Content </ div > < div class = " col-4 " > // Add Content </ div > < div class = " col-4 " > // Add Content </ div > </ div > Example 2: html center image vertically bootstrap mx-auto mt-auto mb-auto Example 3: bootstrap div vertical center < div class = " jumbotron d-flex align-items-center min-vh-100 " > < div class = " container text-center " > I am centered vertically </ div > </ div > Example 4: bootstrap column vertical align < span class = " align-baseline " > baseline </ span > < span class = " align-top " > top </ span > < span class = &q