Tutorial by Examples: c

If you need to listen for changes to the page selected you can implement the ViewPager.OnPageChangeListener listener on the ViewPager: viewPager.addOnPageChangeListener(new OnPageChangeListener() { // This method will be invoked when a new page becomes selected. Animation is not necessar...
In Java, any object or primitive type can be an array. Array indicies are accessed via arrayName[index], e.g. myArray[0]. Values in an array are set via myArray[0] = value, e.g. if myArray is an array of type String[] myArray[0] = "test"; public class CreateBasicArray{ public static ...
public class CreateAnArray{ public static void main(String[] args){ // Creates a new array of Strings with a length of 3 // This length cannot be changed later String[] myStringArray = new String[3]; myStringArray[0] = "Hello"; // Java array ind...
public class CreateArrayWithValues { public static void main(String[] args){ // Initializes an array of Strings with values String[] myArray = {"this", "array", "has", "six", "initial", "values"}; System.out....
Problem statement: Find the minimum (over x, y) of the function f(x,y), subject to g(x,y)=0, where f(x,y) = 2 * x**2 + 3 * y**2 and g(x,y) = x**2 + y**2 - 4. Solution: We will solve this problem by performing the following steps: Specify the Lagrangian function for the problem Determine the K...
public static IWebDriver dismissAlert(this IWebDriver driver) { try { IAlert alert = driver.SwitchTo().Alert(); alert.Dismiss(); } catch {} return driver; } public static IWebDriver acceptAlert(this IWebDriver driver) { try { IAlert a...
public static Screenshot TakeScreenshot(this IWebDriver _driver) { return ((ITakesScreenshot)_driver).GetScreenshot(); } Usage example: driver.TakeScreenshot().SaveAsFile(@"/Test/Test.png",ImageFormat.Png);
Every time jQuery is called, by using $() or jQuery(), internally it is creating a new instance of jQuery. This is the source code which shows the new instance: // Define a local copy of jQuery jQuery = function( selector, context ) { // The jQuery object is actually just the init construct...
jQuery accepts a wide variety of parameters, and one of them is an actual DOM element. Passing a DOM element to jQuery will cause the underlying array-like structure of the jQuery object to hold that element. jQuery will detect that the argument is a DOM element by inspecting its nodeType. The mos...
In some cases, you would need to execute SQL query placed in string. EXEC, EXECUTE, or system procedure sp_executesql can execute any SQL query provided as string: sp_executesql N'SELECT * FROM sys.objects' -- or sp_executesql @stmt = N'SELECT * FROM sys.objects' -- or EXEC sp_executesql N'SEL...
You can execute SQL query as different user using AS USER = 'name of database user' EXEC(N'SELECT * FROM product') AS USER = 'dbo' SQL query will be executed under dbo database user. All permission checks applicable to dbo user will be checked on SQL query.
Dynamic queries are SET @sql = N'SELECT COUNT(*) FROM AppUsers WHERE Username = ''' + @user + ''' AND Password = ''' + @pass + '''' EXEC(@sql) If value of user variable is myusername'' OR 1=1 -- the following query will be executed: SELECT COUNT(*) FROM AppUsers WHERE Username = 'myusername...
In order to avoid injection and escaping problems, dynamic SQL queries should be executed with parameters, e.g.: SET @sql = N'SELECT COUNT(*) FROM AppUsers WHERE Username = @user AND Password = @pass EXEC sp_executesql @sql, '@user nvarchar(50), @pass nvarchar(50)', @username, @password Second ...
Django's built-in User model is not always appropiate for some kinds of projects. On some sites it might make more sense to use an email address instead of a username for instance. You can override the default User model adding your customized User model to the AUTH_USER_MODEL setting, in your proj...
Your code will not work in projects where you reference the User model (and where the AUTH_USER_MODEL setting has been changed) directly. For example: if you want to create Post model for a blog with a customized User model, you should specify the custom User model like this: from django.conf impo...
jQuery accepts a wide variety of parameters as "selectors", and one of them is an HTML string. Passing an HTML string to jQuery will cause the underlying array-like structure of the jQuery object to hold the resulting constructed HTML. jQuery uses regex to determine if the string being pa...
There are many reasons a write operation may fail. A frequent one is because your security rules reject the operation, for example because you're not authenticated (by default a database can only be accessed by an authenticated user). You can see these security rule violations in the output of your...
SQL Server 2008 The ROW_NUMBER function can assign an incrementing number to each row in a result set. Combined with a Common Table Expression that uses a BETWEEN operator, it is possible to create 'pages' of result sets. For example: page one containing results 1-10, page two containing results 11...
SQL Server 2012 The OFFSET FETCH clause implements pagination in a more concise manner. With it, it's possible to skip N1 rows (specified in OFFSET) and return the next N2 rows (specified in FETCH): SELECT * FROM sys.objects ORDER BY object_id OFFSET 40 ROWS FETCH NEXT 10 ROWS ONLY The ORDER...
// It's possible to unpack tuples to assign their inner values to variables let tup = (0, 1, 2); // Unpack the tuple into variables a, b, and c let (a, b, c) = tup; assert_eq!(a, 0); assert_eq!(b, 1); // This works for nested data structures and other complex data types let complex = ((1,...

Page 581 of 826