Skip to content

Instantly share code, notes, and snippets.

View leadVisionary's full-sized avatar

Nicholas Vaidyanathan leadVisionary

View GitHub Profile
@leadVisionary
leadVisionary / Demo.java
Last active November 23, 2019 00:53
QRCode from an Image in Java
import java.io.InputStream;
import java.io.ByteArrayInputStream;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import com.google.zxing.client.j2se.BufferedImageLuminanceSource;
import com.google.zxing.LuminanceSource;
import com.google.zxing.BinaryBitmap;
import com.google.zxing.common.HybridBinarizer;
import com.google.zxing.qrcode.QRCodeReader;
import com.google.zxing.Result;
@leadVisionary
leadVisionary / AppendAsGZip.java
Created April 22, 2018 00:43
Why SelfEncapsulation?
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
@leadVisionary
leadVisionary / demo.html
Created February 21, 2018 03:49
Working ECMAScript modules
<html>
<head>
<title>An E-commerce retailer</title>
</head>
<body>
<h1> Hello <span id="greeting">Placeholder</span>!</h1>
<h2> Please <a href="buy/12345">buy</a> this product</h2>
</body>
<script src="greeting.js" type="module"></script>
<script type="module">
@leadVisionary
leadVisionary / demo.html
Created February 21, 2018 03:47
ECMAScript modules part dumb
<html>
<head>
<title>An E-commerce retailer</title>
</head>
<body>
<h1>
Hello <span id="greeting">Placeholder</span>!</h1>
<h2>
Please <a href="https://www.blogger.com/buy/12345">buy</a> this product</h2>
</body>
@leadVisionary
leadVisionary / demo.html
Created February 21, 2018 03:46
Trying ECMAScript modules part duh
<html>
<head>
<title>An E-commerce retailer</title>
</head>
<body>
<h1>
Hello <span id="greeting">Placeholder</span>!</h1>
<h2>
Please <a href="https://www.blogger.com/buy/12345">buy</a> this product</h2>
</body>
@leadVisionary
leadVisionary / cross_platform_span_update.js
Created February 21, 2018 03:42
First Attempt at ECMAScript modules
export default function crossPlatformSpanTextUpdate(span, text) {
if ('textContent' in span) {
span.textContent = text;
} else {
span.innerText = text;
}
}
@leadVisionary
leadVisionary / AllowMeToLetYouHandleErrors.java
Created January 24, 2013 21:38
How I prefer to handle Java's IllegalInvocationException.java
import java.lang.reflect.InvocationTargetException;
public class AllowMeToLetYouHandleErrors {
public static void main(String[] args) {
System.out.println("Yo, can I eat an error?");
try {
@leadVisionary
leadVisionary / HttpCourier.java
Created November 28, 2012 10:42
A study in expressive programming
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpGet;
@Test
public void testConfiguration_shouldHaveWrittenTheLaterOne() throws Exception {
ServiceReference[] allServiceReferences = ctx.getAllServiceReferences(ConfigurationAdmin.class.getName(), null);
for (ServiceReference serviceReference : allServiceReferences) {
ConfigurationAdmin service = (ConfigurationAdmin) ctx.getService(serviceReference);
try {
org.osgi.service.cm.Configuration configuration = service.getConfiguration("tests");
assertEquals("myvalue2", configuration.getProperties().get("mykey"));
return;
} catch (Exception e) {
@leadVisionary
leadVisionary / KarafTest.java
Created August 21, 2012 16:53
Karaf Testing with Pax Exam
@RunWith(JUnit4TestRunner.class)
@ExamReactorStrategy(AllConfinedStagedReactorFactory.class)
public class KarafTest {
@Inject
CommandProcessor commandProcessor;
@ProbeBuilder
public TestProbeBuilder probeConfiguration(TestProbeBuilder probe) {
probe.setHeader(Constants.DYNAMICIMPORT_PACKAGE,