What are all the uses of an underscore in Scala?

The ones I can think of are Existential types def foo(l: List[Option[_]]) = … Higher kinded type parameters case class A[K[_],T](a: K[T]) Ignored variables val _ = 5 Ignored parameters List(1, 2, 3) foreach { _ => println(“Hi”) } Ignored names of self types trait MySeq { _: Seq[_] => } Wildcard patterns Some(5) match … Read more

Checking if a variable is defined?

Use the defined? keyword (documentation). It will return a String with the kind of the item, or nil if it doesn’t exist. >> a = 1 => 1 >> defined? a => “local-variable” >> defined? b => nil >> defined? nil => “nil” >> defined? String => “constant” >> defined? 1 => “expression” As skalee … Read more

Merging dictionaries in C#

This partly depends on what you want to happen if you run into duplicates. For instance, you could do: var result = dictionaries.SelectMany(dict => dict) .ToDictionary(pair => pair.Key, pair => pair.Value); That will throw an exception if you get any duplicate keys. EDIT: If you use ToLookup then you’ll get a lookup which can have … Read more

How to iterate (keys, values) in JavaScript? [duplicate]

tl;dr In ECMAScript 2017, just call Object.entries(yourObj). In ECMAScript 2015, it is possible with Maps. In ECMAScript 5, it is not possible. ECMAScript 2017 ECMAScript 2017 introduced a new Object.entries function. You can use this to iterate the object as you wanted. ‘use strict’; const object = {‘a’: 1, ‘b’: 2, ‘c’ : 3}; for … Read more

How to trigger a file download when clicking an HTML button or JavaScript

You can trigger a download with the HTML5 download attribute. <a href=”https://stackoverflow.com/questions/11620698/path_to_file” download=”proposed_file_name”>Download</a> Where: path_to_file is a path that resolves to an URL on the same origin. That means the page and the file must share the same domain, subdomain, protocol (HTTP vs. HTTPS), and port (if specified). Exceptions are blob: and data: (which always … Read more

Adding multiple class using ng-class

To apply different classes when different expressions evaluate to true: <div ng-class=”{class1 : expression1, class2 : expression2}”> Hello World! </div> To apply multiple classes when an expression holds true: <!– notice expression1 used twice –> <div ng-class=”{class1 : expression1, class2 : expression1}”> Hello World! </div> or quite simply: <div ng-class=”{‘class1 class2’ : expression1}”> Hello World! … Read more

How can I remove a package from Laravel using PHP Composer?

Composer 1.x and 2.x Running the following command will remove the package from vendor (or wherever you install packages), composer.json and composer.lock. Change vendor/package appropriately. composer remove vendor/package Obviously you’ll need to remove references to that package within your app. I’m currently running the following version of Composer: Composer version 1.0-dev (7b13507dd4d3b93578af7d83fbf8be0ca686f4b5) 2014-12-11 21:52:29 Documentation … Read more