Tutorial by Examples

A method can be converted to a closure using the & operator. def add(def a, def b) { a + b } Closure addClosure = this.&add assert this.add(4, 5) == addClosure(4, 5)
Add a keystore using: keytool -genkey -v -keystore example.keystore -alias example -keyalg RSA -keysize 2048 -validity 10000 Note: This should be at root of project. Though not a hard requirement, it eases the file referencing Add a build.json with release/dev configuration for key...
To view a pdf you can download Adobe reader for free . You can create pdfs programmatically with the help of, e.g by using iTextSharp, jsPDF or PDFSharp (there are other libraries available)
This code writes the string to a file. It is important to close the writer, so this is done in a finally block. public void writeLineToFile(String str) throws IOException { File file = new File("file.txt"); BufferedWriter bw = null; try { bw = new BufferedWriter(ne...
Early Bound (with a reference to Microsoft Scripting Runtime) Sub EnumerateFilesAndFolders( _ FolderPath As String, _ Optional MaxDepth As Long = -1, _ Optional CurrentDepth As Long = 0, _ Optional Indentation As Long = 2) Dim FSO As Scripting.FileSystemObject Set ...
Declaring an array is very similar to declaring a variable, except you need to declare the dimension of the Array right after its name: Dim myArray(9) As String 'Declaring an array that will contain up to 10 strings By default, Arrays in VBA are indexed from ZERO, thus, the number inside the par...
Split Function returns a zero-based, one dimensional array containing a specified number of substrings. Syntax Split(expression [, delimiter [, limit [, compare]]]) PartDescriptionexpressionRequired. String expression containing substrings and delimiters. If expression is a zero-length string(&q...
Inside parent-component.hbs {{yield (hash child=( component 'child-component' onaction=(action 'parentAction') ) )}} Inside parent-component.js export default Ember.Component.extend({ actions: { // We pass this action to the child to call at it's discretion par...
Meteor.call(name, [arg1, arg2...], [asyncCallback]) (1) name String (2) Name of method to invoke (3) arg1, arg2... EJSON-able Object [Optional] (4) asyncCallback Function [Optional] On one hand, you can do : (via Session variable, or via ReactiveVar) var syncCall = Meteor.call("my...
When using non-lazy translation, strings are translated immediately. >>> from django.utils.translation import activate, ugettext as _ >>> month = _("June") >>> month 'June' >>> activate('fr') >>> _("June") 'juin' >>> a...
Create Table mysql> CREATE TABLE account (acct_num INT, amount DECIMAL(10,2)); Query OK, 0 rows affected (0.03 sec) Create Trigger mysql> CREATE TRIGGER ins_sum BEFORE INSERT ON account -> FOR EACH ROW SET @sum = @sum + NEW.amount; Query OK, 0 rows affected (0.06 sec) The CRE...
Prefer dict.get method if you are not sure if the key is present. It allows you to return a default value if key is not found. The traditional method dict[key] would raise a KeyError exception. Rather than doing def add_student(): try: students['count'] += 1 except KeyError: ...
stringVar="Apple Orange Banana Mango" arrayVar=(${stringVar// / }) Each space in the string denotes a new item in the resulting array. echo ${arrayVar[0]} # will print Apple echo ${arrayVar[3]} # will print Mango Similarly, other characters can be used for the delimiter. stringVa...
First, add Mongoid to your Gemfile: gem "mongoid", "~> 4.0.0" and then run bundle install. Or just run: $ gem install mongoid After installation, run the generator to create the config file: $ rails g mongoid:config which will create the file (myapp)/config/mongoid...
Create a model (lets call it User) by running: $ rails g model User which will generate the file app/models/user.rb: class User include Mongoid::Document end This is all you need to have a model (albeit nothing but an id field). Unlike ActiveRecord, there is no migration files. All the...
As per the Mongoid Documentation, there are 16 valid field types: Array BigDecimal Boolean Date DateTime Float Hash Integer BSON::ObjectId BSON::Binary Range Regexp String Symbol Time TimeWithZone To add a field (let's call it name and have it be a String), add this to your mode...
Mongoid allows the classic ActiveRecord associations: One-to-one: has_one / belongs_to One-to-many: has_many / belongs_to Many-to-many: has_and_belongs_to_many To add an association (lets say the User has_many posts), you can add this to your User model file: has_many :posts and this to ...
Mongoid allows Embedded Associations: One-to-one: embeds_one / embedded_in One-to-many: embeds_many / embedded_in To add an association (lets say the User embeds_many addresses), add this to your User file: embeds_many :addresses and this to your Address model file: embedded_in :user ...
Mongoid tries to have similar syntax to ActiveRecord when it can. It supports these calls (and many more) User.first #Gets first user from the database User.count #Gets the count of all users from the database User.find(params[:id]) #Returns the user with the id found in params[:id] User.w...
The first thing you need to know when structuring your apps is that the Meteor tool has some directories that are hard-coded with specific logic. At a very basic level, the following directories are "baked in" the Meteor bundler. client/ # client applicati...

Page 397 of 1336