Skip to content

Instantly share code, notes, and snippets.

View wblakecaldwell's full-sized avatar

Blake Caldwell wblakecaldwell

View GitHub Profile
@wblakecaldwell
wblakecaldwell / ClassLoggerFactory.java
Last active December 27, 2015 18:09
Java Logger Factory that uses the stack trace to infer the logger name, allowing copy/paste.
package net.blakecaldwell.safehibernate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Factory for log messages, picking the enclosing class as the
* logger. This is safe from copypasta.
*
* Use: private static Logger logger = ClassLoggerFactory.make();
@wblakecaldwell
wblakecaldwell / google_io_puzzle.py
Last active August 29, 2015 14:00
Google I/O secret invite code finder
#
# Google I/O 2014 secret invite code finder
#
# Blake Caldwell, 2014
#
# Blog Post: http://blakecaldwell.net/blog/2014/4/23/solving-a-2014-google-io-secret-invite-puzzle.html
#
# Repeatedly hit https://developers.google.com looking two-colored "I/O" on the page,
# with a secret code in comments below it. Using the color codes of the "I" and "O",
# calculate the 6-character Google URL-shortened link code, and print the code out.
@wblakecaldwell
wblakecaldwell / json_sensitive_fields.go
Last active August 29, 2015 14:13
JSON Encoding in Go: Dealing with Sensitive Fields
//
// Golang example: Handling sensitive struct fields when JSON encoding.
//
// Blog Post: http://blakecaldwell.net/blog/2015/1/20/json-encoding-in-go-dealing-with-sensitive-fields.html
//
// Try this in the Go Playground: https://play.golang.org/p/Du5ztx6zjC
//
// Author
// ------
//
@wblakecaldwell
wblakecaldwell / gist:ed43ad11271200403f5e
Last active August 29, 2015 14:14
Stuck network goroutines
**** whoa, interesting
goroutine 23885395 [syscall, 228 minutes, locked to thread]:
net._C2func_getaddrinfo(0x1924010, 0x0, 0xc2087a9278, 0xc2087a91c8, 0x301befcd00000000, 0x0, 0x0)
/usr/src/go/src/net/:26 +0x55
net.cgoLookupIPCNAME(0xc208bd45c0, 0x15, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
/usr/src/go/src/net/cgo_unix.go:96 +0x1c5
net.cgoLookupIP(0xc208bd45c0, 0x15, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc2080da240)
/usr/src/go/src/net/cgo_unix.go:148 +0x65
net.lookupIP(0xc208bd45c0, 0x15, 0x0, 0x0, 0x0, 0x0, 0x0)
/usr/src/go/src/net/lookup_unix.go:64 +0x5f
@wblakecaldwell
wblakecaldwell / cylon.py
Created February 24, 2015 05:16
cylon.py - Pulse an LED bar like a Cylon - Raspberry Pi
#
# Pulse an LED bar like a Cylon
#
# This is my Raspberry Pi "Hello World".
#
import RPi.GPIO as GPIO
import time
@wblakecaldwell
wblakecaldwell / .vimrc
Last active August 29, 2015 14:24 — forked from spheromak/.vimrc
"
" Jesse Nelson <spheromak@gmail.com>
" ab
"-------------------------------------------------------------------------------
"
"
set nocompatible " be iMproved
scriptencoding utf-8
set encoding=utf-8
@wblakecaldwell
wblakecaldwell / README.md
Last active August 29, 2015 14:25 — forked from leehambley/README.md
Simple bash script to wire up Grafana 2.x with InfluxDB 0.8

Simple bash script to wire up Grafana 2.x with InfluxDB 0.8

This Bash script exposes a few functions to create a Grafana data source, and setup the InfluxDB database behind that. It has some configuration functions in the top. It is a continuation of the Python script offered in this Grafana issue comment.

Usage

$ ./grafana-influxdb-wiring.sh name_of_database
@wblakecaldwell
wblakecaldwell / fastbit-deadlock.txt
Created September 28, 2015 18:21
Fastbit deadlocking code path
** This is from a modified fork of Fastbit 1.3.8, so the line numbers will be off by a little.
Description
-----------
Deadlock is caused by `ibis::fileManager::getFile` (#7 below) locking the fileManager's mutex, and then the constructor
at `ibis::fileManager::storage::storage` (#4 below) locking it in the same thread, when it realizes it needs to make
some room in the cache first. There seem to be many similar code paths where this sort of deadlock will arise, all when
the cache size is near or over `maxBytes`.
@wblakecaldwell
wblakecaldwell / wisdom.md
Created January 12, 2022 20:22 — forked from merlinmann/wisdom.md
Merlin's Wisdom Project (Draft)

Merlin's Wisdom Project

Or: “Everybody likes being given a glass of water.”

By Merlin Mann.

It's only advice for you because it had to be advice for me.

(Link to this page)

@wblakecaldwell
wblakecaldwell / SDL2_static.cpp
Created May 4, 2023 05:31
Chat GPT4 writing C++ SDL2 code to fill a screen, giving each pixel a random color, regenerating every 1/24th of a second
#include <SDL2/SDL.h>
#include <stdio.h>
#include <cstdlib>
#include <ctime>
const int WINDOW_WIDTH = 640;
const int WINDOW_HEIGHT = 480;
int main(int argc, char *argv[]) {
srand(static_cast<unsigned>(time(0)));