<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Programming on Infinite Script</title><link>https://www.infinitescript.com/categories/programming/</link><description>Recent content in Programming on Infinite Script</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Sun, 24 Jul 2022 15:22:00 +0000</lastBuildDate><atom:link href="https://www.infinitescript.com/categories/programming/index.xml" rel="self" type="application/rss+xml"/><item><title>Build an iOS App from Scratch with SwiftUI</title><link>https://www.infinitescript.com/2022/07/build-an-ios-app-from-scratch-with-swiftui/</link><pubDate>Sun, 24 Jul 2022 15:22:00 +0000</pubDate><guid>https://www.infinitescript.com/2022/07/build-an-ios-app-from-scratch-with-swiftui/</guid><description>&lt;h2 id="background"&gt;Background&lt;/h2&gt;&#10;&lt;p&gt;On Valentine&amp;rsquo;s day 2021 I put together a small static website, &lt;a href="https://love.haozhexie.com"&gt;Infinite Love&lt;/a&gt;, to hold a handful of pictures. Because it is static, adding a new photo means editing the source and redeploying, not something you want to do from your phone. So I set out to wrap it in an iOS app with a proper &amp;ldquo;new post&amp;rdquo; button.&lt;/p&gt;&#10;&lt;p&gt;I had done plenty of web development, but this was my first time writing anything for iOS. What follows is the walkthrough I wish I&amp;rsquo;d had: taking an empty Xcode project all the way to an app running on a real iPhone.&lt;/p&gt;</description></item><item><title>Build PyTorch Extensions with CUDA and CFFI</title><link>https://www.infinitescript.com/2018/03/build-pytorch-extensions-with-cuda-and-cffi/</link><pubDate>Wed, 28 Mar 2018 12:30:58 +0000</pubDate><guid>https://www.infinitescript.com/2018/03/build-pytorch-extensions-with-cuda-and-cffi/</guid><description>&lt;blockquote&gt;&#10;&lt;p&gt;&lt;strong&gt;Deprecated warning&lt;/strong&gt;: PyTorch 1.0+ replaced the old TH/THC tensor backend with ATen, and the &lt;code&gt;torch.utils.ffi&lt;/code&gt; toolchain described here was removed along the way. If you target PyTorch 1.0 or newer, write your extensions with &lt;code&gt;torch.utils.cpp_extension&lt;/code&gt; instead, see &lt;a href="https://github.com/hzxie/GRNet/tree/master/extensions"&gt;this GitHub repository&lt;/a&gt; for a working example. The article below documents the older CFFI-based approach and is kept for reference.&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;p&gt;Python is one of the most popular languages for deep learning, but as an interpreted language it is slow at tight numerical loops. Most of the time this does not matter, because the heavy lifting happens inside libraries written in C and CUDA. It starts to matter the moment you need an operation that the framework does not provide out of the box.&lt;/p&gt;</description></item><item><title>Lua in a Nutshell: A Quick Tutorial for Lua</title><link>https://www.infinitescript.com/2018/01/lua-in-a-nutshell-a-quick-tutorial-for-lua/</link><pubDate>Tue, 09 Jan 2018 02:10:34 +0000</pubDate><guid>https://www.infinitescript.com/2018/01/lua-in-a-nutshell-a-quick-tutorial-for-lua/</guid><description>&lt;p&gt;I&amp;rsquo;m reading source code written with Torch these days. &lt;a href="http://torch.ch/"&gt;Torch&lt;/a&gt; is a well-known deep learning framework written in Lua.&lt;/p&gt;&#10;&lt;p&gt;So I summarize its grammar and provide a quick tutorial here.&lt;/p&gt;&#10;&lt;h2 id="getting-started"&gt;Getting Started&lt;/h2&gt;&#10;&lt;p&gt;Like many languages, Lua is case-sensitive.&lt;/p&gt;&#10;&lt;p&gt;The following code outputs &amp;ldquo;Hello World&amp;rdquo; with Lua. Note that the semicolon at the end of a line is optional, like JavaScript.&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-lua" data-lang="lua"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;Hello World&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;You can use the interpreter of Lua in the command line:&lt;/p&gt;</description></item><item><title>Introduction to Java Virtual Machine</title><link>https://www.infinitescript.com/2015/08/introduction-to-java-virtual-machine-jvm/</link><pubDate>Fri, 07 Aug 2015 07:27:00 +0000</pubDate><guid>https://www.infinitescript.com/2015/08/introduction-to-java-virtual-machine-jvm/</guid><description>&lt;blockquote&gt;&#10;&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; This article has been &lt;strong&gt;updated for Java 8 and later&lt;/strong&gt;. The original 2015 version described the &lt;em&gt;Permanent Generation&lt;/em&gt; (PermGen), which Java 8 removed and replaced with &lt;em&gt;Metaspace&lt;/em&gt; (&lt;a href="https://openjdk.org/jeps/122"&gt;JEP 122&lt;/a&gt;); the garbage-collection section has also been rewritten to cover the modern HotSpot collectors (G1, ZGC, Shenandoah). The behaviors described here are those of HotSpot; other JVM implementations may differ.&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;h2 id="what-is-jvm"&gt;What is JVM?&lt;/h2&gt;&#10;&lt;p&gt;The Java Virtual Machine is the cornerstone of the Java platform. It is the component responsible for Java&amp;rsquo;s hardware and operating-system independence, the small size of its compiled code, and its ability to protect users from malicious programs.&lt;/p&gt;</description></item><item><title>Difference Between require and include in PHP</title><link>https://www.infinitescript.com/2014/11/difference-between-require-and-include-in-php/</link><pubDate>Fri, 14 Nov 2014 06:33:06 +0000</pubDate><guid>https://www.infinitescript.com/2014/11/difference-between-require-and-include-in-php/</guid><description>&lt;p&gt;One of the most common questions I get from PHP beginners is: why are there four different ways to pull one file into another?&lt;/p&gt;&#10;&lt;p&gt;There is &lt;a href="https://www.php.net/manual/en/function.include.php"&gt;include&lt;/a&gt;, &lt;a href="https://www.php.net/manual/en/function.include-once.php"&gt;include_once&lt;/a&gt;, &lt;a href="https://www.php.net/manual/en/function.require.php"&gt;require&lt;/a&gt;, and &lt;a href="https://www.php.net/manual/en/function.require-once.php"&gt;require_once&lt;/a&gt;. They look almost interchangeable, but picking the wrong one can either hide a fatal bug or crash a page that should have kept running.&lt;/p&gt;&#10;&lt;p&gt;The four are really just combinations of two independent choices:&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;strong&gt;&lt;code&gt;include&lt;/code&gt; vs &lt;code&gt;require&lt;/code&gt;&lt;/strong&gt;: what happens when the file is missing. &lt;code&gt;include&lt;/code&gt; emits a warning and keeps going; &lt;code&gt;require&lt;/code&gt; stops the script with a fatal error.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;plain vs &lt;code&gt;_once&lt;/code&gt;&lt;/strong&gt;: how many times the file may be loaded. The plain form loads the file on every call; the &lt;code&gt;_once&lt;/code&gt; form loads it at most once per request.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;One note before we start: despite the parentheses you often see, &lt;code&gt;include&lt;/code&gt; and &lt;code&gt;require&lt;/code&gt; are &lt;em&gt;language constructs&lt;/em&gt;, not functions. Both &lt;code&gt;require 'core.php';&lt;/code&gt; and &lt;code&gt;require('core.php');&lt;/code&gt; work, but the manual recommends the parenthesis-free form, which is what I&amp;rsquo;ll use throughout.&lt;/p&gt;</description></item><item><title>Java Collections Framework</title><link>https://www.infinitescript.com/2014/10/java-collections-framework/</link><pubDate>Thu, 30 Oct 2014 13:40:38 +0000</pubDate><guid>https://www.infinitescript.com/2014/10/java-collections-framework/</guid><description>&lt;p&gt;Almost all collections in Java are derived from the &lt;strong&gt;&lt;a href="http://docs.oracle.com/javase/8/docs/api/java/util/Collection.html"&gt;java.util.Collection&lt;/a&gt;&lt;/strong&gt; interface. Collection defines the basic parts of all collections. The interface states the add() and remove() methods for adding to and removing from a collection respectively. Also required is the toArray() method, which converts the collection into a simple array of all the elements in the collection. Finally, the contains() method checks if a specified element is in the collection. The Collection interface is a subinterface of &lt;strong&gt;&lt;a href="http://docs.oracle.com/javase/8/docs/api/java/lang/Iterable.html"&gt;java.lang.Iterable&lt;/a&gt;&lt;/strong&gt;, so any Collection may be the target of a for-each statement. (The Iterable interface provides the iterator() method used by for-each statements.) Additionally, Collection is a generic, so any collection can be written to store any class. For example, a &lt;code&gt;Collection&amp;lt;String&amp;gt;&lt;/code&gt; can hold strings, and the elements can be used as strings without any casting required.&lt;/p&gt;</description></item><item><title>The String Constant Pool</title><link>https://www.infinitescript.com/2014/10/the-string-constant-pool/</link><pubDate>Mon, 06 Oct 2014 08:47:31 +0000</pubDate><guid>https://www.infinitescript.com/2014/10/the-string-constant-pool/</guid><description>&lt;p&gt;The String Constant Pool is a JVM-wide cache of string literals: when different parts of your code reference a string with the same content, they can share a single &lt;code&gt;String&lt;/code&gt; object instead of allocating a new one each time. This is possible only because &lt;code&gt;String&lt;/code&gt; is immutable in Java, combined with the String interning mechanism. In other words, the pool is an application of the Flyweight design pattern.&lt;/p&gt;&#10;&lt;h2 id="string-pool-examples"&gt;String Pool Examples&lt;/h2&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-java" data-lang="java"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;String&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;s1&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;&amp;#34;Hello&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;String&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;s2&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;&amp;#34;Hello&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;String&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;s3&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;&amp;#34;Hel&amp;#34;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;&amp;#34;lo&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;String&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;s4&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;&amp;#34;Hel&amp;#34;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;lo&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;String&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;s5&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;Hello&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;String&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;s6&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;s5&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="na"&gt;intern&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s1&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;s2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// true&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s1&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;s3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// true&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s1&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;s4&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// false&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s4&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;s5&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// false&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s1&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;s6&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// true&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id="explanation"&gt;Explanation&lt;/h2&gt;&#10;&lt;p&gt;The references of &lt;code&gt;s1&lt;/code&gt;, &lt;code&gt;s2&lt;/code&gt;, &lt;code&gt;s3&lt;/code&gt;, and &lt;code&gt;s6&lt;/code&gt; all point to the same pooled object, while &lt;code&gt;s4&lt;/code&gt; and &lt;code&gt;s5&lt;/code&gt; do not. Here is why:&lt;/p&gt;</description></item><item><title>The 23 Gang of Three Design Patterns</title><link>https://www.infinitescript.com/2014/10/the-23-gang-of-three-design-patterns/</link><pubDate>Sat, 04 Oct 2014 02:09:13 +0000</pubDate><guid>https://www.infinitescript.com/2014/10/the-23-gang-of-three-design-patterns/</guid><description>&lt;p&gt;Design patterns represent the best practices used by experienced object-oriented software developers. Design patterns are solutions to general problems that software developers faced during software development. These solutions were obtained by trial and error by numerous software developers over quite a substantial period of time.&lt;/p&gt;&#10;&lt;p&gt;This tutorial will take you through step by step approach and examples using Java while learning Design Pattern concepts.&lt;/p&gt;&#10;&lt;p&gt;&#10;&#10;&lt;a href="https://www.infinitescript.com/2014/10/Design-Pattern-Relationships.webp" data-fancybox data-caption="Design-Pattern-Relationships"&gt;&#10; &lt;img src="https://www.infinitescript.com/2014/10/Design-Pattern-Relationships.webp" width="799" height="987" alt="Design-Pattern-Relationships" loading="lazy"&gt;&#10;&lt;/a&gt;&#10;&#10;&#10;&lt;/p&gt;&#10;&lt;h2 id="three-types-of-design-patterns"&gt;Three Types of Design Patterns&lt;/h2&gt;&#10;&lt;p&gt;Design patterns are divided into three fundamental groups: Behavioral Patterns, Creational Patterns, and Structural Patterns.&lt;/p&gt;</description></item><item><title>Difference between wait() and sleep(), yield() in Java</title><link>https://www.infinitescript.com/2014/09/difference-between-wait-and-sleep-yield-in-java/</link><pubDate>Tue, 23 Sep 2014 14:13:41 +0000</pubDate><guid>https://www.infinitescript.com/2014/09/difference-between-wait-and-sleep-yield-in-java/</guid><description>&lt;p&gt;The difference between wait() and sleep(), or between sleep() and yield(), is one of the oldest questions asked in Java interviews. All three pause the currently running thread, but they differ in who owns them, whether they release the lock, and how the thread wakes up again.&lt;/p&gt;&#10;&lt;h2 id="tldr"&gt;TL;DR&lt;/h2&gt;&#10;&lt;table&gt;&#10;&#9;&lt;thead&gt;&#10;&#9;&#9;&#9;&lt;tr&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;th&gt;&lt;/th&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;th&gt;&lt;code&gt;sleep()&lt;/code&gt;&lt;/th&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;th&gt;&lt;code&gt;yield()&lt;/code&gt;&lt;/th&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;th&gt;&lt;code&gt;wait()&lt;/code&gt;&lt;/th&gt;&#10;&#9;&#9;&#9;&lt;/tr&gt;&#10;&#9;&lt;/thead&gt;&#10;&#9;&lt;tbody&gt;&#10;&#9;&#9;&#9;&lt;tr&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;Defined in&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;&lt;code&gt;Thread&lt;/code&gt;&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;&lt;code&gt;Thread&lt;/code&gt;&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;&lt;code&gt;Object&lt;/code&gt;&lt;/td&gt;&#10;&#9;&#9;&#9;&lt;/tr&gt;&#10;&#9;&#9;&#9;&lt;tr&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;Static method?&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;Yes&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;Yes&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;No&lt;/td&gt;&#10;&#9;&#9;&#9;&lt;/tr&gt;&#10;&#9;&#9;&#9;&lt;tr&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;Releases the lock/monitor?&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;No&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;No&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;Yes&lt;/td&gt;&#10;&#9;&#9;&#9;&lt;/tr&gt;&#10;&#9;&#9;&#9;&lt;tr&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;Must hold the monitor (be in &lt;code&gt;synchronized&lt;/code&gt;)?&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;No&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;No&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;Yes&lt;/td&gt;&#10;&#9;&#9;&#9;&lt;/tr&gt;&#10;&#9;&#9;&#9;&lt;tr&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;Wakes up when&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;timeout expires or interrupted&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;the scheduler decides (maybe immediately)&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;&lt;code&gt;notify()&lt;/code&gt;/&lt;code&gt;notifyAll()&lt;/code&gt;, timeout, or interrupt&lt;/td&gt;&#10;&#9;&#9;&#9;&lt;/tr&gt;&#10;&#9;&#9;&#9;&lt;tr&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;Typical use&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;pause for a fixed time&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;hint to give up the CPU&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;coordination between threads&lt;/td&gt;&#10;&#9;&#9;&#9;&lt;/tr&gt;&#10;&#9;&lt;/tbody&gt;&#10;&lt;/table&gt;&#10;&lt;h2 id="javadoc-definition"&gt;JavaDoc Definition&lt;/h2&gt;&#10;&lt;h3 id="thread-class"&gt;Thread Class&lt;/h3&gt;&#10;&lt;p&gt;&lt;strong&gt;public static void sleep(long millis[, int nanos]) throws InterruptedException&lt;/strong&gt;&lt;/p&gt;</description></item><item><title>Object Initialization Order in Java</title><link>https://www.infinitescript.com/2014/09/object-initialization-order-in-java/</link><pubDate>Mon, 22 Sep 2014 08:51:05 +0000</pubDate><guid>https://www.infinitescript.com/2014/09/object-initialization-order-in-java/</guid><description>&lt;p&gt;An object is a chunk of memory bundled with the code that manipulates memory. In the memory, the object maintains its &lt;em&gt;state&lt;/em&gt; (the values of its instance variables), which can change and evolve throughout its lifetime. To get a newly-created object off to a good start, its newly-allocated memory must be initialized to a proper initial state. Here we take an in-depth look at the mechanisms Java uses to manage object initialization.&lt;/p&gt;</description></item><item><title>HashMap Internal Implementation Analysis in Java</title><link>https://www.infinitescript.com/2014/09/hashmap-internal-implementation-analysis-in-java/</link><pubDate>Tue, 09 Sep 2014 03:38:29 +0000</pubDate><guid>https://www.infinitescript.com/2014/09/hashmap-internal-implementation-analysis-in-java/</guid><description>&lt;p&gt;&lt;a href="https://docs.oracle.com/javase/8/docs/api/java/util/HashMap.html"&gt;HashMap&lt;/a&gt; is one of the most common topics in Java interviews, and &amp;ldquo;How does HashMap work?&amp;rdquo; has a deceptively simple one-line answer: &amp;ldquo;On the principle of hashing.&amp;rdquo; To say anything more, you need to know how hashing works and how HashMap applies it internally.&lt;/p&gt;&#10;&lt;p&gt;This post assumes you already know the basics of using a HashMap; if not, start with the official &lt;a href="https://docs.oracle.com/javase/8/docs/api/java/util/HashMap.html"&gt;Java docs&lt;/a&gt;. The walkthrough below uses the pre-Java-8 source as its baseline; wherever Java 8+ changed the implementation, an inline &lt;em&gt;Note&lt;/em&gt; flags it.&lt;/p&gt;</description></item><item><title>How To Convert Byte[] Array To String in Java</title><link>https://www.infinitescript.com/2013/11/how-to-convert-byte-array-to-string-in-java/</link><pubDate>Sun, 03 Nov 2013 08:00:51 +0000</pubDate><guid>https://www.infinitescript.com/2013/11/how-to-convert-byte-array-to-string-in-java/</guid><description>&lt;p&gt;It is common to convert a &lt;code&gt;String&lt;/code&gt; into a &lt;code&gt;byte[]&lt;/code&gt; array and back again. The catch is that &lt;em&gt;how&lt;/em&gt; you convert depends on what the bytes actually are: human-readable text in some encoding, or arbitrary binary data such as the output of a cipher. Using the wrong approach silently corrupts your data.&lt;/p&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; This post has been &lt;strong&gt;updated to always specify a charset explicitly&lt;/strong&gt; and to cover the binary-data case. The original advice — &lt;code&gt;new String(bytes)&lt;/code&gt; — relies on the platform&amp;rsquo;s default charset, which makes the result differ from machine to machine, and it cannot round-trip binary data at all. Both pitfalls are addressed below.&lt;/p&gt;</description></item><item><title>Use SQLite in Qt</title><link>https://www.infinitescript.com/2013/07/use-sqlite-in-qt/</link><pubDate>Mon, 15 Jul 2013 15:03:48 +0000</pubDate><guid>https://www.infinitescript.com/2013/07/use-sqlite-in-qt/</guid><description>&lt;p&gt;SQLite is a lightweight, file-based database that needs no separate server process, which makes it a perfect fit for desktop applications that want to store data locally. Qt ships with a built-in SQLite driver as part of its SQL module, so you can talk to a database without pulling in any third-party dependency. This post walks through the few steps required to set it up and run your first queries.&lt;/p&gt;</description></item><item><title>Convert Excel Date into Timestamp in PHP</title><link>https://www.infinitescript.com/2013/04/convert-excel-date-into-timestamp/</link><pubDate>Fri, 05 Apr 2013 08:05:30 +0000</pubDate><guid>https://www.infinitescript.com/2013/04/convert-excel-date-into-timestamp/</guid><description>&lt;p&gt;Excel stores a date internally as a number of days since January 1, 1900.&lt;br&gt;&#10;For example: &amp;ldquo;June 9th, 2011 10:30 AM&amp;rdquo; would be stored as &amp;ldquo;40703.4375&amp;rdquo;.&lt;br&gt;&#10;40703 is the number of full days since 01/01/1900 and 0.4375 represents the time (10.5/24 = 0.4375).&lt;/p&gt;&#10;&lt;p&gt;When you process dates read from an Excel spreadsheet (&lt;em&gt;e.g.&lt;/em&gt;, using &lt;a href="https://github.com/phpoffice/phpexcel"&gt;PHPExcel&lt;/a&gt;) you often want to convert them into a UNIX timestamp, &lt;em&gt;i.e.&lt;/em&gt; a number of seconds elapsed since midnight of January 1, 1970 UTC.&lt;/p&gt;</description></item><item><title>Writing Your First Win32 Application with C++</title><link>https://www.infinitescript.com/2013/03/writing-your-first-windows-application-with-c/</link><pubDate>Wed, 20 Mar 2013 12:20:09 +0000</pubDate><guid>https://www.infinitescript.com/2013/03/writing-your-first-windows-application-with-c/</guid><description>&lt;p&gt;Welcome to the first windows tutorial. In this tutorial, I&amp;rsquo;ll give you the basic information on how to code in windows and we&amp;rsquo;ll go over a few important details first.&lt;/p&gt;&#10;&lt;h2 id="messages"&gt;Messages&lt;/h2&gt;&#10;&lt;p&gt;The basic windows program has two important functions inside. The first one is the event handler(I&amp;rsquo;ll talk about this one later on) and the second one is the main function(WinMain from now on). WinMain is similar to DOS&amp;rsquo; main function, in fact, WinMain is called from the DOS main function but in windows, we don&amp;rsquo;t have access to the DOS main; everything is covered up by windows. Windows introduces us to messages. A message could be easily described as a pile of data that gets sent to the event handler which then tells the window what to do. A message&amp;rsquo;s name is prefixed with WM(stands for Windows Message as you might have guessed?). There are a whole lot of messages that a window can handle, however, we&amp;rsquo;ll only need a few of them. You can use these messages in many ways. For example, the message WM_CREATE, can be used for initialization purposes, it gets sent to the window when it&amp;rsquo;s created, and WM_PAINT is used when you want to draw something on the screen, and so on, you get the image. Most of the messages get sent to the window automatically; for example, when you move your mouse around you send a message to windows, and any other actions like that send messages to windows. You can also send a message to your window yourself, but you&amp;rsquo;ll probably never need to.&lt;/p&gt;</description></item><item><title>C# - Run Application as Administrator Automatically</title><link>https://www.infinitescript.com/2012/08/c-run-application-as-administrator-automatically/</link><pubDate>Tue, 21 Aug 2012 14:46:13 +0000</pubDate><guid>https://www.infinitescript.com/2012/08/c-run-application-as-administrator-automatically/</guid><description>&lt;p&gt;In this tutorial, you will learn how you can run your application as an administrator automatically using Visual C#2012.&lt;/p&gt;&#10;&lt;h2 id="adding-an-application-manifest"&gt;Adding an Application Manifest&lt;/h2&gt;&#10;&lt;p&gt;Start by opening your C# Windows forms application.&lt;/p&gt;&#10;&lt;p&gt;Right click on your project name in the solution explorer and add a new item&amp;hellip;&lt;/p&gt;&#10;&lt;p&gt;Select an application manifest file:&lt;/p&gt;&#10;&lt;p&gt;&#10;&#10;&lt;a href="https://www.infinitescript.com/2012/08/Create-App-Mainfest.webp" data-fancybox data-caption="Create-App-Mainfest"&gt;&#10; &lt;img src="https://www.infinitescript.com/2012/08/Create-App-Mainfest.webp" width="640" height="407" alt="Create-App-Mainfest" loading="lazy"&gt;&#10;&lt;/a&gt;&#10;&#10;&#10;&lt;/p&gt;&#10;&lt;p&gt;Click add.&lt;/p&gt;&#10;&lt;h2 id="requiring-administrator-privileges"&gt;Requiring Administrator Privileges&lt;/h2&gt;&#10;&lt;p&gt;A new tab should open up, most of the codes in it are not important to us.&lt;br&gt;&#10;There is one line however that we need to change:&lt;/p&gt;</description></item><item><title>Regular Expression</title><link>https://www.infinitescript.com/2012/08/regular-expression/</link><pubDate>Fri, 03 Aug 2012 05:32:29 +0000</pubDate><guid>https://www.infinitescript.com/2012/08/regular-expression/</guid><description>&lt;p&gt;In computing, a regular expression is a specific pattern that provides concise and flexible means to &amp;ldquo;match&amp;rdquo; (specify and recognize) strings of text, such as particular characters, words, or patterns of characters. Common abbreviations for &amp;ldquo;regular expression&amp;rdquo; include regex and regexp.&lt;/p&gt;&#10;&lt;h2 id="basic-concepts"&gt;Basic Concepts&lt;/h2&gt;&#10;&lt;p&gt;A regular expression, often called a pattern, is an expression that specifies a set of strings. To specify such sets of strings, rules are often more concise than lists of a set&amp;rsquo;s members. For example, the set containing the three strings &amp;ldquo;Handel&amp;rdquo;, &amp;ldquo;Händel&amp;rdquo;, and &amp;ldquo;Haendel&amp;rdquo; can be specified by the pattern H(ä|ae?)ndel (or alternatively, it is said that the pattern matches each of the three strings). In most formalisms, if there exists at least one regex that matches a particular set then there exist an infinite number of such expressions. Most formalisms provide the following operations to construct regular expressions.&lt;/p&gt;</description></item></channel></rss>