Skip to content

Instantly share code, notes, and snippets.

View ae6rt's full-sized avatar

Mark Petrovich ae6rt

  • Petaluma, CA
View GitHub Profile
@ae6rt
ae6rt / gist:0e4f4bc66a17d275af08
Created November 14, 2014 16:47
git logging to-file example
package main
import (
"flag"
"log"
"os"
)
var (
logFile = flag.String("log-file", "", "Log file name")
@ae6rt
ae6rt / gist:6671f5762e2144d18c8c
Created November 7, 2014 18:05
Go Makefile prototype
NAME := stashkins
ARCH := amd64
VERSION := 1.0
DATE := $(shell date)
COMMIT_ID := $(shell git rev-parse --short HEAD)
SDK_INFO := $(shell go version)
LD_FLAGS := -X main.version $(VERSION) -X main.commit $(COMMIT_ID) -X main.buildTime '$(DATE)' -X main.sdkInfo '$(SDK_INFO)'
all: clean binaries package
@ae6rt
ae6rt / gist:57a123563317aed603ee
Last active August 29, 2015 14:07
.emacs init file
(add-to-list 'load-path "/Users/mpetrovic/.emacs.d/")
(require 'go-mode-load)
(add-hook 'before-save-hook 'gofmt-before-save)
(require 'auto-complete-config)
(add-to-list 'ac-dictionary-directories "~/.emacs.d/ac-dict")
(ac-config-default)
(require 'go-autocomplete)
(require 'auto-complete-config)
;; (setq auto-save-visited-file-name t)
@ae6rt
ae6rt / gist:2caef0df93d29a60ec8a
Created October 1, 2014 18:59
Autowired no more
Good:
@Configuration
@EnableSwagger
public class SwaggerConfiguration {
public static final List<String> DEFAULT_INCLUDE_PATTERNS = Arrays.asList("^(?!/error|/internal/).*$");
private static final String SWAGGER_GROUP = "";
@Bean
public SwaggerSpringMvcPlugin swaggerPlugin(SpringSwaggerConfig springSwaggerConfig) {
@ae6rt
ae6rt / gist:38b23e9ed90f752851f6
Created September 21, 2014 20:08
Examine specific network errors in Go for more failure information
if err, ok := err.(net.Error); ok {
if err.Timeout() {
responseCode = http.StatusGatewayTimeout
fmt.Printf("Timeout\n")
}
}
@ae6rt
ae6rt / gist:5a9b5e34c242a8e982db
Created September 19, 2014 16:08
Give us your interfaces
In org.apache.curator.x.discovery.ServiceInstanceBuilder
private static final AtomicReference<LocalIpFilter> localIpFilter = new AtomicReference<LocalIpFilter>
(
new LocalIpFilter()
{
@Override
public boolean use(NetworkInterface nif, InetAddress adr) throws SocketException
{
return (adr != null) && !adr.isLoopbackAddress() && (nif.isPointToPoint() || !adr.isLinkLocalAddress());
@ae6rt
ae6rt / gradle-wsdl
Created February 8, 2014 12:56
Gradle build snippet to generate Java from WSDL
configurations {
jaxws
}
dependencies {
jaxws 'com.sun.xml.ws:jaxws-tools:2.1.4'
}
task wsimport {
ext.destDir = file("${projectDir}/src/main/generated")
@ae6rt
ae6rt / draininputstream
Last active August 22, 2018 17:36
Java: drain an inputstream of bytes
private byte[] drainInputStream(InputStream is) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[8192];
int bytesRead;
while ((bytesRead = is.read(buffer)) != -1) {
baos.write(buffer, 0, bytesRead);
}
return baos.toByteArray();
}
@ae6rt
ae6rt / jsonpp.py
Created December 23, 2013 13:33
JSON pretty printer
cat ~/bin/jsonpp.py
#!/usr/bin/python
import sys, json
print json.dumps(json.load(sys.stdin), sort_keys=True, indent=4)
@ae6rt
ae6rt / omitemptybuild.gradle
Last active December 31, 2015 20:59
In a multiproject Gradle build with potentially empty intermediate directories, here is how to avoid empty build/ directories. Only apply the java plugin to directories containing actual source.
afterEvaluate { project ->
configure(subprojects.findAll { new File(it.projectDir, "src").exists() }) {
apply plugin: 'java'
compileJava {
options.compilerArgs << '-Xlint:unchecked'
}
sourceCompatibility = targetCompatibility = 1.6
tasks.withType(Test) {