Skip to content

Instantly share code, notes, and snippets.

View alebian's full-sized avatar
🌊

Alejandro Bezdjian alebian

🌊
View GitHub Profile
require 'benchmark'
require 'benchmark/ips'
require 'memory_profiler'
N = 50000
PROCS = [
[
"Description 1",
-> { 'Insert code here' }
class DatabaseRowStream
include Enumerable
BATCH_SIZE = 20_000
def initialize(sql, options = {})
@sql = sql
if options[:pluck]
@pluck = options[:pluck].respond_to?(:join) ? options[:pluck].join(', ') : options[:pluck]
end
class Retryer
def initialize
@retry_times = 3
@block = Proc.new {}
@args = nil
@backoff = false
end
def block(&block)
@block = block
require 'rspec/expectations'
RSpec::Matchers.define :match_stream do |expected_stream|
match do |actual_stream|
loop do
actual_element = actual_stream.next rescue :eof
expected_element = expected_stream.next rescue :eof
return false unless actual_element == expected_element
return true if actual_element == :eof
end
class BasicStruct
ATTRIBUTES = %i[]
def initialize(options = {})
attributes = options.with_indifferent_access
self.class::ATTRIBUTES.each do |attribute|
instance_variable_set("@#{attribute}", attributes[attribute])
class_eval { attr_reader attribute }
end
end
class Gracefully
class << self
alias_method :handle, :new
end
attr_reader :error, :value
def initialize
@value = nil
@error = nil
module Test
class Base
def hello
puts 'Hello'
end
end
Application = Base.new
module Delegator
require 'jwt'
module Token
class Builder
VALID_ALGORITHMS = ['HS256', 'RS256'].freeze
attr_reader :token
def initialize
@payload = {}
@alebian
alebian / MonoBehaviourSingleton.cs
Created October 6, 2017 18:29
Unity useful scripts
#define SAMPLE_OUTSIDE_EDITOR
using UnityEngine;
using UnityEngine.Profiling;
public class MonoBehaviourSingleton<T> : MonoBehaviour where T : MonoBehaviourSingleton<T>
{
static MonoBehaviourSingleton<T> instance;
// Used to select the behavior of the singleton when it's destroyed, if it's "true" then
@alebian
alebian / interactor_mixin.rb
Last active September 26, 2017 18:09
Mixin for Interactor objects. Dependencies: interactor, dry-types
require 'interactor'
require 'dry-types'
# Author:: Alejandro Bezdjian
# Copyright:: Copyright (c) 2017 Alejandro Bezdjian
# License:: Apache 2.0
class InteractorMixin
include Interactor