One of the easiest ways to connect to MySQL is by using mysql module. This module handles the connection between Node.js app and MySQL server.
You can install it like any other module:
npm install --save mysql
Now you have to create a mysql connection, which you can later query.
const mysql ...
You send the query as a string and in response callback with the answer is received.
The callback gives you error, array of rows and fields.
Each row contains all the column of the returned table. Here is a snippet for the following explanation.
connection.query('SELECT name,email from users', fu...
Since PHP objects don't inherit from any base class (including stdClass), there is no support for type hinting a generic object type.
For example, the below will not work.
<?php
function doSomething(object $obj) {
return $obj;
}
class ClassOne {}
class ClassTwo {}
$classOne= new...
Objects will often depend on other objects. Instead of creating the dependency in the constructor, the dependency should be passed into the constructor as a parameter. This ensures there is not tight coupling between the objects, and enables changing the dependency upon class instantiation. This has...
Putting a & (ampersand) in front of an argument will pass it as the method's block. Objects will be converted to a Proc using the to_proc method.
class Greeter
def to_proc
Proc.new do |item|
puts "Hello, #{item}"
end
end
end
greet = Greeter.new
%w(world l...
If you want to download an object from GCS that is publicly viewable, the simplest way is to use a web browser or a command line tool to fetch a URL with this pattern: https://storage.googleapis.com/bucketName/objectName.
Example: https://storage.googleapis.com/pub/someOfTheTeam.jpg
To ignore a file foo.txt in any directory you should just write its name:
foo.txt # matches all files 'foo.txt' in any directory
If you want to ignore the file only in part of the tree, you can specify the subdirectories of a specific directory with ** pattern:
bar/**/foo.txt # matches all file...
You can access SharedPreferences in several ways:
Get the default SharedPreferences file:
import android.preference.PreferenceManager;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
Get a specific SharedPreferences file:
public static final String PREF_FILE_NAM...
A class designed to be inherited-from is called a Base class. Care should be taken with the special member functions of such a class.
A class designed to be used polymorphically at run-time (through a pointer to the base class) should declare the destructor virtual. This allows the derived parts of...
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
...
If you have an existing class that you'd like to use, perform Step 2 and then skip to Step 5. (For some cases, I had to add an explicit #import <Foundation/Foundation.h to an older ObjC File)
Step 1: Add Objective-C Implementation -- .m
Add a .m file to your class, and name it CustomObje...
Step 1: Create New Swift Class
Add a .swift file to your project, and name it MySwiftObject.swift
In MySwiftObject.swift:
import Foundation
class MySwiftObject : NSObject {
var someProperty: AnyObject = "Some Initializer Val"
init() {}
func someFunction(someArg...
An alternative to extending Enumeration is using sealed case objects:
sealed trait WeekDay
object WeekDay {
case object Mon extends WeekDay
case object Tue extends WeekDay
case object Wed extends WeekDay
case object Thu extends WeekDay
case object Fri extends WeekDay
case objec...
The number of seconds from the current date and time for the new date. Use a negative value to specify a date before the current date.
For doing this we have a method named dateWithTimerIntervalSinceNow(seconds: NSTimeInterval) -> NSDate (Swift) or + (NSDate*)dateWithTimeIntervalSinceNow:(NSTime...
Get the description of an specific property in an object.
var sampleObject = {
hello: 'world'
};
Object.getOwnPropertyDescriptor(sampleObject, 'hello');
// Object {value: "world", writable: true, enumerable: true, configurable: true}
Compare method
Either you implement a compare-method for your object:
- (NSComparisonResult)compare:(Person *)otherObject {
return [self.birthDate compare:otherObject.birthDate];
}
NSArray *sortedArray = [drinkDetails sortedArrayUsingSelector:@selector(compare:)];
NSSortDescriptor
NSS...
You may want to create a duplicate of a table:
CREATE TABLE ClonedEmployees AS SELECT * FROM Employees;
You can use any of the other features of a SELECT statement to modify the data before passing it to the new table. The columns of the new table are automatically created according to the selec...