Skip to content

Instantly share code, notes, and snippets.

View glaucocustodio's full-sized avatar
🇧🇷

Glauco Custódio glaucocustodio

🇧🇷
View GitHub Profile
@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()
#!/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: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.
@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 / Default.sublime-theme
Created January 5, 2015 16:30
Increase font size and row padding from Sublime Text 3's sidebar
// 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
@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 / excel.pmt.formula.swift
Created May 28, 2015 18:16
Excel PMT Formula in Swift
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 {