Posts

Showing posts from September, 2019

Concat All Strings Inside A List Using LINQ

Answer : String.Join(delimiter, list); is sufficient. By using LINQ, this should work; string delimiter = ","; List<string> items = new List<string>() { "foo", "boo", "john", "doe" }; Console.WriteLine(items.Aggregate((i, j) => i + delimiter + j)); class description: public class Foo { public string Boo { get; set; } } Usage: class Program { static void Main(string[] args) { string delimiter = ","; List<Foo> items = new List<Foo>() { new Foo { Boo = "ABC" }, new Foo { Boo = "DEF" }, new Foo { Boo = "GHI" }, new Foo { Boo = "JKL" } }; Console.WriteLine(items.Aggregate((i, j) => new Foo{Boo = (i.Boo + delimiter + j.Boo)}).Boo); Console.ReadKey(); } } And here is my best :) items.Select(i => i.Boo).Aggregate((i, j) => i + delimiter + j) This is for a string array: string.Join(delimiter, array)

Converst Indian Currency To Chinea Currency In Java Code Example

Example: Given a double-precision number, , denoting an amount of money, use the NumberFormat class' getCurrencyInstance method to convert into the US, Indian, Chinese, and French currency formats import java . util . Scanner ; import java . text . NumberFormat ; import java . util . Locale ; public class Solution { public static void main ( String [ ] args ) { /* Read input */ Scanner scanner = new Scanner ( System . in ) ; double payment = scanner . nextDouble ( ) ; scanner . close ( ) ; /* Create custom Locale for India. I used the "IANA Language Subtag Registry" to find India's country code */ Locale indiaLocale = new Locale ( "en" , "IN" ) ; /* Create NumberFormats using Locales */ NumberFormat us = NumberFormat . getCurrencyInstance ( Locale . US ) ; NumberFormat india = NumberFormat . getCurrencyInstance ( indiaLocale ) ;

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

80 Cm In Inches Code Example

Example: cm to inches const cm = 1; console.log(`cm:${cm} = in:${cmToIn(cm)}`); function cmToIn(cm){ var in = cm/2.54; return in; }

How To Color Svg Color Code Example

Example 1: change svg color filter : invert ( 100 % ) sepia ( 0 % ) saturate ( 7443 % ) hue-rotate ( 198 deg ) brightness ( 126 % ) contrast ( 112 % ) ; Example 2: change svg color <svg width= "96px" height= "96px" viewBox= "0 0 512 512" enable-background= "new 0 0 512 512" xml : space= "preserve" > <path id= "time-3-icon" .../> </svg> SVG are XML document so just add a style= "fill:red" on the SVG tag when you open the file <image class= "my-svg-alternate" width= "96" height= "96" src= "ppngfallback.png" />

Css Hide Div Code Example

Example 1: hidden div css display : none ; /* remove the element from page and DOM. */ visibility : hidden ; /* remove only from page. */ Example 2: hide element using css #tinynav1 { display : none } Example 3: css hide element .classname { display : none ; } Example 4: hide in css display : none ; Example 5: hide a div <div id= "main" > <p> Hide/show this div </p> </div> ( '#main' ) . hide ( ) ; //to hide // 2 nd way , by injecting css using jquery $ ( "#main" ) . css ( "display" , "none" ) ;

How To Import One Javascript File Into Another Code Example

Example 1: include other js files in a js file document. writeln ( "<script type='text/javascript' src='Script1.js'></script>" ) ; document. writeln ( "<script type='text/javascript' src='Script2.js'></script>" ) ; Example 2: javascript using another js file // module .js export function hello ( ) { return "Hello" ; } // main .js import { hello } from 'module' ; // or './module' let val = hello ( ) ; // val is "Hello" ;

Can I Safely Remove /var/cache?

Answer : From http://www.lindevdoc.org/wiki//var/cache Sorry for the (very) late answer, but I believe it's important to include this bit for future reference. Highlighted the bit which does answer this question. The /var/cache directory contains cached files, i.e. files that were generated and can be re-generated any time, but they are worth storing to save time of recomputing them. Any application can create a file or directory here. It is assumed that files stored here are not critical, so the system can delete the contents of /var/cache either periodically, or when its contents get too large. Any application should take into account that the file stored here can disappear any time, and be ready to recompute its contents (with some time penalty). So yes, you may remove these files without expecting anything bad to happen. No . For one, I believe that /var/cache/bind/ is the default directory where bind9 expects its zone files to be stored (at lea

Horizontal Space In Html Code Example

Example 1: add space in html <!-- vertical space --> &nbsp ; &ensp ; &emsp ; <! --horizontal space --> <br/> Example 2: html horizontal line style <!-- HTML --> <!-- You can change the style of the horizontal line like this : --> <hr style= "width:50%" , size= "3" , color= black > <!-- Or like this : --> <hr style= "height:2px; width:50%; border-width:0; color:red; background-color:red" >

How To Make Text Color Gradient In Css Code Example

