Skip to content

Instantly share code, notes, and snippets.

Useful commands

last_response
    .body

last_request
    .path
    .url
    .session

.cookies

require "minitest/autorun"
require_relative "../lib/conversor_de_numero_romano.rb"
class TestConversorDeNumeroRomano < MiniTest::Unit::TestCase
def teste_deve_entender_o_simbolo_I
romano = ConversorDeNumeroRomano.new
numero = romano.converte 'I'
assert_equal 1, numero
end
Warden::Manager.serialize_into_session{|user| user.id }
Warden::Manager.serialize_from_session{|id| User.get(id) }
Warden::Manager.before_failure do |env,opts|
# Sinatra is very sensitive to the request method
# since authentication could fail on any type of method, we need
# to set it for the failure app so it is routed to the correct block
env['REQUEST_METHOD'] = "POST"
end
require 'sinatra'
require 'warden'
class YourApp < Sinatra::Application
get "/" do
erb 'index'.to_sym
end
get "/protected_pages" do
@TiagoTi
TiagoTi / 0-song.rb
Last active August 29, 2015 14:15
RestFull Routes and Templeates Slim With DataMapper
class Song
include DataMapper::Resource
property :id, Serial
property :title, String
property :lyrics, Text
property :length, Integer
property :released_on, Date
def released_on=date
super Date.strptime(date, '%m/%d/%Y')
end
@TiagoTi
TiagoTi / v1 file 1 config_initializers_pagseguro.rb
Last active August 29, 2015 14:16
Configuração PagSeguro Ruby
I18n.locale='pt-BR'
PagSeguro.configure do |c|
c.token= 'X89X78XX72034XX7XXXC6X73X146978X'
c.email= 'xxxxxx@xxxxxx.xxx.xx'
end
@TiagoTi
TiagoTi / controller.rb
Created March 18, 2015 15:12
atrr_manual.face
class YourController < ApplicationController
def new
@model = YourModel.new
end
def create
#set from the views
@model = YourModel.new(params[:model])
#set manual
@model.anything= '...'
require 'sinatra'
# Listen on all interfaces in the development environment
set :bind, '0.0.0.0'
get '/' do
"Hello World! Is it " + settings.bind + " you're looking for?"
end
@TiagoTi
TiagoTi / screen cast to gif.ssh
Created February 3, 2017 11:28
How to create animated GIF images of a screencast?
sudo apt-get install imagemagick mplayer gtk-recordmydesktop
#Then use Desktop Recorder to capture a portion of the screen/application to use as the screencast.
mplayer -ao null <video file name> -vo jpeg:outdir=output
#Use ImageMagick to convert the screenshots into an animated gifs.
convert output/* output.gif
#you can optimize the screenshots this way:
convert output.gif -fuzz 10% -layers Optimize optimised.gif
@TiagoTi
TiagoTi / SecurityConfig.java
Created May 30, 2018 16:22
basic atutentication
package br.net.ti2.MarinaAbramovick.config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@Configuration