I have read and watched a lot of different Dagger2 tutorials but most of them are too long or hard to understand so I decided to write a new simple and short tutorial for Dagger2, I hope you like it.
Why we need it?
Simplifies access to shared instances: It provides a simple way to obtain refere...
Min-Heap
1
/ \
2 3
/ \ / \
4 5 6 7
The above tree is a Min-Heap since the root is the minimum among all the nodes present in the tree.The same property is followed by all the nodes in the tree.
Max-Heap
7
/ \
6 5
/ \ /...
// Import the action types to recognize them
import { ACTION_ERROR, ACTION_ENTITIES_LOADED, ACTION_ENTITY_CREATED } from './actions';
// Set up a default state
const initialState = {
error: undefined,
entities: [],
loading: true
};
// If no state is provided, we take the defa...
Algorithm
This algorithm is a two step process.First we create a auxiliary array lps[] and then use this array for searching the pattern.
Preprocessing :
We pre-process the pattern and create an auxiliary array lps[] which
is used to skip characters while matching.
Here lps[] indicates longes...
Suppose we have an API which allows us to get object metadata in single request (getAllPets), and other request which have full data of single resource (getSinglePet). How we can query all of them in a single chain?
public class PetsFetcher {
static class PetRepository {
List<Integer&g...
<?php
//Creating Connection to MySQL database using MySQLi
$mysqli = mysqli_connect("IP ADDRESS OR DOAMIN", "username", "password", "database_name");
//Executing Query in the Database using MySQLi
$result = mysqli_query($mysqli, "SELECT * FROM T...
Let's assume we have a Dogs application, then our model will be a Dog class.
DatabaseReference reference = FirebaseDatabase.getInstance().getReference().child("dogs");
This is how to send a Dog to the database, a new unique dog and set the dog with the key.
String key = reference.push...
import csv
#------ We will write to CSV in this function ------------
def csv_writer(data, path):
#Open CSV file whose path we passed.
with open(path, "wb") as csv_file:
writer = csv.writer(csv_file, delimiter=',')
for line in data:
...
JSON data
{
"name" : { "first" : "Joe", "last" : "Sixpack" },
"gender" : "MALE",
"verified" : false,
"userImage" : "keliuyue"
}
It takes two lines of Java to turn it into a User insta...
Generating simple blog engine
rails plugin new [engine name] --mountable
Famous engines examples are
Device (authentication gem for rails)
Spree (Ecommerce)
Use Spring REST Docs to document your services. It's a powerful framework which makes sure that the Service logic is always inline with the documentation. In order to do so, you would have to write integration tests for your services.
If there is any mismatch in the documentation & service beha...
Encoded URL
http%3A%2F%2Fwww.foo.com%2Findex.php%3Fid%3Dqwerty
Use this command to decode the URL
echo "http%3A%2F%2Fwww.foo.com%2Findex.php%3Fid%3Dqwerty" | sed -e "s/%\([0-9A-F][0-9A-F]\)/\\\\\x\1/g" | xargs -0 echo -e
Decoded URL (result of command)
http://www.foo...
In the example below, the calculateShippingPrice method calculates shipping cost, which takes some processing time. In a real world example, this would e.g. be contacting another server which returns the price based on the weight of the product and the shipping method.
By modeling this in an async ...
REM Truncate table (for testing)
SQLCMD -Q "TRUNCATE TABLE TestDatabase.dbo.myNative;"
REM Import data
bcp TestDatabase.dbo.myNative IN D:\BCP\myNative.bcp -T -n
REM Review results
SQLCMD -Q "SELECT * FROM TestDatabase.dbo.myNative;"
To make the use of the adapter pattern and the kind of situation when it may be applied more imaginable, a small, simple and very concrete example is given here.
There will be no code in here, just UML and a description of the example situation and its problem. Admittedly, the UML content is writte...