Skip to content

Instantly share code, notes, and snippets.

@mkaschenko
mkaschenko / difference_in_years.rb
Last active March 1, 2025 06:24
The difference in years between dates
# Year 2017
module Date
# NOTE: There are two scenarios to consider based on the order of input dates:
# 1. Ascending order: Only negative differences in days and/or months affect the year count.
# 2. Descending order: Only positive differences in days and/or months affect the year count.
def self.difference_in_years(left_date, right_date)
diff_in_years = right_date.year - left_date.year
diff_in_months = (right_date.month - left_date.month) / 100.0
diff_in_days = (right_date.day - left_date.day) / 10_000.0
@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])
http://gmapuploader.com/
http://gmapuploader.com/view/wpfzJD4T4P
Каждый масштабный уровень содержит в 4 раза большее количество элементов, чем предыдущий.
http://dl.dropbox.com/u/11808009/%D1%84%D0%BE%D1%82%D0%BE%D0%B3%D1%80%D0%B0%D1%84%D0%B8%D1%8F.JPG
map.setCenter(new YMaps.GeoPoint(0,0),1); задается центр карты на первом уровне масштаба /= Это для яндекса, надо прочекать в leaflet
http://www.xakep.ru/post/47006/default.asp
@mkaschenko
mkaschenko / gist:1317036
Last active September 27, 2015 18:58
sort by two parameters
sort_by { |x| [x.a, x.b] }