Tutorial by Examples

Getting a single frame from a movie ( supports only AVC, H.264 in MP4, ISO BMF, Quicktime container ): int frameNumber = 150; BufferedImage frame = FrameGrab.getFrame(new File("filename.mp4"), frameNumber); ImageIO.write(frame, "png", new File("frame_150.png")); G...
Java Singleton Pattern To implement Singleton pattern, we have different approaches but all of them have following common concepts. Private constructor to restrict instantiation of the class from other classes. Private static variable of the same class that is the only instance of the class. P...
In order to set the pagination style for the entire project, you need to set the DEFAULT_PAGINATION_CLASS and PAGE_SIZE on the project settings. To do so, go to settings.py and on the REST_FRAMEWORK variable, add the following: REST_FRAMEWORK = { 'DEFAULT_PAGINATION_CLASS': 'rest_fr...
Call from main() // Simple lazy loader - not thread safe HolderNaive holderNaive = new HolderNaive(); Heavy heavy = holderNaive.getHeavy(); Heavy.class /** * * Heavy objects are expensive to create. * */ public class Heavy { private static final Logger LOGGER = LoggerFactory.ge...
Download the latest JAR or grab via Maven: <dependency> <groupId>com.squareup.okio</groupId> <artifactId>okio</artifactId> <version>1.12.0</version> </dependency> or Gradle: compile 'com.squareup.okio:okio:1.12.0'
Decoding the chunks of a PNG file demonstrates Okio in practice. private static final ByteString PNG_HEADER = ByteString.decodeHex("89504e470d0a1a0a"); public void decodePng(InputStream in) throws IOException { try (BufferedSource pngSource = Okio.buffer(Okio.source(in))) { Byt...
ByteStrings and Buffers Okio is built around two types that pack a lot of capability into a straightforward API: ByteString is an immutable sequence of bytes. For character data, String is fundamental. ByteString is String's long-lost brother, making it easy to treat binary data as a value. This c...
Open the C# project Right-click on the solution -> Add -> New Project… (Figure 1) Go to Installed -> Visual C# -> Test Click on Unit Test Project Give it a name and click OK (Figure 2) The unit test project is added to the solution (Figure 3) Adding the referen...
Method 1 Go to your unit test class in the unit test project Write a unit test [Testclass] public class UnitTest1 { [TestMethod] public void TestMethod1() { //Arrange ApplicationToTest.Calc ClassCalc = new ApplicationToTest.Calc(); int expectedResul...
To see you unit tests go to Test -> Windows -> Test Explorer (Figure 1) This will open an overview of all the tests in the application (Figure 2) In the figure above you can see that the example has one unit test and it hasn’t been run yet You can double-click on a tes...
To see you unit tests go to Test -> Windows -> Code Coverage Results (Figure 1) It will open the following window (Figure 2) The window is now empty Go to the Test menu -> Analyze Code Coverage (Figure 3) The tests will now be run as well (See the results in the T...
Starting with Android 3.1 all applications, upon installation, are placed in a stopped state. While in stopped state, the application will not run for any reason, except by a manual launch of an activity, or an explicit intent that addresses an activity ,service or broadcast. When writing system ap...
Override Pagination Style: Every available pagination style can be overridden by creating a new class that inherits from one of the available styles and then alters its parameters: class MyPagination(PageNumberPagination): page_size = 20 page_size_query_param = 'page_size' max_page...
The nil-coalescing operator <OPTIONAL> ?? <DEFAULT VALUE> unwraps the <OPTIONAL> if it contains a value, or returns <DEFAULT VALUE> if is nil. <OPTIONAL> is always of an optional type. <DEFAULT VALUE> must match the type that is stored inside <OPTIONAL>. T...
We can perform a GROUP BY ... COUNT or a GROUP BY ... SUM SQL equivalent queries on Django ORM, with the use of annotate(), values(), order_by() and the django.db.models's Count and Sum methods respectfully: Let our model be: class Books(models.Model): title = models.CharField() ...
Lets assume that we have a complex api, with many generic views and some generic viewsets. We want to enable PageNumberPagination to every view, except one (either generic view or viewset, does not make a difference) for which we want a customized case of LimitOffsetPagination. To achieve that we n...
:help map-modes :nunmap can also be used outside of a monastery.
A generalization of std::condition_variable, std::condition_variable_any works with any type of BasicLockable structure. std::cv_status as a return status for a condition variable has two possible return codes: std::cv_status::no_timeout: There was no timeout, condition variable was notified st...
Function definition: def run_training(train_X, train_Y): Inputs variables: X = tf.placeholder(tf.float32, [m, n]) Y = tf.placeholder(tf.float32, [m, 1]) Weight and bias representation W = tf.Variable(tf.zeros([n, 1], dtype=np.float32), name="weight") b = tf.Variable(tf.zeros([...
def main(): train_X, train_Y = read_data() train_X = feature_normalize(train_X) run_training(train_X, train_Y) Note: remember review functions dependencies. read_data, feature_normalize and run_training

Page 1248 of 1336