This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# REFERENCES | |
# https://github.com/codedance/Retaliation/blob/master/retaliation.py | |
# http://www.rkblog.rk.edu.pl/w/p/controlling-usb-missile-launchers-python/ | |
# http://matthias.vallentin.net/blog/2007/04/writing-a-linux-kernel-driver-for-an-unknown-usb-device/ | |
require 'libusb' | |
class Launcher | |
ID_PRODUCT = 0x0701 | |
ID_VENDOR = 0x0a81 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# source: http://blacklane.github.io/2016/04/23/lessons-learned-from-some-of-the-best-ruby-codebases-part-1/ | |
class Foo < Module | |
def initialize | |
@module = Module.new | |
end | |
def included(descendant) | |
@module.class_eval do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
schema = Compel.integer.min(1900).max(2016) | |
result = schema.validate(2017) | |
puts result.errors | |
# => ["cannot be greater than 2016"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object = { | |
first_name: 'Joaquim', | |
birth_date: '1989-0', | |
address: { | |
line_one: 'Lisboa', | |
post_code: '1100', | |
country_code: 'PT' | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
schema = Compel.array.items( | |
Compel.hash.keys({ | |
a: Compel.string.required, | |
b: Compel.string.format(/^abc$/) | |
}) | |
) | |
object = [ | |
{ a: 'A', b: 'abc' }, | |
{ a: 'B' }, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module UseCases | |
module User | |
module Create | |
class Validate < RestMyCase::Base | |
# all necessary validations to persit | |
context_reader :user, | |
:user_attributes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ActiveRecord::Model | |
default_scope { where(state: 'active') } | |
scope :inactive, -> { where(active: false) } | |
validates_presence_of :first_name, :last_name, :email, :password, :invitation_token | |
validates :first_name, length: { minimum: 2 } | |
validates :last_name, length: { minimum: 2 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'grape' | |
module Blog | |
class Web < Grape::API | |
... | |
desc "Create post comment" | |
params do | |
requires :id, type: Integer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'internal_task/version' | |
module InternalTask | |
extend Rake::DSL | |
namespace :internal_task do | |
desc 'Say hello' | |
task :hello do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# input = [ | |
# {:alarma=>{:foo2=>"bar2"}}, | |
# {:alarma=>{:foo=>"bar"}}, | |
# {:alarma=>{:test2=>{:foo=>"bar"}}}, | |
# {:cenas=>"teste"}, | |
# {:alarma=>{:foo2=>"bar2", :foo=>"bar"}} | |
# ] | |
input = [ | |
{:foo=>{:foo=>{:bar=>"stuff"}}}, |
NewerOlder