Skip to content

Instantly share code, notes, and snippets.

View brasten's full-sized avatar

Brasten Sager brasten

View GitHub Profile
@brasten
brasten / gist:732816
Created December 8, 2010 02:54
Using Ant from Rakefile in JRuby
task :war do
ant.war :destfile => 'pkg/project.war' do |war|
war.fileset :dir => 'public'
war.webinf :dir => '.' do |wi|
wi.include :name => 'config/**/*'
wi.include :name => 'lib/**/*'
wi.include :name => 'app/**/*'
wi.include :name => 'vendor/**/*'
wi.include :name => 'config.ru'
wi.include :name => 'Rakefile'
@brasten
brasten / index.ts
Last active January 14, 2019 18:34
TypeScript - Less-permissive implementation of interface
// TypeScript v 3.2.2
//
// I feel like something along the way here should fail type-checking.
//
// The interface for Repository#saveFeed takes an attribute
// with an optional `feed` property. The implementation requires the
// `feed` property, and thus - I suppose - satisfies the requirement?
type FeedInfo = {
feed: {
@brasten
brasten / README.md
Last active January 28, 2019 16:06
Default method for invoking objects in JavaScript

Proposal: "Callable" objects via Symbol.apply function

Objects w/ default method can be invoked like a function.

Problem

Objects that are well constrained (single responsibility) can tend to end up with a single method, or at least a single method that is important to most consumers. These methods tend to be named by either verbing the class name (eg. UserCreator.create()) or with

@brasten
brasten / README.md
Created December 3, 2020 01:15
ConfigKit

Purpose

I don't like shuffling configuration files around. Often chunks of config are related to a specific entity in a specific environment (like the "production redis service" or some such). ConfigKit resolves a series of URI-like references until a concrete value it located, making it easy to provide sensible defaults for local development while also pointing to environmentally-appropriate configuration in an operationally-appropriate repository (GCP Secret Manager or the like).

// In server.ts for example:
@brasten
brasten / index.ts
Created October 13, 2021 17:14
Destructuring and Typing
class MyClass {
// if destructured renaming wasn't a thing, this is
// what I'd naturally expect. But it's already
// valid JS syntax for renaming, obviously.
constructor({ coreService: CoreService }) {
//...
}
// maybe-ish?
constructor({ coreService as CoreService }) {