Skip to content

Instantly share code, notes, and snippets.

View dstagner's full-sized avatar

Dave Stagner dstagner

View GitHub Profile
Candidate Favorable Unfavorable No Opinion
Sanders 70 22 8
Biden 74 15 11
Warren 60 23 17
Harris 55 12 33
O'Rourke 51 14 35
Buttigieg 42 8 50
Inslee 21 9 70
@dstagner
dstagner / gist:193207fed46acf5b5bae
Last active September 23, 2023 18:19
Ruby ISO8601 time in milliseconds

So you want to generate ISO8601 formatted timestamps in Ruby, but need resolution finer than a second?

First, make sure to require 'time' in order to get ISO8601 formatting. But that gets you this:

2.1.0 :001 > require 'time'
 => true 
2.1.0 :002 > Time.now.utc.iso8601
 => "2015-11-12T04:46:43Z" 
@dstagner
dstagner / gist:838ff6cc98b5f544f785
Last active August 29, 2015 14:23
Getting JNDI property and config values from Glassfish with asadmin

Just leaving this here since it's almost impossible to figure out from the documentation...

You can get the entire list of JNDI resources from a running Glassfish instance using this commmand:

asadmin get resources.*

You can also get configuration using a similar command:

asadmin get configs.*

@dstagner
dstagner / gist:1e0538bf3c4c38e785c0
Last active August 29, 2015 14:08
rails-api and jbuilder not working together?

This drove me nuts! I couldn't get jbuilder to render with a rails-api app. Here's the fix:

# app/controllers/application_controller.rb
class ApplicationController < ActionController::API
  include ActionController::ImplicitRender
end

This turns rendering back on, one of the things disabled by rails-api.

@dstagner
dstagner / gist:8d75dd16d43c35360f5e
Created August 11, 2014 17:44
Octopress/Jekyll pagination not working? Possible solution.

I was trying to rebuild my blog in Octopress, using the beautiful MediumFox theme by Adrian Artiles, but it wasn't loading my old blog entries on the front page correctly. However, the "All posts" link was working. So hmmm.

It was clearly working on Adrian's own blog, so I started digging into his source code to find what was different. My problem was in the pagination variables in _config.yml. The default Octopress configuration has something like paginate_path: "posts/:num". This should be removed and replaced with pagination_dir: posts. Then your pagination will work correctly.

The bug isn't in MediumFox itself, and I don't think it's in Octopress - it's just an interaction. So I'm not sure where to send a pull request. I'll think of something. In the meantime, maybe someone googlebugging the problem will find this gist...

@dstagner
dstagner / vagrant_parse_string_suckage
Created May 1, 2014 03:02
vagrant problem - "in `rescue in parse_string': Caught Encoding::CompatibilityError"
Ran across this little annoyance after upgrading vagrant. There's a whole stack trace after and a line number before that I'm not including because they might be different for you.
Anyway, solution. Delete or rename ~/.vagrant.d and the problem goes away. It's some sort of ASCII vs UTF-8 issue that chokes a regexp.
Nuking from orbit is always an option.
@dstagner
dstagner / multikey_constraints_neo4j
Created January 27, 2014 15:54
Multi-key constraints in Neo4J
Problem: In a data structure, sometimes we want constraints on more than one key. But right now, the Neo4J 2.0 uniqueness constraint really only supports uniqueness on one key.
Example: Parents (the meatspace kind) can have several children. None of their children should have the same name. However, their children may have the same name as children of other parents. So you don't want uniqueness on names for all children, but you want uniqueness on names for children of specific parents. This is two-key uniqueness.
Victor has three children - Mary, Alice, and Quasimodo. And Marissa has three children - Xena, Bob, and Alice. Victor's Alice and Marissa's Alice are two different children, but have the same name.
Solution: Create a unique key on parents (like a uuid, since parents shouldn't be unique on name). Then create a unique key on child that's a combination of parent uuid and child name. Kind of a hack, but it should work.
More later when I actually write an implementation.