Skip to content

Instantly share code, notes, and snippets.

View rickcrawford's full-sized avatar

Rick Crawford rickcrawford

View GitHub Profile
@rickcrawford
rickcrawford / ElasticSearchTest.java
Created July 11, 2012 19:54
I spent a couple hours trying to figure out the client API for ElasticSearch, so I wrote this simple unit test to try out some of the features.
package com.typeahead.dropwizard.elasticsearch;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import java.util.Date;
import java.util.Map;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
import org.elasticsearch.action.admin.cluster.node.info.NodeInfo;
#!/bin/sh
#
# openresty adapted script to start and stop the openresty compiled
# nginx daemon
# --- original nginx comment ---
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
@rickcrawford
rickcrawford / gist:8188206
Last active January 1, 2016 19:09
Convert strings with ascii escaped characters to a valid java string. For example \x04 would escape to \n
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang.StringUtils;
public class Utils {
public static String decodeHex(String str) {
if (StringUtils.isBlank(str)) {
return str;
}
return StringEscapeUtils.unescapeJava(
str.replaceAll("(?i)\\\\x([0-9a-f]{2})", "\\\\u00$1"))
.trim();
@rickcrawford
rickcrawford / l1cache.js
Last active August 29, 2015 13:56
Sizable Hash with expiring keys for storing objects in memory in Node.js. Oldest object will be removed from the hash once the limit is reached.
//created by Rick Crawford - https://github.com/rickcrawford
var _ = require("underscore"),
bunyan = require('bunyan');
var log = bunyan.createLogger({
name: "test",
stream: process.stdout,
level: 'debug'
});
this is a test HTML file
<div style="color: red">
red text here
</div>
@rickcrawford
rickcrawford / Dockerfile
Last active March 31, 2017 18:14
Docker image to build go from source
FROM gcr.io/google-appengine/debian8:latest
# Install Go
RUN apt-get update \
&& apt-get install -y \
curl \
gcc \
git \
build-essential \
ca-certificates \
@rickcrawford
rickcrawford / cert.go
Last active October 17, 2017 23:46
AES encryption example
package main
import (
"crypto/tls"
"fmt"
"log"
"net"
"net/http"
"os"
"os/signal"
@rickcrawford
rickcrawford / README.md
Created September 5, 2017 22:58
Getting started with Go
@rickcrawford
rickcrawford / golang_public_gcs_bucket.md
Last active July 16, 2022 15:00
Golang Read from a GCS Cloud Storage bucket

Read data from a public bucket using gzip compression.

First bit of code opens a bucket and lists contents.

Next reads a gzip json file and deserializes it to an array. Please note not very efficient for a large array since the byte array is loaded into memory.

package main

import (
	"compress/gzip"
@rickcrawford
rickcrawford / gcs_create_and_read_pubsub.md
Created November 27, 2017 03:42
Create a GCS topic if it doesn't exist, then creates messages

Checks if a topic exists. If it doesn't it will be created. Next it will create messages on that topic with a new subscription.

package main

import (
	"context"
	"log"
	"time"