Skip to content

Instantly share code, notes, and snippets.

@harschware
harschware / TestStopWatch.java
Last active October 23, 2018 22:54
Test NiFi StopWatch class - demonstrates bug at NIFI-5742
import org.apache.nifi.util.StopWatch;
import java.util.concurrent.TimeUnit;
class Scratch {
// https://github.com/apache/nifi/blob/02261311b3b3f765ebb394f8f101b0373a7fb3ab/nifi-commons/nifi-utils/src/main/java/org/apache/nifi/util/StopWatch.java#L77
public static void main(String[] args) {
StopWatch stopWatch = new StopWatch(true);
package harschware.sandbox.scratch;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import java.util.Arrays;
import java.util.Objects;
/**
import org.springframework.aop.target.HotSwappableTargetSource;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.GenericXmlApplicationContext;
/**
* Inspired by: https://stackoverflow.com/a/12808171/154461
*/
public class SwappableBeans {
public static void main(String... args) {
@harschware
harschware / livyResultForSchemaAsJson.json
Created May 15, 2018 22:22
Livy result for schema using %json magick
{
"code": "import org.apache.spark.sql._\nvar d = sqlContext.sql(\"SELECT tbl10.`venueid`, tbl10.`venuename`, tbl10.`venuecity`, tbl10.`venuestate`, tbl10.`venueseats`, tbl10.`processing_dttm` AS `venues_processing_dttm` FROM `concerts`.`venues` tbl10\")\nvar e = d.schema\n%json e\n",
"id": 7,
"output": {
"data": {
"application/json": [
{
"dataType": {},
"metadata": {
"map": {}
@harschware
harschware / livyResultForSchema.json
Created May 15, 2018 22:18
livy result shows dataframe.schema contains data types
{
"code": "import org.apache.spark.sql._\nvar d = sqlContext.sql(\"SELECT tbl10.`venueid`, tbl10.`venuename`, tbl10.`venuecity`, tbl10.`venuestate`, tbl10.`venueseats`, tbl10.`processing_dttm` AS `venues_processing_dttm` FROM `concerts`.`venues` tbl10\")\nd.schema\n",
"id": 5,
"output": {
"data": {
"text/plain": "import org.apache.spark.sql._\nd: org.apache.spark.sql.DataFrame = [venueid: int, venuename: string, venuecity: string, venuestate: string, venueseats: int, venues_processing_dttm: string]\nres2: org.apache.spark.sql.types.StructType = StructType(StructField(venueid,IntegerType,true), StructField(venuename,StringType,true), StructField(venuecity,StringType,true), StructField(venuestate,StringType,true), StructField(venueseats,IntegerType,true), StructField(venues_processing_dttm,StringType,true))\n"
},
"execution_count": 5,
"status": "ok"
},
@harschware
harschware / scalaLivyResult.json
Created May 11, 2018 19:47
Livy DataTypes are Missing from Schema
{
"code": "import org.apache.spark.sql._\nvar d = sqlContext.sql(\"SELECT tbl10.`venueid`, tbl10.`venuename`, tbl10.`venuecity`, tbl10.`venuestate`, tbl10.`venueseats`, tbl10.`processing_dttm` AS `venues_processing_dttm` FROM `concerts`.`venues` tbl10\")\nval e = d.take(2)\n%json e\n",
"id": 13,
"output": {
"data": {
"application/json": [
{
"schema": [
{
"dataType": {},
#!/usr/bin/perl
# Produces output found at the end of this script / after __END__
use TAP::Parser;
my $NO_DESC = <<EOF;
1..1
ok 1 # skip for a really good reason
EOF
@harschware
harschware / SSHJConnect.java
Created November 21, 2014 22:00
A class for connecting via public key exchange using SSHJ
package harschware.sandbox;
import java.io.IOException;
import java.security.Security;
import java.util.concurrent.TimeUnit;
import net.schmizz.sshj.SSHClient;
import net.schmizz.sshj.common.IOUtils;
import net.schmizz.sshj.connection.channel.direct.Session;
import net.schmizz.sshj.connection.channel.direct.Session.Command;
package com.hp.hpl.jena.sparql.path;
import static org.junit.Assert.assertEquals;
import java.io.File;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
2013-Oct-04 17:52:34.010 PDT DEBUG [main] [org.apache.jena.riot.stream.JenaIOEnvironment:createLocationMapper] [JenaIOEnvironment.java:181] [] [] [] - Failed to find configuration: location-mapping.ttl;location-mapping.rdf;location-mapping.n3;etc/location-mapping.rdf;etc/location-mapping.n3;etc/location-mapping.ttl
=== FILE CONTENTS ===
_:b0 <http://p> <http://o> .
=== MODEL CONTENTS ===
blank URI URI
Exception in thread "main" com.hp.hpl.jena.shared.BadURIException: Only well-formed absolute URIrefs can be included in RDF/XML output: <http://> Code: 57/REQUIRED_COMPONENT_MISSING in HOST: A component that is required by the scheme is missing.
at com.hp.hpl.jena.xmloutput.impl.BaseXMLWriter.checkURI(BaseXMLWriter.java:820)
at com.hp.hpl.jena.xmloutput.impl.BaseXMLWriter.xmlnsDecl(BaseXMLWriter.java:339)
at com.hp.hpl.jena.xmloutput.impl.Basic.writeRDFHeader(Basic.java:64)
at com.hp.hpl.jena.xmloutput.impl.Basic.writeBody(Basic.java:47)