Example 1: css gradient text h1 { font-size : 72 px ; background : -webkit-linear-gradient ( #eee , #333 ) ; -webkit-background-clip : text ; -webkit-text-fill-color : transparent ; } Example 2: text color as gradient css .gradient-text { background-color : #f3ec78 ; background-image : linear-gradient ( 45 deg , #f3ec78 , #af4261 ) ; background-size : 100 % ; -webkit-background-clip : text ; -moz-background-clip : text ; -webkit-text-fill-color : transparent ; -moz-text-fill-color : transparent ; } Example 3: gradient text color css h4 { background : linear-gradient ( to right , #494964 , #6f6f89 ) ; -webkit-background-clip : text ; -webkit-text-fill-color : transparent ; }

Convert Int To Float Sql Server Code Example

Example 1: sql cast to integer -- NOTE: this is for SQL-Oracle specifically /* <...> : Your personal entry */ -- syntax: CAST( as ) -- in this case: = INTEGER -- example: SELECT CAST(MEMBER_NO as INTEGER) FROM DUAL; Example 2: sql value of string -- Specifically for Oracle -- EXAMPLE CAST('732.98' AS INT) /* SYNTAX CAST( AS ) */

Shape Circle Set To Span In Html Code Example

Example 1: css circle #circle { width : 100 px ; height : 100 px ; background : red ; border-radius : 50 % } Example 2: make span html circle css span { display : block ; height : 60 px ; width : 60 px ; line-height : 60 px ; -moz-border-radius : 30 px ; /* or 50% */ border-radius : 30 px ; /* or 50% */ background-color : black ; color : white ; text-align : center ; font-size : 2 em ; }

"Build Periodically" With A Multi-branch Pipeline In Jenkins

Answer : If you use a declarative style Pipeline and only want to trigger the build on a specific branch you can do something like this: String cron_string = BRANCH_NAME == "master" ? "@hourly" : "" pipeline { agent none triggers { cron(cron_string) } stages { // do something } } Found on Jenkins Jira If you are using a declarative style Jenkinsfile then you use the triggers directive. pipeline { agent any triggers { cron('H 4/* 0 0 1-5') } stages { stage('Example') { steps { echo 'Hello World' } } } } I was able to find an example illustrating this an discarding old builds, which is also something I wanted. Jenkinsfile in jenkins-infra/jenkins.io: properties( [ [ $class: 'BuildDiscarderProperty', strategy: [$class: 'LogRotator', numToKeepStr: '10'] ],

Convert Unique Numbers To Md5 Hash Using Pandas

Answer : hashlib.md5 takes a single string as input -- you can't pass it an array of values as you can with some NumPy/Pandas functions. So instead, you could use a list comprehension to build a list of md5sums: ob['md5'] = [hashlib.md5(val).hexdigest() for val in ob['ssno']] In case you are hashing to SHA256, you'll need to encode your string first to (probably) UTF-8: ob['sha256'] = [hashlib.sha256(val.encode('UTF-8')).hexdigest() for val in ob['ssno']]

'adb' Is Not Recognized As An Internal Or External Command, Operable Program Or Batch File

Answer : Set the path of adb into System Variables. You can find adb in " ADT Bundle/sdk/platform-tools " Set the path and restart the cmd n then try again. Or You can also goto the dir where adb.exe is located and do the same thing if you don't wanna set the PATH. If you wanna see all the paths, just do echo %PATH% From Android Studio 1.3, the ADB location is at: C:\Users\USERNAME\AppData\Local\Android\sdk\platform-tools. Now add this location to the end of PATH of environment variables. Eg: ;C:\Users\USERNAME\AppData\Local\Android\sdk\platform-tools If you want to use it every time add the path of adb to your system variables: enter to cmd (command prompt) and write the following: echo %PATH% this command will show you what it was before you will add adb path setx PATH "%PATH%;C:\Program Files\android-sdk-windows\platform-tools" be careful the path that you want to add if it contains double quote after you restart your cmd rewrite

Image Remove Bg Hd Code Example

Example: remove background from image Use this one its best linK : https : //www.remove.bg/

Javascript Null Iif Code Example

Example: javascript double question mark let a = null ; const b = a ?? -1 ; // Same as b = ( a != null ? a : -1 ) ; console. log ( b ) ; // output : -1 //OR IF let a = 9 ; const b = a ?? -1 ; console. log ( b ) ; // output : 9 //PS. , VERY CLOSE TO '||' OPERATION IN FUNCTION , BY NOT THE SAME

Among Us Font Css Code Example

Example: font-family css font-family : "Times New Roman" , Georgia , serif ; /* If the browser does not support the first font (ie: Times New Roman), it will then try the next font (ie: Georgia). The last font should always be a "generic-family" font (ie: serif, sans-serif, etc..). /* If font is more then one word, it must be put into quotes. */

Callback Returns Undefined With Chrome.storage.sync.get

Answer : The chrome.storage API is asynchronous - it doesn't return it directly, rather passing it as an argument to the callback function. The function call itself always returns undefined . This is often used to allow other methods to run without having to wait until something responds or completes - an example of this is setTimeout (only difference is that it returns a timer value, not undefined ). For example, take this: setTimeout(function () { alert(1); }, 10000); alert(0); Because setTimeout is asynchronous, it will not stop all code until the entire function completes, rather returning initially, only calling a function when it is completed later on - this is why 0 comes up before 1. For this reason, you cannot simply do something like: // "foo" will always be undefined var foo = asyncBar(function (e) { return e; }); Generally, you should put what you want to do in your callback (the function that is called when the asynchronous function i