Skip to content

Instantly share code, notes, and snippets.

View Zainab692's full-sized avatar

Zainab Zainab692

  • Petaling Jaya, Malaysia
View GitHub Profile
# NAME: authinabox
# VERSION: 1.01 (Dec 27, 2008)
# AUTHOR: Peter Cooper [ http://www.rubyinside.com/ github:peterc twitter:peterc ]
# DESCRIPTION: An "all in one" Sinatra library containing a User model and authentication
# system for both session-based logins OR HTTP Basic auth (for APIs, etc).
# This is an "all in one" system so you will probably need to heavily tailor
# it to your own ideas, but it will work "out of the box" as-is.
# COMPATIBILITY: - Tested on 0.3.2 AND the latest rtomayko Hoboken build! (recommended for the latter though)
# - NEEDS DataMapper!
# - Less work needed if you use initializer library -- http://gist.github.com/40238
@pfeilbr
pfeilbr / classic_sinatra_app.rb
Created March 19, 2010 11:58
ruby sinatra file upload example
require 'rubygems'
require 'sinatra/base'
class MyApp < Sinatra::Base
get '/' do
'myapp2 Hello world!'
end
get '/hello' do
@kevinold
kevinold / trivial_file_upload_service.rb
Created August 8, 2011 15:58
Upload file in Sinatra
require 'rubygems'
require 'sinatra'
require 'fileutils'
# upload with:
# curl -v -F "data=@/path/to/filename" http://localhost:4567/user/filename
# or just go to http://localhost:4567/user/filename with a browser
get '/:name/:filename' do
@runemadsen
runemadsen / app.rb
Created October 17, 2012 13:45
Sinatra File Upload
require 'sinatra'
get "/" do
erb :form
end
post '/save_image' do
@filename = params[:file][:filename]
file = params[:file][:tempfile]
@mayfer
mayfer / actions.rb
Created April 23, 2015 18:34
Sinatra login/logout
# Homepage (Root path)
enable :sessions
helpers do
def current_user
begin
@current_user = User.find(session["user_id"].to_i)
# @current_user = User.find(response.cookies["user_id"].to_i)
rescue
@current_user = nil
@tomdalling
tomdalling / simple_authentication.rb
Created May 23, 2016 12:26
A simple Sinatra app that demonstrates basic authentication
#!/user/bin/env ruby
require 'bundler/inline'
gemfile(true) do
source 'https://rubygems.org'
gem 'sinatra', '~> 1.4'
gem 'bcrypt', '~> 3.1'
end
require 'sinatra/base'