Tutorial by Examples: by

$sku = 'sku-goes-here'; $product = Mage::getModel('catalog/product')->loadByAttribute('sku', $sku);
$id = 1; $product = Mage::getModel('catalog/product')->load($id); if($product->getId()){ //product was found }
$collection = Mage::getModel('catalog/product')->getCollection(); // Using operator $collection->addAttributeToFilter('status', array('eq' => 1)); // Without operator (automatically uses 'equal' operator $collection->addAttributeToFilter('status', 1);
ThenBy can only be used after a OrderBy clause allowing to order using multiple criteria var persons = new[] { new {Id = 1, Name = "Foo", Order = 1}, new {Id = 1, Name = "FooTwo", Order = 2}, new {Id = 2, Name = "Bar", Order = 2}, new {Id = 2, Nam...
One might want to group their data by the runs of a variable and perform some sort of analysis. Consider the following simple dataset: (dat <- data.frame(x = c(1, 1, 2, 2, 2, 1), y = 1:6)) # x y # 1 1 1 # 2 1 2 # 3 2 3 # 4 2 4 # 5 2 5 # 6 1 6 The variable x has three runs: a run of l...
The data.table package provides a convenient way to group by runs in data. Consider the following example data: library(data.table) (DT <- data.table(x = c(1, 1, 2, 2, 2, 1), y = 1:6)) # x y # 1: 1 1 # 2: 1 2 # 3: 2 3 # 4: 2 4 # 5: 2 5 # 6: 1 6 The variable x has three runs: a run ...
static class Program { static void Main() { dynamic dynamicObject = new ExpandoObject(); string awesomeString = "Awesome"; // Prints True Console.WriteLine(awesomeString.IsThisAwesome()); dynamicObject.StringValue = awesomeStrin...
git shortlog summarizes git log and groups by author If no parameters are given, a list of all commits made per committer will be shown in chronological order. $ git shortlog Committer 1 (<number_of_commits>): Commit Message 1 Commit Message 2 ... Committer 2 (<number_of_...
Lambdas can be used to create anonymous methods to assign to a delegate: Func<int,int> addOne = x => x+1; Note that the explicit declaration of type is required when creating a variable this way: var addOne = x => x+1; // Does not work
Following the Rcpp example in this documentation entry, consider the following tough-to-vectorize function, which creates a vector of length len where the first element is specified (first) and each element x_i is equal to cos(x_{i-1} + 1): repeatedCosPlusOne <- function(first, len) { x <-...
The ls command's -S option sorts the files in descending order of file size. $ ls -l -S ./Fruits total 444 -rw-rw-rw- 1 root root 295303 Jul 28 19:19 apples.jpg -rw-rw-rw- 1 root root 102283 Jul 28 19:19 kiwis.jpg -rw-rw-rw- 1 root root 50197 Jul 28 19:19 bananas.jpg When used with the -r o...
When contributors add to a project from different machines or operating systems, it may happen that they use different email addresses or names for this, which will fragment contributor lists and statistics. Running git shortlog -sn to get a list of contributors and the number of commits by them co...
$string = "0| PHP 1| CSS 2| HTML 3| AJAX 4| JSON"; //[0-9]: Any single character in the range 0 to 9 // + : One or more of 0 to 9 $array = preg_split("/[0-9]+\|/", $string, -1, PREG_SPLIT_NO_EMPTY); //Or // [] : Character class // \d : Any digit // + : One or more ...
use std::fs::File; use std::io::{BufRead, BufReader}; fn main() { let filename = "src/main.rs"; // Open the file in read-only mode (ignoring errors). let file = File::open(filename).unwrap(); let reader = BufReader::new(file); // Read the file line by line us...
string[] names= { "mark", "steve", "adam" }; Ascending: Query Syntax var sortedNames = from name in names orderby name select name; Method Syntax var sortedNames = names.OrderBy(name => name); sortedNames contains the names in following ord...
const fs = require('fs'); const readline = require('readline'); const rl = readline.createInterface({ input: fs.createReadStream('text.txt') }); // Each new line emits an event - every time the stream receives \r, \n, or \r\n rl.on('line', (line) => { console.log(line); }); ...
Sometimes you may want to bypass an alias temporarily, without disabling it. To work with a concrete example, consider this alias: alias ls='ls --color=auto' And let's say you want to use the ls command without disabling the alias. You have several options: Use the command builtin: command...
To find all the files of a certain extension within the current path you can use the following find syntax. It works by making use of bash's built-in glob construct to match all the names having the .extension. find /directory/to/search -maxdepth 1 -type f -name "*.extension" To find ...
Comparable is one of the most popular modules in Ruby. Its purpose is to provide with convenience comparison methods. To use it, you have to include Comparable and define the space-ship operator (<=>): class Rectangle include Comparable def initialize(a, b) @a = a @b = b ...
GroupBy is an easy way to sort a IEnumerable<T> collection of items into distinct groups. Simple Example In this first example, we end up with two groups, odd and even items. List<int> iList = new List<int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; var grouped = iList.GroupBy(x => x ...

Page 3 of 23