Tutorial by Examples: ect

Given this object: var obj = { a: "hello", b: "this is", c: "javascript!", }; You can convert its values to an array by doing: var array = Object.keys(obj) .map(function(key) { return obj[key]; }); console.log(array); // [&quot...
A JSON Object is surrounded by curly braces and contains key-value pairs. { "key1": "value1", "key2": "value2", ... } Keys must be valid strings, thus surrounded by double quotation marks. Values can be JSON objects, numbers, strings, arrays, or one of the...
Unlike many other languages, Perl does not have constructors that allocate memory for your objects. Instead, one should write a class method that both create a data structure and populate it with data (you may know it as the Factory Method design pattern). package Point; use strict; sub new { ...
In Perl, the difference between class (static) and object (instance) methods is not so strong as in some other languages, but it still exists. The left operand of the arrow operator -> becomes the first argument of the method to be called. It may be either a string: # the first argument of new ...
To filter a selection you can use the .filter() method. The method is called on a selection and returns a new selection. If the filter matches an element then it is added to the returned selection, otherwise it is ignored. If no element is matched then an empty selection is returned. The HTML Thi...
Collections in Java only work for objects. I.e. there is no Map<int, int> in Java. Instead, primitive values need to be boxed into objects, as in Map<Integer, Integer>. Java auto-boxing will enable transparent use of these collections: Map<Integer, Integer> map = new HashMap<&g...
Options have some useful higher-order functions that can be easily understood by viewing options as collections with zero or one items - where None behaves like the empty collection, and Some(x) behaves like a collection with a single item, x. val option: Option[String] = ??? option.map(_.trim) ...
Panels can have sections, sections can have settings, and settings can have controls. Settings are saved in the database, while the controls for particular settings are only used to display their corresponding setting to the user. This code creates a basic section in the panel from above. Inside a...
An Explain infront of a select query shows you how the query will be executed. This way you to see if the query uses an index or if you could optimize your query by adding an index. Example query: explain select * from user join data on user.test = data.fk_user; Example result: id select_type...
A less known builtin feature is Controller Action injection using the FromServicesAttribute. [HttpGet] public async Task<IActionResult> GetAllAsync([FromServices]IProductService products) { return Ok(await products.GetAllAsync()); } An important note is that the [FromServices] c...
ng-app Sets the AngularJS section. ng-init Sets a default variable value. ng-bind Alternative to {{ }} template. ng-bind-template Binds multiple expressions to the view. ng-non-bindable States that the data isn't bindable. ng-bind-html Binds inner HTML property of an HTML element....
XSS attacks consist in injecting HTML (or JS) code in a page. See What is cross site scripting for more information. To prevent from this attack, by default, Django escapes strings passed through a template variable. Given the following context: context = { 'class_name': 'large" style=&...
This multimap allows duplicate key-value pairs. JDK analogs are HashMap<K, List>, HashMap<K, Set> and so on. Key's orderValue's orderDuplicateAnalog keyAnalog valueGuavaApacheEclipse (GS) CollectionsJDKnot definedInsertion-orderyesHashMapArrayListArrayListMultimapMultiValueMapFastListMu...
Compare operation with collections - Create collections 1. Create List DescriptionJDKguavags-collectionsCreate empty listnew ArrayList<>()Lists.newArrayList()FastList.newList()Create list from valuesArrays.asList("1", "2", "3")Lists.newArrayList("1", &...
select_dtypes method can be used to select columns based on dtype. In [1]: df = pd.DataFrame({'A': [1, 2, 3], 'B': [1.0, 2.0, 3.0], 'C': ['a', 'b', 'c'], 'D': [True, False, True]}) In [2]: df Out[2]: A B C D 0 1 1.0 a True 1 2 2.0 b False 2...
To connect to MySQL you need to use the MySQL Connector/J driver. You can download it from http://dev.mysql.com/downloads/connector/j/ or you can use Maven: <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version...
To create a project called helloworld run: stack new helloworld simple This will create a directory called helloworld with the files necessary for a Stack project.
NodeJS executes the module only the first time you require it. Any further require functions will re-use the same Object, thus not executing the code in the module another time. Also Node caches the modules first time they are loaded using require. This reduces the number of file reads and helps to...
from struct import pack print(pack('I3c', 123, b'a', b'b', b'c')) # b'{\x00\x00\x00abc'
from struct import unpack print(unpack('I3c', b'{\x00\x00\x00abc')) # (123, b'a', b'b', b'c')

Page 28 of 99