Skip to content

Instantly share code, notes, and snippets.

View jspooner's full-sized avatar

Jonathan Spooner jspooner

View GitHub Profile
@jspooner
jspooner / time.rb
Created March 31, 2011 15:56
Extend the Ruby Time object with a method that will find the next weekday.
class Time
class << self
def next(day, from = nil)
day = [:sunday,:monday,:tuesday,:wednesday,:thursday,:friday,:saturday].find_index(day) if day.class == Symbol
one_day = 60 * 60 * 24
original_date = from || now
result = original_date
result += one_day until result > original_date && result.wday == day
result
end
@jspooner
jspooner / gist:5282904
Created April 1, 2013 02:24
pod spec error
pod spec lint --local --verbose
> Google-Maps-iOS-SDK
Google-Maps-iOS-SDK (1.1.2) - Analyzing on iOS 5.1 platform.
Analyzing dependencies
Fetching external sources
-> Fetching podspec for `Google-Maps-iOS-SDK` from `/Users/jonathanspooner/Documents/git/Specs/Google-Maps-iOS-SDK/1.1.2`
@jspooner
jspooner / logmon.sh
Created October 28, 2014 19:57
logmonitor
declare -i cnt
last_cnt=0
while true
do
    (( cnt = $(grep met=618 access.log | wc -l) ))
    ((difference = $cnt - $last_cnt))
    (( last_cnt=$cnt ))
    echo $difference
    sleep 60
done
@jspooner
jspooner / refactor_me.rb
Last active May 24, 2021 21:38
This code test helps us measure your knowledge of Ruby on Rails best practices. Please download this pseudo-Ruby on Rails code, refactor it, and email the results to jonathan[at]carrot.com.
# Controller
class People < ActionController::Base
# ... Other REST actions
def create
@person = Person.new(params[:person])
slug = "ABC123#{Time.now.to_i.to_s}1239827#{rand(10000)}"
<button id="btn-0">Button 1!</button>
<button id="btn-1">Button 2!</button>
<button id="btn-2">Button 3!</button>
<script type="text/javascript">
var prizes = ['A Unicorn!', 'A Hug!', 'Fresh Laundry!'];
var btnNum = 0;
for (var x = 0; x < prizes.length; x++) {
// for each of our buttons, when the user clicks it...
document.getElementById('btn-' + btnNum).onclick = function() {
// tell her what she's won!
@jspooner
jspooner / gist:45f203e33099880613acbfc36847f80a
Last active June 4, 2016 21:38
Regular Schedule Generator
require 'active_support'
require 'date'
def format_date d
d.strftime("%D %I:%M %p")
end
week_one_start = DateTime.parse("2016-03-03 4:00 PM")
week_one_end = DateTime.parse("2016-03-06 5:30 PM")
week_two_start = DateTime.parse("2016-03-09 4:00 PM")
@jspooner
jspooner / gist:54cff2a299c4d1a3293f9d4c05c9bb8e
Last active July 18, 2018 17:26
Databricks + es-hadoop + Amazon Elasticsearch Service
import org.elasticsearch.spark._
import org.elasticsearch.spark.rdd.EsSpark
import org.elasticsearch.spark.sql._
// Create a DataFrame to write to ElasticSearch
case class SimpsonCharacter(name: String, actor: String, episodeDebut: String)
val simpsonsDF = sc.parallelize(
SimpsonCharacter("Homer", "Dan Castellaneta", "Good Night") ::
@jspooner
jspooner / gist:aca369e357ac824c5832b347f98c005a
Last active July 1, 2016 20:02
Elastic Search array update
demographics.groovy
if (ctx._source.demographics) {
match_found = false
x = 0
for (d in ctx._source.demographics) {
if (d.source == demographic.source) {
match_found = true
ctx._source.demographics[x] = demographic // will destroy the original object. Any keys could be lost
}
@jspooner
jspooner / elasticsearch.yml
Last active July 4, 2018 18:28
Spark(emr-5.2.0) + Elasticsearch Bulk Loading Optimization on AWS
# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
# Before you set out to tweak and tune the configuration, make sure you
# understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please see the documentation for further information on configuration options:
@jspooner
jspooner / Dockerfile
Created December 8, 2017 21:54
GoLang Docker Example
FROM golang:latest
RUN mkdir /app
ADD . /app/
WORKDIR /app
RUN go build -o main .
CMD ["/app/main"]