Tutorial by Examples: o

When we query our data, we often need more than one filter to get the exact data set we are looking for. In SQL, we handle this with AND and OR clauses. We can achieve the same thing with collections. To add an AND clause to your query, just simply add another method call. This will append the seco...
This uses the SwiftyDropbox library to upload a file from a NSFileHandle to the Dropbox account using upload sessions, handling every error case: import UIKit import SwiftyDropbox class ViewController: UIViewController { // filled in later in doUpload: var fileHandle : NSFileHandle?...
var express = require("express"), bodyParser = require("body-parser"), server = express(); //body parser for parsing request body server.use(bodyParser.json()); server.use(bodyParser.urlencoded({ extended: true })); //temperary store for `item` in memory var it...
Sample JSON: { "id": "12345", "type": "android" } Define your request: public class GetDeviceRequest { @SerializedName("deviceId") private String mDeviceId; public GetDeviceRequest(String deviceId) { this....
import curses import traceback try: # -- Initialize -- stdscr = curses.initscr() # initialize curses screen curses.noecho() # turn off auto echoing of keypress on to screen curses.cbreak() # enter break mode where pressing Enter key ...
Use the double negation syntax to check for truthiness of values. All values correspond to a boolean, irrespective of their type. irb(main):001:0> !!1234 => true irb(main):002:0> !!"Hello, world!" (irb):2: warning: string literal in condition => true irb(main):003:0> !...
You do not need to use double negation in if-else statements. if 'hello' puts 'hey!' else puts 'bye!' end The above code prints 'hey!' on the screen.
JSON (JavaScript Object Notation) is a lightweight data interchange format. Many web applications use it to send and receive data. In Ruby you can simply work with JSON. At first you have to require 'json', then you can parse a JSON string via the JSON.parse() command. require 'json' j = '{&q...
You can use JSON together with Ruby symbols. With the option symbolize_names for the parser, the keys in the resulting hash will be symbols instead of strings. json = '{ "a": 1, "b": 2 }' puts JSON.parse(json, symbolize_names: true) >> {:a=>1, :b=>2}
If you can say “YAGNI” (You ain’t gonna need it) about a feature, you better not implement it. There can be a lot of development time saved through focussing onto simplicity. Implementing such features anyway can lead to problems: Problems Overengineering If a product is more complicated than it...
Lets you compose several functions f₀ f₁ … fₙ. It returns a function that will successively apply fₙ to its arguments, then fₙ₋₁ to the result of fₙ and so on. Function are applied from right to left, like for mathematical function composition: (f ∘ g ∘ h)(x) = f(g(h(x))). > ((compose sqrt +) 16...
Your app can't access your reminders and your calendar without permission. Instead, it must show an alert to user, requesting him/her to grant access to events for the app. To get started, import the EventKit framework: Swift import EventKit Objective-C #import <EventKit/EventKit.h> ...
Accessing the array of calendars To access the array of EKCalendars, we use the calendarsForEntityType method: Swift let calendarsArray = eventStore.calendarsForEntityType(EKEntityType.Event) as! [EKCalendar] Iterating through calendars Just use a simple for loop: Swift for calendar in cale...
In Symfony, the built-in ChoiceType (and EntityType or DocumentType extending it), basicaly work with a constant choice list. If you want to make it work with ajax calls, you have to change them to accept any sumitted extra choices. How to start with an empty choice list ? When you build your...
This is an example to show how to change the allowed choices on a subCategory select field depending on the value of the category select field. To do that you have to make your subCategory choices dynamical for both client and server side. 1. Make the form dynamic on the client side for display / ...
When you define a class or module, the implicit receiver becomes a reference to the class itself. For example: puts "I am #{self}" class Example puts "I am #{self}" end Executing the above code will print: "I am main" "I am Example"
Most Ruby code utilizes the implicit receiver, so programmers who are new to Ruby are often confused about when to use self. The practical answer is that self is used in two major ways: 1. To change the receiver. Ordinarily the behavior of def inside a class or module is to create instance methods...
Qt provides a deployment tool for Windows: windeployqt. The tool inspects a Qt application executable for its dependecies to Qt modules and creates a deployment directory with the necessary Qt files to run the inspected executable. A possible script may look like: set PATH=%PATH%;<qt_install_pre...
Setup variables JUSERID=$[ ( $RANDOM % 100 ) + 1 ] JUSERNAME="admin" JUSEREMAIL="[email protected]" JUSERPASS="qweasd" DB="joomla_3" DBUSER="jdbuser" DBPASS="dbupass" DBPREFIX="prfx_" JOOMLAVERSION="3.6.2" ...
BEGIN TRY -- start error handling BEGIN TRANSACTION; -- from here on transactions (modifictions) are not final -- start your statement(s) select 42/0 as ANSWER -- simple SQL Query with an error -- end your statement(s) COMMIT TRANSACTION; -- finalize all transa...

Page 622 of 1038