This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Returns true if the given cnpj is valid | |
func checkIfCNPJIsValid(cnpj: String) -> Bool { | |
if(cnpj.isEmpty) { | |
return true | |
} | |
// validates format, allowed ones: 38.041.242/0001-04, 38041242000104 | |
var formatRegex = NSRegularExpression(pattern: "^[0-9\\.\\-\\/]*[0-9]$", options: NSRegularExpressionOptions.CaseInsensitive, error: nil) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def current_time_between start_time, end_time | |
now = Time.now | |
start_time = start_time.split(':') | |
end_time = end_time.split(':') | |
start_time_hour = start_time.first.to_i | |
start_time_min = start_time.last.to_i | |
end_time_hour = end_time.first.to_i | |
end_time_min = end_time.last.to_i |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ExcelFormulas { | |
class func pmt(rate : Double, nper : Double, pv : Double, fv : Double = 0, type : Double = 0) -> Double { | |
return ((-pv * pvif(rate, nper: nper) - fv) / ((1.0 + rate * type) * fvifa(rate, nper: nper))) | |
} | |
class func pow1pm1(x : Double, y : Double) -> Double { | |
return (x <= -1) ? pow((1 + x), y) - 1 : exp(y * log(1.0 + x)) - 1 | |
} | |
class func pow1p(x : Double, y : Double) -> Double { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Activate the gem you are reporting the issue against. | |
# gem 'activerecord', '4.1.9' # test passing | |
gem 'activerecord', '4.2.0' # test failing | |
require 'active_record' | |
require 'minitest/autorun' | |
require 'logger' | |
# Ensure backward compatibility with Minitest 4 | |
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
// for the ST3 users who don't have the Default.sublime-theme file (which is actually the default configuration), | |
// the simplest procedure is: | |
// 1- Navigate to Sublime Text -> Preferences -> Browse Packages | |
// 2- Open the User directory | |
// 3- Create a file named Default.sublime-theme with the following content (modify font.size as required): | |
[ | |
{ | |
"class": "sidebar_label", | |
"color": [0, 0, 0], | |
"font.size": 16 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# my_page.models.py | |
from mezzanine.blog.models import BlogCategory | |
class MyBlogCategory(BlogCategory): | |
color = models.CharField('Hexadecimal color', max_length=6, blank=True, null=True) | |
class Meta: | |
verbose_name = "My Category" | |
verbose_name_plural = "My Categories" | |
# my_page.admin.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Model | |
# Working in Rails 3 with Ruby 1.9.3 - always returning false in Rails 4 with Ruby 2 | |
with_options :if => :condition? do |co| | |
co.validates :date_birth, :format => {:with => /[0-3]{1}[0-9]{1}\/[0-1]{1}[0-9]{1}\/[1-2]{1}[0-9]{3}/, :message => "invalid"} | |
# I also tried below and many others regex | |
#co.validates :date_birth, :format => {:with => /[1-2]{1}[0-9]{3}\-[0-1]{1}[0-9]{1}\-[0-3]{1}[0-9]{1}/, :message => "invalid"} | |
end | |
# Workaround to work in Rails 4 with Ruby 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Following https://github.com/sferik/rails_admin/wiki/Theming-and-customization I have created a custom js to load rich base, in this way I get the assets included on top of page | |
# /assets/javascripts/rails_admin/custom/ui.js | |
//= require rich/base | |
//= require_self | |
# File upload at Rails 4 | |
# How rich still uses 'attr_accessible' and I didnt want use attr_protected gem I had to overrode RichFile class to comment attr_accessible, I just created /models/rich/rich_file.rb with the same content from rich gem and commented out attr_acessible line. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# routes | |
use_doorkeeper do | |
controllers :applications => 'custom_applications', | |
:authorized_applications => 'custom_authorized_applications', | |
:authorizations => 'custom_authorizations' | |
end | |
# application | |
config.to_prepare do | |
# Only Applications list |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: UTF-8 | |
pt-BR: | |
activerecord: | |
errors: | |
models: | |
application: | |
attributes: | |
redirect_uri: | |
fragment_present: 'não pode conter um fragemento.' | |
has_query_parameter: 'não pode conter uma parâmetro de query.' |