tag:blogger.com,1999:blog-20834005800501658112024-03-05T14:38:50.084+00:00Illegal Argument ExceptionMiscellaneous Computer CodeUnknownnoreply@blogger.comBlogger112125tag:blogger.com,1999:blog-2083400580050165811.post-54634399137258111092017-02-12T19:40:00.001+00:002017-02-16T22:36:36.288+00:00Git: on a (Compute) Stick
How to make a home Git server out of an Intel Compute Stick STCK1A8LFC.
It is assumed readers have enough knowledge of Linux and IP networking to know when to alter instructions to suit their own network and needs.
Some of these instructions are destructive!
Requirements
Single-user Git server
Infrequent push/pull
Physically unobtrusive
Networked from any room - i.e. WiFi
McDowellhttp://www.blogger.com/profile/15240682237791734569noreply@blogger.com0tag:blogger.com,1999:blog-2083400580050165811.post-62269355582772445442016-09-19T20:42:00.002+01:002016-09-19T20:43:32.894+01:00Java: close any type in try-with-resources using lambdas
Java 7 introduced the AutoCloseable
interface for use in try-with-resources
statements. However, not every resource implements this interface. The
JDK's own StAX
resources don't; 3rd party types like SWT widgets or SNMP4J I/O classes may not be able to
for compile-time compatibility reasons.
This post looks at releasing any resource using Java 8 lambdas.
Using method references to McDowellhttp://www.blogger.com/profile/15240682237791734569noreply@blogger.com0tag:blogger.com,1999:blog-2083400580050165811.post-87116506186771326812016-03-05T13:19:00.000+00:002016-03-05T13:19:44.026+00:00Pacemaker: Observations on Building ClustersPacemaker is a cluster resource manager used in Red Hat/CentOS 6.5+/7.
This is a short post on considerations for building a server cluster using Pacemaker.
This is not a tutorial.
Clustering
A cluster is a democracy for computers.
The primary purpose of a cluster member (node) is voting on the availibility and viability of other members.
A cluster member does not necessarily have to do McDowellhttp://www.blogger.com/profile/15240682237791734569noreply@blogger.com0tag:blogger.com,1999:blog-2083400580050165811.post-68356003731544404352015-09-09T21:26:00.000+01:002015-09-09T21:26:26.967+01:00Python: Office 365 alerts on Linux
It is possible to use Microsoft's Office 365 with native Linux clients for mail and calendar:
Mozilla's Thunderbird with the Lightning plugin and the EWS provider
GNOME's Evolution
However, neither have proven reliable.
The web interface is good but being browser based has meeting and new mail alert limitations.
Fortunately, Office 365 has a REST API...
Some familiarity with Python is McDowellhttp://www.blogger.com/profile/15240682237791734569noreply@blogger.com0tag:blogger.com,1999:blog-2083400580050165811.post-19490687651890250592015-09-03T20:36:00.000+01:002015-09-03T20:42:47.922+01:00ISC DHCP: OMAPI wire protocolOMAPI: Object Management Application Programming Interface
This post briefly describes the OMAPI protocol for the Internet Systems Consortium DHCP server version 4.1-ESV-R11.
From the dhcpd man page:
The DHCP server provides the capability to modify some of its configuration while it is running, without stopping it, modifying its
database files, and restarting it. This capability McDowellhttp://www.blogger.com/profile/15240682237791734569noreply@blogger.com0tag:blogger.com,1999:blog-2083400580050165811.post-28036023699725628992015-07-04T12:08:00.000+01:002015-07-06T18:53:28.468+01:00Rust: RustDT IDE on Linux with Eclipse MarsThis is a quick guide to setting up an IDE for Rust using RustDT.
Familiarity with Linux and root access is assumed.
Modify commands to suit your preferences, paths, and/or the latest versions.
Stack:
Host: Debian 8.1.0 amd64 lxde (debian-live-8.1.0-amd64-lxde-desktop.iso)
Eclipse: Mars; JDK 8 runtime
Rust: 1.1.0
Documentation:
Installing Rust
RustDT User Guide
Files Used
McDowellhttp://www.blogger.com/profile/15240682237791734569noreply@blogger.com0tag:blogger.com,1999:blog-2083400580050165811.post-49492095035439042782015-05-26T22:16:00.001+01:002015-05-27T19:00:31.785+01:00Rust: print the program argumentsA simple example using Cargo in Rust 1.0 on Linux.
Install Rust if you haven't. Create a project:
$ cargo new hello --bin
This will create the files:
hello/Cargo.toml
hello/src/main.rs
Replace the contents of main.rs with:
use std::env;
fn main() {
for argument in env::args() {
println!("Hello, {}!", argument);
}
}
From the hello directory run:
$ cargo run World Kitty "to myMcDowellhttp://www.blogger.com/profile/15240682237791734569noreply@blogger.com0tag:blogger.com,1999:blog-2083400580050165811.post-38098056853519159712015-05-25T21:22:00.001+01:002015-05-27T18:58:02.669+01:00Blog: Google Code shutting down; code moved to GitHubMany previous posts link to https://code.google.com/p/illegalargumentexception/ but this resource is going away:
Hello,
Earlier today, Google announced we will be turning down Google Code Project Hosting. The service started in 2006 with the goal of providing a scalable and reliable way of hosting open source projects. Since that time, millions of people have contributed to open source McDowellhttp://www.blogger.com/profile/15240682237791734569noreply@blogger.com0tag:blogger.com,1999:blog-2083400580050165811.post-79445077869150410052015-05-15T20:21:00.002+01:002015-05-15T21:53:55.793+01:00Rust: is ready to roll (1.0.0 released)
$ sudo ./install.sh
install: creating uninstall script at /usr/local/lib/rustlib/uninstall.sh
install: installing component 'rustc'
install: installing component 'cargo'
install: installing component 'rust-docs'
Rust is ready to roll.
$ rustc --version
rustc 1.0.0 (a59de37e9 2015-05-13) (built 2015-05-14)
Rust has been released.
The sample 1.0.0-beta.4 code in previous posts still McDowellhttp://www.blogger.com/profile/15240682237791734569noreply@blogger.com0tag:blogger.com,1999:blog-2083400580050165811.post-35152760780331820012015-05-13T20:44:00.000+01:002015-05-13T20:47:49.002+01:00Rust: send and receive on localhost with UDPUDP it is the simple cousin of TCP. You send a message off into the ether, you might listen a period of time for a response, and the payloads are small enough to fit in a packet.
This post looks at sending and receiving packets in Rust.
use std::thread;
use std::net;
fn socket(listen_on: net::SocketAddr) -> net::UdpSocket {
let attempt = net::UdpSocket::bind(listen_on);
let mut socket;
McDowellhttp://www.blogger.com/profile/15240682237791734569noreply@blogger.com0tag:blogger.com,1999:blog-2083400580050165811.post-3311815976214356182015-05-13T20:43:00.000+01:002015-05-13T21:20:22.278+01:00Rust: start thread & return value on finishRust threads are relatively easy to spawn and pass results back from.
use std::thread;
pub fn add_in_future(i1: i32, i2: i32) -> i32 {
let handle = thread::spawn(move || {
i1 + i2
});
handle.join().unwrap()
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn test_future() {
let expected = 3;
let actual = add_in_future(1, 2);
assert_eq!(expected, actual);
}
}
McDowellhttp://www.blogger.com/profile/15240682237791734569noreply@blogger.com0tag:blogger.com,1999:blog-2083400580050165811.post-53980064443593712182015-05-13T20:42:00.000+01:002015-05-23T22:32:03.062+01:00Rust: serializing structs to bytesBack when I wrote C code for platform-dependent binary formats it was fairly common to perform stream I/O with structs and unions. This post looks at similar functionality in Rust.
use std::mem;
#[allow(dead_code)]
pub struct Ser {
prop: u32
}
pub fn to_bytes(ser: Ser) -> [u8; 4] {
unsafe { mem::transmute_copy::<Ser, [u8; 4]>(&ser) }
}
#[cfg(test)]
mod test {
use super::*;
#[testMcDowellhttp://www.blogger.com/profile/15240682237791734569noreply@blogger.com0tag:blogger.com,1999:blog-2083400580050165811.post-21647632898793489752015-05-13T20:40:00.000+01:002015-05-13T20:40:00.462+01:00Rust: the size of a structThis code determines the size of a data structure in byte terms.
use std::mem;
#[allow(dead_code)]
pub struct AStruct {
prop: u32
}
pub fn size_of_a_struct() -> usize {
mem::size_of::<AStruct>()
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn test_size() {
let expected = 4 as usize;
assert_eq!(expected, size_of_a_struct());
}
}
Rust provides the size_of function McDowellhttp://www.blogger.com/profile/15240682237791734569noreply@blogger.com0tag:blogger.com,1999:blog-2083400580050165811.post-65975090608585195192015-05-13T20:35:00.000+01:002015-05-13T20:35:00.808+01:00Rust: byte array to hex StringThis code allows you to express arbitrary octet sequences as hex.
pub fn to_hex_string(bytes: Vec<u8>) -> String {
let strs: Vec<String> = bytes.iter()
.map(|b| format!("{:02X}", b))
.collect();
strs.connect(" ")
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn test_to_hex_string() {
let bytes: Vec<u8> = McDowellhttp://www.blogger.com/profile/15240682237791734569noreply@blogger.com0tag:blogger.com,1999:blog-2083400580050165811.post-60261522652654529832015-05-13T20:30:00.000+01:002015-05-13T20:30:01.653+01:00Rust: network byte orderLanguages on different architectures might serialize the 32-bit unsigned int 15 as the byte sequences 00 00 00 0F (big-endian) or 0F 00 00 00 (little-endian) but network protocols generally prefer the former.
pub fn to_network_byte_order(n: u32) -> u32 {
n.to_be()
}
pub fn from_network_byte_order(n: u32) -> u32 {
u32::from_be(n)
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn McDowellhttp://www.blogger.com/profile/15240682237791734569noreply@blogger.com0tag:blogger.com,1999:blog-2083400580050165811.post-47050667340024383552015-05-13T20:25:00.000+01:002015-05-18T20:56:54.316+01:00Rust: UTF-8 byte array to StringRust has a string type that mandates UTF-8 for strings but at some point you need to turn raw octets into structures you can treat as character data.
pub fn utf8_to_string(bytes: &[u8]) -> String {
let vector: Vec<u8> = Vec::from(bytes);
String::from_utf8(vector).unwrap()
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn test_to_string() {
let bytes: [u8; 7] = [0x55, McDowellhttp://www.blogger.com/profile/15240682237791734569noreply@blogger.com0tag:blogger.com,1999:blog-2083400580050165811.post-13281752023369669102015-05-10T20:37:00.001+01:002015-05-18T20:53:25.500+01:00Rust: first lookRust is approaching its 1.0 release.
Rust is a systems programming language that runs blazingly fast, prevents almost all crashes*, and eliminates data races.
* In theory. Rust is a work-in-progress and may do anything it likes up to and including eating your laundry.
Rust has been under public development for a number of years.
Many search engine results will lead to obsolete code.
That Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-2083400580050165811.post-70852417460067018472015-05-06T21:34:00.000+01:002015-05-06T23:13:23.205+01:00UML: authoring simple sequence diagramsI had specific criteria for a UML sequence diagram generator:
Text-sourced
Simple
Off-line
Linux
seqdiag fits the bill.
There is an interactive shell if you want to try it out before installing.
Installing seqdiag on Ubuntu
My Linux distro report:
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 14.04.2 LTS
Release: 14.04
Codename: trustyMcDowellhttp://www.blogger.com/profile/15240682237791734569noreply@blogger.com0tag:blogger.com,1999:blog-2083400580050165811.post-58805982203385661012015-04-27T18:52:00.001+01:002015-04-27T18:54:56.052+01:00CentOS 6.6: redirecting SNMP traps from low ports to high ports with iptables
I have a Java application that processes SNMP traps.
Traps arrive on port 162.
Normally Java cannot listen on the low ports.
You can use setcap to permit it or run as root but these introduce potential security issues.
I opted to have the Java process listen on port 1162. Changes will have to be performed as root.
Redirecting incoming traps with iptables
Allow SNMP traffic in:
iptables -McDowellhttp://www.blogger.com/profile/15240682237791734569noreply@blogger.com0tag:blogger.com,1999:blog-2083400580050165811.post-37232264203371308272015-03-12T22:10:00.000+00:002015-04-08T19:51:39.024+01:00Java: handling null in getter method chains
Null is just something you need to deal with in Java.
This post looks at the mechanism for handling chained method calls without causing a
NullPointerException.
This post uses Java 8.
Beans
Here's a deep object graph for illustration purposes:
public class Root {
private Trunk trunk;
public Trunk getTrunk() { return trunk; }
public void setTrunk(Trunk trunk) { this.trunk =McDowellhttp://www.blogger.com/profile/15240682237791734569noreply@blogger.com0tag:blogger.com,1999:blog-2083400580050165811.post-57381290028264326392014-11-16T15:26:00.000+00:002014-11-18T20:28:19.102+00:00Java: equals and hashCode performanceI wanted to benchmark KλudJe's equals/hashCode implementation against common alternatives.
I used JMH 1.2 to measure performance.
POJO
A POJO with four properties was used as a test source:
public abstract class Pojo {
protected final long id;
protected final String data;
protected final java.time.Instant time;
protected final int count;
//constructors etc.
SubclassesMcDowellhttp://www.blogger.com/profile/15240682237791734569noreply@blogger.com0tag:blogger.com,1999:blog-2083400580050165811.post-69982413959884207942014-08-10T17:55:00.000+01:002014-08-10T17:55:34.305+01:00Java: easy equals/hashCode/toString (less boilerplate; no magic)
This post describes a way to implement the
equals
hashCode
and
toString
methods with relative brevity using Java 8 and KλudJe.
Plain Old Java Object
Consider this simple, three property type:
import java.time.LocalDate;
import java.util.Objects;
public class PersonPojo {
private final long id;
private final String name;
private final LocalDate dateOfBirth;
public PersonPojo(McDowellhttp://www.blogger.com/profile/15240682237791734569noreply@blogger.com0tag:blogger.com,1999:blog-2083400580050165811.post-22443297934189323662014-07-29T20:53:00.002+01:002014-07-29T20:53:34.004+01:00I18N: dead links; Michael Kaplan's blog
Many of the links on this blog useful for Windows internationalization are dead as Microsoft has ceased hosting them.
Some of the information may still be available here.
McDowellhttp://www.blogger.com/profile/15240682237791734569noreply@blogger.com0tag:blogger.com,1999:blog-2083400580050165811.post-21483622798203572102014-07-22T23:43:00.000+01:002014-07-29T20:15:39.417+01:00Java: arbitrary functional interfaces and checked exceptions in Java 8The last couple of posts have covered how to handle exceptions with Java 8 functional interfaces.
This post discusses how to handle arbitrary functional interfaces as of KλudJe 0.2.
Java 8 Method References can be Functional Interface Type Adapters
Exploiting Adapters with KλudJe
N-ary Interfaces
Generating Exception Adapting Types
Java 8 Method References can be Functional McDowellhttp://www.blogger.com/profile/15240682237791734569noreply@blogger.com0tag:blogger.com,1999:blog-2083400580050165811.post-85647742778152620322014-07-19T19:38:00.001+01:002014-07-22T19:22:09.665+01:00Java: lambdas, streams and IOExceptionThe last post discussed exception handling with KλudJe in broad terms.
This post presents a more practical example with the Stream type and I/O.
Streaming I/O Example
Here is a simple type that counts the number of lines in a collection of files:
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collection;
import java.util.Map;
import McDowellhttp://www.blogger.com/profile/15240682237791734569noreply@blogger.com0