Skip to content

Instantly share code, notes, and snippets.

View pmashchak's full-sized avatar

Pavlo Mashchak pmashchak

  • Atkins & Pearce
  • Orlando, FL
View GitHub Profile
@pmashchak
pmashchak / occure.rb
Created April 2, 2014 18:42
Find occurences in string
a = 'Baloon . || woo,,ooddreeeed'
occurences = Hash.new(0)
array = a.gsub(/\W+/, '').split('')
array.each_with_index do |el, idx|
break if array.size == idx + 1
if el == array[idx + 1] && el != array[idx - 1]
occurences[el] += 1
end
end
# reverse decimal int number
# without converting to string
def reverse_decimal num
while num > 0 do
# condition
last = num % 10
# algorithm body
res ||= 0
res = (res *= 10) + last
module Client
TABLE = 'TestDevelopment1'
def client
Aws::DynamoDB::Client.new(region: 'No',
credentials: Rails.configuration.api.pulsar.creds,
endpoint: Rails.configuration.api.pulsar.east,
ssl_verify_peer: false)
end
@pmashchak
pmashchak / faraday_benchmark.rb
Last active December 18, 2015 20:19
Faraday_Manticore_Test
class TestController < ApplicationController
skip_before_action :verify_authenticity_token
def index
json = { first_name: 'Jonh', last_name: 'Smith', address: '10 Greenwood Ave, Garden, MI, 15006', age: '25', status: 'married' }
render json: json, status: :ok
end
end
if __FILE__ == $0
class A
attr_accessor :options
cattr_accessor :name
def initialize
self.options = { code: 200, controller: OpenStruct.new(log_state: true) }
self.class.name = :api_name
end
end
# Place this file in /shingle directory name it shingle.rb
# run `gem install sinatra`
# run `ruby shingle/shingle.rb`
# open browser on http://localhost:4567
require 'rubygems'
require 'sinatra'
set :port, '4567'
set :static, true
require 'benchmark'
def get_benchmark
c = Aws::DynamoDB::Client.new(region: 'No', credentials: Rails.configuration.api.pulsar.creds, endpoint: Rails.configuration.api.pulsar.base, ssl_verify_peer: false)
ips = ["2001:0558:4030:0002", "2001:0558:6000:0002", "2601:0A40:0100:00A8", "67.164.233.81", "69.247.98.137",
"69.247.99.167", "69.247.99.168", "69.247.99.9", "76.26.116.108", "76.26.116.116"]
ids = ["1416782538086630295-2001:0558:4030:0002", "1416782538086630295-2001:0558:6000:0002",
"1416782538086630295-2601:0A40:0100:00A8", "1416782538086630295-67.164.233.81", "1416782538086630295-69.247.98.137",
"1416782538086630295-69.247.99.167", "1416782538086630295-69.247.99.168", "1416782538086630295-69.247.99.9",
"1416782538086630295-76.26.116.108", "1416782538086630295-76.26.116.116"]
bm = Benchmark.bm(7) do |x|
@pmashchak
pmashchak / http_request_pulsar.rb
Last active July 13, 2016 05:00
HTTP request wrapper with retry logic and Manticore client integration + DynamoDB data class
# HTTPRequest class is an http client for API calls services
# see usages bellow
class HTTPRequest
attr_accessor :client, :options, :exceptions, :api_context, :async
module ::Manticore
class ResponseCodeException < ManticoreException; end
end
@pmashchak
pmashchak / http_request_spec.rb
Last active May 4, 2016 00:13
HTTP request wapper test + DynamoDB data class
require 'rails_helper'
describe HTTPRequest do
let(:logger) { ->(params) { } }
let(:api_context) { ParentalControls.new('', '', logger: logger) }
let(:subject) { HTTPRequest.new(api_context: api_context, headers: { 'Accept' => 'application/xml' }) }
let(:response) { double(:response, code: 200, body: {}.to_json) }
before do
allow_any_instance_of(ParentalControls).to receive(:get).and_return({})
# bash/zsh completion support for core Git.
#
# Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
# Distributed under the GNU General Public License, version 2.0.
#
# The contained completion routines provide support for completing:
#
# *) local and remote branch names
# *) local and remote tag names