traviscj/blog

Posts

May 5, 2017

relational java explorations with sqlite3 vtab

One idea i have been mulling over lately is exposing a java codebase relationally, with queries like:

SELECT *
FROM classes c
JOIN annotations a
  ON a.class_id = c.id
WHERE a.name = 'MyAnnotationClass';

The idea here is that you could search a codebase by pretending that you had tables for a whole bunch of things like:

  • classes
  • annotations
  • variables
  • literals
  • methods

This would be a useful thing because instead of relying on an IDE like IntelliJ to do “find usages” operations, you could actually script those interactions. Admittedly, of course, Java has some pretty sophisticated reflection APIs to find this sort of stuff too, but it seems like exploring the structure could be much easier writing Java code to traverse those trees.

read more
April 19, 2017

toy/life data models

I’ve been experimenting a lot with some kinda “toy” data models based on random things that I wish there was a database to query, but isn’t. For example:

  • What was my average arrival time this week?
  • How much of my equity has vested before a certain date?
  • When was the last time we had spaghetti for dinner?

I’ve been doing this with flat JSON files. This is a bit of an odd choice for me; I actually love schematizing data models in protobuf and MySQL and designing proper indices for the data models I work on during work hours.

read more
April 3, 2017

_useful

I often create a directory/file called _useful/_useful.org/_useful.txt. I have one in my Dropbox, for example, that contains:

  1. My apartment lease
  2. My car/motorcycle insurance details
  3. A textfile with my vehicle plate numbers/VINs/insurance policy numbers.

At work, I have one with

  1. the top visited links for logs/metrics/admin interfaces for the services I work with most
  2. a list of links of “typical” or “exemplar” things
    • links to our internal tool views for typical payments, merchants, etc
    • typical size (in bytes) of various protobuf messages we use a lot, size of 1M messages, #messages in 1MB/GB
  3. common coding idioms, like several variants of @RunWith that we use in various cases in our test code.
  4. useful commands for doing stuff (curl/SQL/plain old shell)

Plain text is great for all the reasons it usually is. But it’s especially useful here (see what I did there?) because the file loads much faster than Google Docs or wiki pages, it’s grep-able, it’s trivial to copy to a new machine, there’s no fuss about futzing with the document to get it to format properly, and soforth.

read more
March 31, 2017

.sqliterc

I came across Better output from sqlite3 command line. His .sqliterc file did not work for me, but the simpler

.mode "column"
.headers on

did work nicely.

I also found out that brew install sqlite3 does not install the sqlite3 binary to $PATH, which stinks.

The sqlite3 environment is still much less pleasant than the mysql cli. A few things on my wishlist:

  • tab completion of tables, fields, keywords, and functions.
  • nicer .schema output – I’ve just gotten really used to reading them in mysql output

It sounds like maybe apsw can be something useful? Or maybe Navicat? (but that’s expensive)

read more
March 29, 2017

sprat: multiplayer solitaire

I took a quick pass at describing the rules of a card game I grew up playing, Sprat:

Each player(or team) has 1 deck of cards. initial setup is 4 cards face up (the “personal piles”), 13 cards (top card face up, others face down) in the “sprat deck”, and the remaining cards in the “flip deck”.

The center of the table is the space for the “ace piles”. A new ace pile can be started by any player with any ace; any player can play the next card of the same suit on any ace pile.

read more
March 27, 2017

idea: transaction ordering in ledger-cli

I love ledger-cli but keeping it in sync with my bank statements drives me crazy. The problem is that the transactions can end up with an essentially arbitrary ordering, and the order they clear (and even the date they clear) is not necessarily under my direct control.

One answer to this is: stop caring about the ordering of your transactions! That’s a decent answer, except that not addressing the ordering issue means that you can only ever have “end-of-day” consistency. This means you need a different report to reconcile the transactions.

read more
February 1, 2017

basic http requests and server handlers in clojure

I’ve been playing around a tiny bit with clojure, and wanted to document the process of doing something pretty basic: make a project that can request my website over HTTPs.

The first step is pretty easy:

brew install leiningen
lein new random-experimentation
cd random-experimentation

and add [clj-http "3.4.1"] to project.clj.

The HTTPS part is a bit trickier. The JDK doesn’t include the Letsencrypt certificates. But I found a simple script install-letsencrypt-in-jdk.sh that can set it up.

read more
January 20, 2017

use the `locale.currency` library function

I had stupidly written a pair of functions like this:

def comma_sep(amount):
    thousands = int(amount/1000)
    remainder = int(amount%1000)
    if thousands > 0:
        return comma_sep(thousands)+","+"%.3d"%(remainder)
    else:
        return str(remainder)
def friendly_from_cents(total_cents):
    pos = total_cents >= 0
    total_cents = abs(total_cents)
    cents = int(total_cents%100)
    dollars = int(total_cents/100)
    friendly = "$"+comma_sep(dollars)+"."+str(cents)
    if pos:
        return friendly
    else:
        return "-" + friendly

This is stupid, because python has builtin support to localize currency:

import locale
locale.setlocale(locale.LC_ALL, 'en_US')
locale.currency(-1800, grouping=True)

I think it’s tempting to fall into these traps, because it always starts simpler: I had some total_cents variable and just wanted to display quick and dirty. The complexity built up gradually, until I had something pretty complicated. Oops.

read more
January 18, 2017

filter vs spec (draft)

Consider a silly data model to store data about cities like

message City {
  optional string city_name = 1;
  optional string state = 2;
  optional int32 population = 3;
  optional int32 year_founded = 4;
  // ... presumably others :-)
}

and some sample data like:

[
  {"city_name": "Portland", "state": "OR", "population": ...},
  {"city_name": "Portland", "state": "ME", "population": ...},
  {"city_name": "Springfield", "state": "FL", "population": ...},
  {"city_name": "Springfield", "state": "IL", "population": ...},
  {"city_name": "Springfield", "state": "CO", "population": ...}
]

There are some useful entities we can define: (DRAFT NB: don’t read too much into the matcher vs filter lingo.)

read more
December 31, 2016

korean beef recipe

Ingredients:

  • 1/4 cup brown sugar, packed
  • 1/4 cup reduced sodium soy sauce
  • 2 tsp sesame oil
  • 1/2 tsp crushed red-pepper flakes
  • 1/4 tsp ground ginger
  • 1 tbsp vegetable oil
  • 3 cloves garlic, minced
  • 1 pound ground beef
  • 2 green onions, thinly sliced.
  • 1/4 tsp sesame seeds

Directions

  1. Mix brown sugar, soy sauce, sesame oil, red pepper flakes, ginger.
  2. Sizzle garlic in the vegetable oil, then add beef and cook until brown.
  3. Stir in soy sauce mixture.
  4. Serve immediately.

Summarized from Korean Beef Bowl on Damn Delicious, itself summarized from Korean Beef and Rice.

read more
  • ««
  • «
  • 4
  • 5
  • 6
  • 7
  • 8
  • »
  • »»
© traviscj/blog 2025