Skip to content

Instantly share code, notes, and snippets.

@mkaschenko
mkaschenko / difference_in_years.rb
Last active May 16, 2022 06:15
The difference in years between dates
# Year 2017
module Date
def self.difference_in_years(left_date, right_date)
# NOTE: xxxx.yyzz (2017.1231)
#
# xxxx stands for years
# yy stands for months
# zz stands for days
#
@cdahlqvist
cdahlqvist / bulk_rejections.md
Last active April 5, 2023 06:27
rally-bulk-rejections-track

Bulk Rejections Test

This Rally track is used to test the relationship between bulk indexing rejections and the following parameters:

  • Number of concurrent clients indexing into Elasticsearch
  • Number of shards actively being indexed into
  • Number of data nodes in the cluster
  • Size of bulk requests

The track contains a number of challenges, each indexing into an index with a set number of shards using a increasing number of concurrent client connections and two different bulk sizes.

module Reverse (..) where
import Html exposing (Html, text)
import String
reverse : List Char -> List Char
reverse str =
case str of
[] ->
@mhuggins
mhuggins / application_controller.rb
Last active July 28, 2017 02:13
Devise authentication via Authentication token header (untested)
class ApplicationController < ActionController::Base
before_filter :authenticate_user_from_token!
private
def authenticate_user_from_token!
authenticate_or_request_with_http_token do |token, options|
user = User.find_by_authentication_token(token)
if user && Devise.secure_compare(user.authentication_token, token)

Figure out a good standard for how to use the HTTP response codes in a 'truly RESTful' (Now called 'Hypermedia API' apparently) way.

Summary

require 'test/unit'
class TestRecursiveReverse < Test::Unit::TestCase
def test_o_make
assert_equal [3, 2, 1], RecursiveReverse.new.o_make([1, 2, 3])
end
def test_f_make
assert_equal [3, 2, 1], RecursiveReverse.new.f_make([1, 2, 3])
@mkaschenko
mkaschenko / gist:1317036
Last active September 27, 2015 18:58
sort by two parameters
sort_by { |x| [x.a, x.b] }