Skip to content

Instantly share code, notes, and snippets.

View glaucocustodio's full-sized avatar
🇧🇷

Glauco Custódio glaucocustodio

🇧🇷
View GitHub Profile
@glaucocustodio
glaucocustodio / rails-4-2-unnest-query-in-array-columns.rb
Last active August 29, 2015 14:13
Scenario from issue with the use of postgres's unnest query in array columns on rails 4.2
# 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)
@glaucocustodio
glaucocustodio / SwitchToFile.py
Created November 14, 2012 16:00 — forked from jbjornson/SwitchToFile.py
Show a input panel to switch to a currently open file
# -------------------------------------------
# You will need to create a key mapping for this, something like:
# { "keys": ["alt+e"], "command": "switch_to_file" }
# -------------------------------------------
class SwitchToFileCommand(sublime_plugin.WindowCommand):
def run(self):
self.display_list = []
self.views = []
for view in self.window.views():
path = view.file_name()
@glaucocustodio
glaucocustodio / application_helper.rb
Created November 23, 2015 17:21
Rails helper that returns if current time is contained in a time range
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
#!/usr/bin/env python
from setuptools import setup
setup(
name='My Project',
version='1.0',
description='OpenShift App',
author='Glauco Custodio',
author_email='glauco.custodio@gmail.com',
@glaucocustodio
glaucocustodio / doorkeeper.pt-BR.yml
Created July 4, 2013 14:51
pt-BR translations for Doorkeeper gem
# 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.'
@glaucocustodio
glaucocustodio / gist:5929646
Created July 4, 2013 18:59
Doorkepper and CanCan
# 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
@glaucocustodio
glaucocustodio / gist:6039161
Last active December 20, 2015 00:09
Rails 4 and Ruby 2 date format validation
# 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
# 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
@glaucocustodio
glaucocustodio / cnpj_validator.swift
Last active February 4, 2016 17:19
Swift (1.2) function to validate CNPJ
// 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)
@glaucocustodio
glaucocustodio / gist:5985229
Last active March 20, 2016 08:50
Rails 4 , Rails Admin and Rich
# 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.