Skip to content

Instantly share code, notes, and snippets.

View macedo's full-sized avatar

Rafael Macedo macedo

View GitHub Profile
@macedo
macedo / urlshortener_project_layout
Last active September 30, 2021 16:16
Como projeto urlshortener esta estruturado
➜ urlshortener tree -a .
.
├── .devcontainer
│   ├── Dockerfile
│   ├── devcontainer.json
│   └── docker-compose.yml
└── README.md
1 directory, 4 files
<script>
speechRecognition = new webkitSpeechRecognition();
speechRecognition.continuous = true;
speechRecognition.lang = 'pt-br';
speechRecognition.interimResults = true;
speechRecognition.start();
speechRecognition.onresult = function (event) {
if (typeof (event.results) == 'undefined') {
speechRecognition.stop();
irb(main):010:0> a = KioskConfiguration.with_computer_id('00-50-E4-00-0E-C6').count
(2.6ms) SELECT COUNT(*) FROM "kiosk_configurations" WHERE "kiosk_configurations"."deleted_at" IS NULL AND "kiosk_configurations"."computer_id" = $1 [["computer_id", "00-50-E4-00-0E-C6"]]
=> 0
irb(main):011:0> KioskConfiguration.all.map &:computer_id
KioskConfiguration Load (3.9ms) SELECT "kiosk_configurations".* FROM "kiosk_configurations" WHERE "kiosk_configurations"."deleted_at" IS NULL
=> ["78-31-c1-cf-fd-12", "00-50-E4-00-0E-AC"]
irb(main):044:0> kc = KioskConfiguration.create computer_id: '00-50-E4-00-0E-C6'
(2.1ms) BEGIN
class UsersController < ApplicationController
def create
respond User::Create do |user, format|
format.json { render status: :created, json: user.to_json }
end
end
end
class User < ActiveRecord::Base
@macedo
macedo / ean_validator.rb
Last active August 29, 2015 14:21
ean rails validator
class EANValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
unless ean_valid?(value)
record.errors[attribute] << (options[:message] || :bad_ean)
end
end
def valid?(ean)
return false unless ean.length == 13
@macedo
macedo / request_recorder.rb
Created April 16, 2015 14:06
Request Recorder
module Recorder
module Config
class << self
attr_accessor :records_path
end
end
def self.config
yield Config
end
@macedo
macedo / ajax_queue.js
Created January 29, 2015 18:21
Ajax requests queue
var AjaxQueue = {
batchSize: 1,
urlQueue: [],
elementsQueue: [],
optionsQueue: [],
setBatchSize: function(bSize) {
this.batchSize = bSize;
},
push: function(url, options, elementID) {
this.urlQueue.push(url);
@macedo
macedo / Vagrantfile
Created September 23, 2014 21:01
Vagrant file to setup a debian-wheezy vm configured to run simplestack (https://github.com/locaweb/simplestack)
$script = <<SCRIPT
function log_and_exec {
callback=${1};
shift 1;
echo "[EXEC] $callback $@";
"$callback" "$@";
}
date > /etc/vagrant_provisioned_at
require 'net/https'
require 'uri'
usernames_to_check = %W(macedo _macedo)
available = []
usernames_to_check.each do |username|
uri = URI.parse "https://twitter.com/#{username}"
http = Net::HTTP.new uri.host, uri.port
@macedo
macedo / grid.scss
Last active August 29, 2015 14:03
grid sass
// Grid
$max-width: 768px;
$column-width: 5.5%;
$gutter-width: 3%;
$maximum-columns: 6;
@function columns($columns) {
$width: $columns * $column-width + ($columns - 1) * $gutter-width;
@return percentage($width / $max-width);
}