Tutorial by Examples: sin

var user = Sitecore.Security.Accounts.User.FromName("sitecore/testname", false); using (new Sitecore.Security.Accounts.UserSwitcher(user)) { var item = Sitecore.Context.Database.GetItem("/sitecore/content/home"); }
NSError *e = nil; NSString *jsonString = @"[{\"id\": \"1\", \"name\":\"sam\"}]"; NSData *data = [jsonString dataUsingEncoding:NSUTF8StringEncoding]; NSArray *jsonArray = [NSJSONSerialization JSONObjectWithData: data options: NSJSONReadingMutabl...
Creating empty deque: dl = deque() # deque([]) creating empty deque Creating deque with some elements: dl = deque([1, 2, 3, 4]) # deque([1, 2, 3, 4]) Adding element to deque: dl.append(5) # deque([1, 2, 3, 4, 5]) Adding element left side of deque: dl.appendleft(0) # deque([0, 1, 2, ...
String to a primitive numeric type or a numeric wrapper type: Each numeric wrapper class provides a parseXxx method that converts a String to the corresponding primitive type. The following code converts a String to an int using the Integer.parseInt method: String string = "59"; int p...
The effect of using the * operator on an argument when calling a function is that of unpacking the list or a tuple argument def print_args(arg1, arg2): print(str(arg1) + str(arg2)) a = [1,2] b = tuple([3,4]) print_args(*a) # 12 print_args(*b) # 34 Note that the length of the starr...
CSS ul { list-style: none; counter-reset: list-item-number; /* self nesting counter as name is same for all levels */ } li { counter-increment: list-item-number; } li:before { content: counters(list-item-number, ".") " "; /* usage of counters() function means val...
The pickle module implements an algorithm for turning an arbitrary Python object into a series of bytes. This process is also called serializing the object. The byte stream representing the object can then be transmitted or stored, and later reconstructed to create a new object with the same charact...
Adding a Conditional attribute from System.Diagnostics namespace to a method is a clean way to control which methods are called in your builds and which are not. #define EXAMPLE_A using System.Diagnostics; class Program { static void Main() { ExampleA(); // This method will ...
First, references will be added to the CLR assemblies that will be used. import clr clr.AddReference('System.Windows.Forms') Next the names we will use are imported. from System.Windows.Forms import Application, Form A class will be created for the Hello World form using Form as its subclas...
The IEnumerable<T> interface has a single method, GetEnumerator(), which returns an IEnumerator<T>. While the yield keyword can be used to directly create an IEnumerable<T>, it can also be used in exactly the same way to create an IEnumerator<T>. The only thing that changes ...
When an object implements the IDisposable interface, it can be created within the using syntax: using (var foo = new Foo()) { // do foo stuff } // when it reaches here foo.Dispose() will get called public class Foo : IDisposable { public void Dispose() { Console.WriteL...
5.1 JavaScript does not directly support enumerators but the functionality of an enum can be mimicked. // Prevent the enum from being changed const TestEnum = Object.freeze({ One:1, Two:2, Three:3 }); // Define a variable with a value from the enum var x = TestEnum.Two; // Prin...
There are three kinds of numeric RangeFields in Python. IntegerField, BigIntegerField, and FloatField. They convert to psycopg2 NumericRanges, but accept input as native Python tuples. The lower bound is included and the upper bound is excluded. class Book(models.Model): name = CharField(max_l...
This query selects all books with any rating less than three. bad_books = Books.objects.filter(ratings_range__contains=(1, 3))
This query gets all books with ratings greater than or equal to zero and less than six. all_books = Book.objects.filter(ratings_range_contained_by=(0, 6))
This query gets all overlapping appointments from six to ten. Appointment.objects.filter(time_span__overlap=(6, 10))
This query selects all books with any rating greater than or equal to four. maybe_good_books = Books.objects.filter(ratings_range__contains=(4, None))
When using a VCS such as Git or SVN, there are some secret data that must never be versioned (whether the repository is public or private). Among those data, you find the SECRET_KEY setting and the database password. A common practice to hide these settings from version control is to create a file...
Removing duplicate values in a list can be done by converting the list to a set (that is an unordered collection of distinct objects). If a list data structure is needed, then the set can be converted back to a list using the function list(): names = ["aixk", "duke", "edik&...
It is possible, inside a closure, to use an external variable with the special keyword use. For instance: <?php $quantity = 1; $calculator = function($number) use($quantity) { return $number + $quantity; }; var_dump($calculator(2)); // Shows "3" You can go further by ...

Page 38 of 161