Skip to content

Instantly share code, notes, and snippets.

View graudeejs's full-sized avatar

Aldis Berjoza graudeejs

View GitHub Profile
@graudeejs
graudeejs / passwords_controller.rb
Created November 20, 2012 09:22 — forked from kazpsp/passwords_controller.rb
StrongParameters with Devise
# app/controllers/users/password_controller.rb
class Users::PasswordsController < Devise::PasswordsController
def resource_params
params.require(:user).permit(:email, :password, :password_confirmation)
end
private :resource_params
end
module ActionDispatch
module Session
class CustomFileStore < ActionDispatch::Session::AbstractStore
def get_session(env, session_id)
session_data = {}
session_id ||= generate_sid
File.open(tmp_file(session_id),'r') do |f|
data = f.read
session_data = ::Marshal.load(data) unless data.empty?
end rescue nil
module Excel
module Formulas
def pmt(rate, nper, pv, fv=0, type=0)
((-pv * pvif(rate, nper) - fv ) / ((1.0 + rate * type) * fvifa(rate, nper)))
end
def ipmt(rate, per, nper, pv, fv=0, type=0)
p = pmt(rate, nper, pv, fv, 0);
ip = -(pv * pow1p(rate, per - 1) * rate + p * pow1pm1(rate, per - 1))
(type == 0) ? ip : ip / (1 + rate)
gem 'database_cleaner', group: :test
##
# This is rake task of padrino-framework
# Display lists of all stacked rack middleware for your padrino app.
# distributed under the MIT License(http://tyabe.mit-license.org/)
#
def stacked_middlewares(app, args)
require Padrino.root('config/boot.rb')
app_obj = app.app_obj
instance = app_obj.new!
build = app_obj.build(instance)
{
"name": "my-app",
"version": "0.0.1",
"dependencies": {
"normalize-css": "latest",
"angular": "latest"
}
}
@graudeejs
graudeejs / time_vs_datatime.md
Created October 16, 2015 06:58 — forked from pixeltrix/time_vs_datatime.md
When should you use DateTime and when should you use Time?

When should you use DateTime and when should you use Time?

It's a common misconception that [William Shakespeare][1] and [Miguel de Cervantes][2] died on the same day in history - so much so that UNESCO named April 23 as [World Book Day because of this fact][3]. However because England hadn't yet adopted [Gregorian Calendar Reform][4] (and wouldn't until [1752][5]) their deaths are actually 10 days apart. Since Ruby's Time class implements a [proleptic Gregorian calendar][6] and has no concept of calendar reform then there's no way to express this. This is where DateTime steps in:

>> shakespeare = DateTime.iso8601('1616-04-23', Date::ENGLAND)
=> Tue, 23 Apr 1616 00:00:00 +0000
>> cervantes = DateTime.iso8601('1616-04-23', Date::ITALY)
=> Sat, 23 Apr 1616 00:00:00 +0000
@graudeejs
graudeejs / routes.rake
Created November 8, 2015 12:44 — forked from oivoodoo/routes.rake
rake task for printing grape routes.
namespace :grape do
desc 'Print compiled grape routes'
task :routes => :environment do
API.routes.each do |route|
puts route
end
end
end
@graudeejs
graudeejs / axlsx.example.rb
Created August 25, 2016 10:23 — forked from randym/axlsx.example.rb
axlsx Generating Excel documents with Ruby
require 'axlsx'
Axlsx::Package.new do |p|
p.workbook do |wb|
styles = wb.styles
header = styles.add_style :bg_color => "DD", :sz => 16, :b => true, :alignment => {:horizontal => :center}
tbl_header = styles.add_style :b => true, :alignment => { :horizontal => :center }
ind_header = styles.add_style :bg_color => "FFDFDEDF", :b => true, :alignment => {:indent => 1}
col_header = styles.add_style :bg_color => "FFDFDEDF", :b => true, :alignment => { :horizontal => :center }
label = styles.add_style :alignment => { :indent => 1 }
@graudeejs
graudeejs / gpg-offline-master.md
Created February 7, 2017 19:00 — forked from abeluck/gpg-offline-master.md
GPG Offline Master Key w/ smartcard