Skip to content

Instantly share code, notes, and snippets.

View alebian's full-sized avatar
🌊

Alejandro Bezdjian alebian

🌊
View GitHub Profile
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
require 'benchmark'
require 'benchmark/ips'
require 'memory_profiler'
N = 50000
PROCS = [
[
"Description 1",
-> { 'Insert code here' }
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 / .rubocop.yml
Last active November 11, 2019 22:50
Rubocop's cop to check if gem has version declared in Gemfile
require:
- ./lib/no_gem_version.rb
module Configurable
def self.with(*attrs)
not_provided = Object.new
config_class = Class.new do
attrs.each do |attr|
define_method attr do |value = not_provided, &block|
if value === not_provided && block.nil?
result = instance_variable_get("@#{attr}")
result.is_a?(Proc) ? instance_eval(&result) : result
class JSHash
def initialize(hash)
@original_hash = hash
@hash = build_recursively(hash)
end
def method_missing(m, *args, &block)
response = @hash.send(:[], m.to_s, *args, &block)
return response if response
response = @hash.send(:[], m.to_sym, *args, &block)