Skip to content

Instantly share code, notes, and snippets.

View tonyta's full-sized avatar

Tony Ta tonyta

View GitHub Profile
@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 / 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

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 / 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>
@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:

{
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 / 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,
}