Skip to content

Instantly share code, notes, and snippets.

View tonyta's full-sized avatar

Tony Ta tonyta

View GitHub Profile
@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
@tonyta
tonyta / index.html
Created June 6, 2014 00:24
Southeast Asia
<!DOCTYPE html>
<meta charset="utf-8">
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="style.css" />
<script type="text/javascript" src="http://d3js.org/d3.v3.min.js"></script>
<script type="text/javascript" src="http://d3js.org/topojson.v1.min.js"></script>
</head>
<body>