If you are inside a folder of a git repository it might be nice to show the current branch you are on. In ~/.bashrc or /etc/bashrc add the following (git is required for this to work):
function prompt_command {
# Check if we are inside a git repository
if git status > /dev/null 2>&a...
This example is based on a blog post by Nicolas Hery. It utilizes ES6 classes and ReactJS's lifecycle methods to keep the D3 component updated
d3_react.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Hello, d3React!</title>...
Suppose the following generic interface has been declared:
public interface MyGenericInterface<T> {
public void foo(T t);
}
Below are listed the possible ways to implement it.
Non-generic class implementation with a specific type
Choose a specific type to replace the formal type ...
Swipe gestures allow you to listen for the user moving their finger across the screen quickly in a certain direction.
Swift
override func viewDidLoad() {
super.viewDidLoad()
// Swipe (right and left)
let swipeRightGesture = UISwipeGestureRecognizer(target: self, action: #selector(...
//Creates a Random instance with a seed of 12345.
Random random = new Random(12345L);
//Gets a ThreadLocalRandom instance
ThreadLocalRandom tlr = ThreadLocalRandom.current();
//Set the instance's seed.
tlr.setSeed(12345L);
Using the same seed to generate random numbers will return the sa...
Jetty is a Java-based, open-source project providing a HTTP server/client and javax.servlet container. Jetty also provides support for HTTP/2, JMX, JNDI, OSGi JAAS and other integrations. Jetty can be deployed as a standard distribution package or as an embeddable web server, allowing users to custo...
The current release version of Jetty is 9.4. Support is still provided for Jetty 9.2 and 9.3, and maintenance releases are provided for Jetty 7 and Jetty 8 when needed.
The most up-to-date distributions can be found on the Jetty Downloads page. It is worth noting that current releases of Jetty requ...
Bytecode is the set of instructions used by the JVM. To illustrate this let's take this Hello World program.
public static void main(String[] args){
System.out.println("Hello World");
}
This is what it turns into when compiled into bytecode.
public static main([Ljava/lang/String...
Firstly the classes from the jar need to be loaded. We'll use three methods for this process:
loadClasses(File)
readJar(JarFile, JarEntry, Map)
getNode(byte[])
Map<String, ClassNode> loadClasses(File jarFile) throws IOException {
Map<String, ClassNode> classes = new HashMap&...
/**
* Load a class by from a ClassNode
*
* @param cn
* ClassNode to load
* @return
*/
public static Class<?> load(ClassNode cn) {
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
return new ClassDefiner(ClassLoader.getSystemClassLoader()).get(cn....
# Process substitution with paste command is common
# To compare the contents of two directories
paste <( ls /path/to/directory1 ) <( ls /path/to/directory1 )
To write data to a file using Channel we need to have the following steps:
First, we need to get an object of FileOutputStream
Acquire FileChannel calling the getChannel() method from the FileOutputStream
Create a ByteBuffer and then fill it with data
Then we have to call the flip() method of ...
We can use PrintStream class to write a file. It has several methods that let you print any data type values. println() method appends a new line.
Once we are done printing, we have to flush the PrintStream.
import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.time.Local...
PHP provides support for the HTTP PUT method used by some clients to store files on a server. PUT requests are much simpler than a file upload using POST requests and they look something like this:
PUT /path/filename.html HTTP/1.1
Into your PHP code you would then do something like this:
<?p...
Sometimes we need to fetch and print the value of a TensorFlow variable to guarantee our program is correct.
For example, if we have the following program:
import tensorflow as tf
import numpy as np
a = tf.Variable(tf.random_normal([2,3])) # declare a tensorflow variable
b = tf.random_normal([2...
Consider the following three equations:
x0 + 2 * x1 + x2 = 4
x1 + x2 = 3
x0 + x2 = 5
We can express this system as a matrix equation A * x = b with:
A = np.array([[1, 2, 1],
[0, 1, 1],
[1, 0, 1]])
b = np.array([4, 3, 5])
Then, use np.linalg....