Skip to content

Instantly share code, notes, and snippets.

Avatar
🐙

matthew sullivan hayduke19us

🐙
View GitHub Profile
View query_subscriber.rb
# To prevent memory leak possibilities with user errors there are constraints.
#
# * Only allows one subscriber to be active at a time. When
# instantiated it always removes all QuerySubscribers subscribed to the :client.
# * It requires a block of assertions where the instantiated monitor is
# available for access to the #query_count.
# * It is meant for a single instantiated use, and removes the subscriber from
# the client's @monitoring#subscribers Hash after the block executes. It also
# clears the recorded queries from the subscriber.
# This means you can use the QueryMonitor as many times as you like in one off
View priceline_catalog.rb
#!/usr/bin/env ruby
require 'uri'
require 'net/http'
require 'json'
require 'bigdecimal'
require 'securerandom'
# Usage
View ruby_concurrency.rb
require 'byebug'
require 'benchmark/ips'
require 'csv'
RESOURCES = 30
BLOCKING_TIME = 3
class SuperUploader
THREAD_MAX = 10
attr_reader :outgoing, :thread_max, :queue, :results, :threads, :switch
View performance.rb
require 'benchmark/ips'
require 'benchmark/memory'
# For use within a spec. Three methods must be provided within the current
# namespace. #performance_object, #performance_a, and #performance_b.
# The object is the object with the methods to be measured.
# The performance a and b are the methods to be compared.
# The original is #performance_a.
#
# Example use
View property_attributes.rb
class PropertyAttributes
attr_reader :raw_data, :cache
def initialize(cache)
@cache = cache
@raw_data = to_object cache.raw_data
end
def to_object(raw_data)
OpenStruct.new Hash[raw_data.map { |k, v| [k, to_struct_attributes(v)] }]
View properties.js
function setModalElementByClass(class_name, inner_html) {
var element = document.getElementsByClassName(class_name)[0]
if (element) {
element.innerHTML = inner_html;
} else {
console.log('Missing modal element class: ' + class_name)
}
}
View performance.rb
require 'benchmark/ips'
require 'benchmark/memory'
# For use within a spec. Three methods must be provided within the current
# namespace. #performance_object, #performance_a, and #performance_b.
# The object is the object with the methods to be measured.
# The performance a and b are the methods to be compared.
# The original is #performance_a.
#
# Example use
View pie_chart.js
import * as d3 from 'd3';
import css from './pie.css'
var contentSuppliers = require('./reports/suppliers.csv')
var margin = { top: 40, right: 20, bottom: 30, left: 20 };
var width = 600 - margin.left - margin.right;
var height = 360 - margin.top - margin.bottom;
var radius = Math.min(width, height) / 2;
var color = d3.scaleOrdinal(d3.schemeCategory20b);
View map_amenities.rb
class SupplierAmenities
attr_reader :file
attr_accessor :mapped
def initialize(file)
@file = file
end
def to_hash
CSV.new(File.read(file), headers: true).to_a.map(&:to_hash)
View multi_request.rb
require 'httparty'
module MultiRequest
extend ActiveSupport::Concern
def multi_request_queue
@multi_request_queue ||= RequestQueue.new
end
class RequestQueue