Skip to content

Instantly share code, notes, and snippets.

View regedarek's full-sized avatar
🏠
Working from home

Darek Finster regedarek

🏠
Working from home
View GitHub Profile
#Session Setup
Warden::Manager.serialize_into_session do |user|
puts '[INFO] serialize into session'
user.id
end
Warden::Manager.serialize_from_session do |id|
puts '[INFO] serialize from session'
User.find(id)
end
module M
def method
puts "hello"
end
end
def execute(current_module, &block)
Object.new.tap do |o|
o.extend(current_module)
o.instance_eval &block
# encoding: UTF-8
%w[rubygems digest/md5 sinatra haml sass warden rack/flash mongo mongo_mapper uri].each{ |gem| require gem }
require 'sinatra/reloader'
configure do
MongoMapper.connection = Mongo::Connection.new('staff.mongohq.com', 10083)
MongoMapper.database = 'hkbase'
MongoMapper.database.authenticate('hksklep', '****')
end
# encoding: UTF-8
require 'sinatra'
require 'haml'
require 'sass'
require 'warden'
require 'rack/flash'
require 'sinatra/activerecord'
require 'active_record'
require 'date'
require_relative 'setup_env'
@regedarek
regedarek / gist:1748728
Created February 6, 2012 01:01
Rezerwacja
def book
if params[:date].present? && params[:room].present? && current_user
room = Room.find_by_id(params[:room])
date = DateTime.strptime(params[:date],"%d-%m-%Y-%H-%M")
unless date > Date.today+8.days || date.past?
unless Book.user(current_user.id).room(room.id).period(room.period).first
unless Book.room(room.id).free(date,date+room.duration.minutes).first
stop = (date+room.duration.minutes).strftime("%H:%M") == "00:00" ? "23:59" : (date+room.duration.minutes).strftime("%H:%M")
unless Book.room(room.id).cyclic.dayoftheweek(date.wday).onlytimefree(date.strftime("%H:%M"),stop).first
require 'faraday'
require 'forwardable'
module Soup
class Agent
extend Forwardable
def initialize(domain = 'https://www.soup.io/')
@agent ||= faraday(domain)
end
@regedarek
regedarek / old
Created February 8, 2012 15:38
sti
Ride coordination board: Singe Table Inheritance
Database: ads
:title
:price
:content
:username
:from
:to
" Configure vim to suck less
let softab = "on"
let tabsize = 2
let arrowkeys = "on"
let gui_font = "Monaco\ 11"
let mapleader = ","
let $LANG = 'en'
set langmenu=none
source ~/.vimrc-defaults
source ~/.vimrc-helpers
= simple_form_for @ad, :html=>{:multipart => true } do |f|
=f.input :title
=f.input :price
=f.input :category_id
= render :partial => "categories/bar"
= f.input :name
= f.input :email
= f.input :phone_number
= f.input :ad_content
require 'faraday'
require 'forwardable'
module Soup
class Agent
extend Forwardable
def initialize(domain = 'https://www.soup.io/')
@agent ||= faraday(domain)
end