Skip to content

Instantly share code, notes, and snippets.

View tonyta's full-sized avatar

Tony Ta tonyta

View GitHub Profile
@tonyta
tonyta / moral_constitution.md
Last active December 11, 2025 20:35
Moral Constitution

A Framework for Moral and Political Reasoning


Preamble

This document articulates foundational principles derived through reflection, testing, and revision over time. It is not a creed to be accepted on faith but a framework that earns its legitimacy through coherence, explanatory power, and alignment with observed outcomes.

The underlying method is a form of reflective equilibrium — moving between intuitions, principles, and outcomes until they cohere — combined with indirect consequentialism, which holds that outcomes matter but are best served by following well-grounded principles rather than case-by-case calculation. Principles here are not axioms but empirical generalizations: patterns robust enough across history and cases that they function as strong defaults, revisable only with overwhelming evidence.

@tonyta
tonyta / csv_filter.rb
Created June 24, 2024 20:52
CSV Filter
#!/usr/bin/env ruby
require "csv"
require "pathname"
require "fileutils"
class CSVFilter
CSV_WRITE_OPTIONS = {
write_headers: true,
force_quotes: true,
}
PS1='\n$(exit_status)'
PS1=$PS1' \[\033[4;34m\]\u\[\033[m\]' # username
PS1=$PS1' \[\033[32m\]\w\[\033[m\]' # directory
PS1=$PS1' $(ruby_version)'
# PS1=$PS1' $(python_version)'
PS1=$PS1' $(lifemeter)'
PS1=$PS1' $(git_branch) $(git_status)'
PS1=$PS1'\n \[\033[1;35m\]»\[\033[m\] ' # prompt
@tonyta
tonyta / cursor.md
Last active August 29, 2015 14:11
Cursor Pagination

Cursor Pagination

It's my understanding that with cursor pagination, there are two types of cursor pagination that differ depending on what the cursor represents:

  1. cursor represents a single point in the dataset
  2. cursor represents a contiguous batch of the dataset

Cursor as Single Point

In this type, the cursor points to a specific point (maybe a record) in a dataset. This is the type used by Facebook and the response looks like this:

{
@tonyta
tonyta / index.html
Created December 8, 2014 17:27
Countdown
<!DOCTYPE html>
<html>
<head>
<title>Countdown</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<div id="input-area"></div>
<h1 id="time">0:00.0</h1>
<script type="text/javascript" src="script.js"></script>

Keyword Args and Hash-types

TLDR: keyword arguments only with with symbol-keyed hashes but DON'T symbolize keys on params unless you know what you're doing.

Ruby's keyword arguments only work with Hash objects where all of the keys are symbols.

They do not with:

  • ActionController::Parameters
  • ActiveSupport::HashWithIndifferentAccess
@tonyta
tonyta / solr_play2.rb
Created August 19, 2014 21:31
solr_play
module JobSearcher
class << self
def search(state: 'any_state', **params)
searcher_class = "JobSearcher::#{ state.camelize }".safe_constantize
if searcher_classes.include?(searcher_class)
searcher_class.new(params)
else
nil
@tonyta
tonyta / solr_job_searcher_spike.md
Last active August 29, 2015 14:05
Sunspot-Solr Job Searcher Spike

Sunspot-Solr Job Searcher Spike

So here is what I've come up with for the JobSearcher.

Brian suggested that breaking this out into another controller which is what I started doing. I haven't looked too much into what the convention here is, so this is just a spike.

I applied what I learned from looking at the Sunspot source to make the searcher.

The main property that we seem to organize Jobs into is by state. From there, an aspect can be called, returning a Sunspot object. I'm aware that some of this will become the responsibility of Tasks, but what I learned from looking at the Sunspot source can be applied to that as well.

@tonyta
tonyta / sunspot_sandbox.md
Last active August 29, 2015 14:05
Sunspot Sandbox

Sunspot Sandbox

This summarizes the things I learned about Sunspot searching while looking throught the source. I included links to specific parts of the source-code. Be sure to check that out if you are curious.

Setting up an Example Object

This Job model will be what the examples below are searching.

class Job < ActiveRecord::Base
  searchable do
    boolean :requires_expertise
    integer :state
 time :deadline_at
@tonyta
tonyta / _README.md
Last active November 10, 2019 13:09
Custom Prompt

My Custom Bash Prompt

terminal

I like that this adds a little color to and otherwise dull looking terminal window. From left to right, I'll describe what it includes:

  • a fun little alien
  • username
  • current directory
  • Ruby version (via rbenv... you'll have to change this if you use rvm)
  • Hearts that deplete throughout the day