Tutorial by Examples

Suppose you have a Post model with a hasMany relationship with Comment. You may insert a Comment object related to a post by doing the following: $post = Post::find(1); $commentToAdd = new Comment(['message' => 'This is a comment.']); $post->comments()->save($commentToAdd); You ca...
However, x in the generator expression is not just variable, but can be any pattern. In cases of pattern mismatch the generated element is skipped over, and processing of the list continues with the next element, thus acting like a filter: [x | Just x <- [Just 1, Nothing, Just 3]] -- [1, 3] ...
Another feature of list comprehensions is guards, which also act as filters. Guards are Boolean expressions and appear on the right side of the bar in a list comprehension. Their most basic use is [x | p x] === if p x then [x] else [] Any variable used in a guard must appear on its left ...
List comprehensions can also draw elements from multiple lists, in which case the result will be the list of every possible combination of the two elements, as if the two lists were processed in the nested fashion. For example, [ (a,b) | a <- [1,2,3], b <- ['a','b'] ] -- [(1,'a'), (1,'b'),...
With Parallel List Comprehensions language extension, [(x,y) | x <- xs | y <- ys] is equivalent to zip xs ys Example: [(x,y) | x <- [1,2,3] | y <- [10,20]] -- [(1,10),(2,20)]
A tuple is a heterogeneous collection of two to twenty-two values. A tuple can be defined using parentheses. For tuples of size 2 (also called a 'pair') there's an arrow syntax. scala> val x = (1, "hello") x: (Int, String) = (1,hello) scala> val y = 2 -> "world" y:...
The TIMESTAMP column will show when the row was last updated. CREATE TABLE `TestLastUpdate` ( `ID` INT NULL, `Name` VARCHAR(50) NULL, `Address` VARCHAR(50) NULL, `LastUpdate` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ) COMMENT='Last Update' ;
Code snippet: import java.util.Set; public class ThreadStatus { public static void main(String args[]) throws Exception { for (int i = 0; i < 5; i++){ Thread t = new Thread(new MyThread()); t.setName("MyThread:" + i); t.start(); ...
Sometimes you need to fetch data asynchronously before passing it to a child component to use. If the child component tries to use the data before it has been received, it will throw an error. You can use ngOnChanges to detect changes in a components' @Inputs and wait until they are defined before a...
We consume rest API as a JSON format and then unmarshal it to a POJO. Jackson’s org.codehaus.jackson.map.ObjectMapper “just works” out of the box and we really don’t do anything in most cases. But sometimes we need custom deserializer to fulfill our custom needs and this tutorial will guide you thro...
If you need to add proxy of your network in a reboot-persistent way, edit: sudo vim /etc/environment Press i and after the row with PATH variable insert: http_proxy=http://<proxy_server>:<port>/ https_proxy=http://<proxy_server>:<port>/ ftp_proxy=http://<proxy_serve...
If you want to show active network interfaces, type: ifconfig If you want to show also network interfaces that are down, type: ifconfig -a
You could use ethtool, but they are not going to be reboot persistent. If you want to achieve this, edit the following file: sudo vim /etc/network/interfaces And edit the file with needed informations: auto <interface_name> iface <interface_name> inet static address <ip_addres...
Using the class below, we can connect to Exchange and then set a specific user's out of office settings with UpdateUserOof: using System; using System.Web.Configuration; using Microsoft.Exchange.WebServices.Data; class ExchangeManager { private ExchangeService Service; public Exch...
x = np.random.random([100,100]) x.tofile('/path/to/dir/saved_binary.npy') y = fromfile('/path/to/dir/saved_binary.npy') z = y.reshape(100,100) all(x==z) # Output: # True
The function np.loadtxt can be used to read csv-like files: # File: # # Col_1 Col_2 # 1, 1 # 2, 4 # 3, 9 np.loadtxt('/path/to/dir/csvlike.txt', delimiter=',', comments='#') # Output: # array([[ 1., 1.], # [ 2., 4.], # [ 3., 9.]]) The same file could be read ...
Different approaches can be used to integrate FontAwesome into a website: For plain HTML/CSS: Download the zip available here, unzip, and copy the contents to your website. Then reference the /css/font-awesome.css in the webpage head like so:<link rel="stylesheet" src="/assets/...
When data is "tidy," it is often organized into several tables. To combine the data for analysis, we need to "update" one table with values from another. For example, we might have sales data for performances, where attributes of the performer (their budget) and of the location ...
# example data a = data.table(id = c(1L, 1L, 2L, 3L, NA_integer_), x = 11:15) # id x # 1: 1 11 # 2: 1 12 # 3: 2 13 # 4: 3 14 # 5: NA 15 b = data.table(id = 1:2, y = -(1:2)) # id y # 1: 1 -1 # 2: 2 -2 Intuition Think of x[i] as selecting a subset of x for each row of i....
# example data DT = as.data.table(mtcars, keep.rownames = TRUE) To rearrange the order of columns, use setcolorder. For example, to reverse them setcolorder(DT, rev(names(DT))) This costs almost nothing in terms of performance, since it is just permuting the list of column pointers in the da...

Page 681 of 1336