Skip to content

Instantly share code, notes, and snippets.

View kdiogenes's full-sized avatar

Kadu Diógenes kdiogenes

View GitHub Profile
@kdiogenes
kdiogenes / gist:2825af0738cef6160f78
Created April 8, 2015 00:59
rails: rendering content
content = ''
@fields_group.each do |fg|
content << @template.content_tag(:div, class: 'fields-group') do
@template.concat(@template.content_tag(:div, class: 'fields-group__header') do
@template.concat @template.content_tag(:h3, fg.label, class: 'fields-group__header-title')
end)
@template.concat(@template.content_tag(:div, class: 'fields-group__body') do
fg.fields.each { |f| @template.concat @template.content_tag(:span, f.name, class: 'fields-group__field') }
end)
end
@kdiogenes
kdiogenes / gist:e9d76080feeb8f5bae9d
Last active August 29, 2015 14:21
Ruby: Exception handling
def save
tour = Tour.find(tour_id)
discourse_user = DiscourseZr.client.user_by_external_id(user_id)
discourse_user = DiscourseZr.sync_sso(User.find(user_id)) if discourse_user.nil?
client = DiscourseZr.client(username: discourse_user['username'])
client.create_post(topic_id: tour.discourse_topic_id, raw: content)
rescue DiscourseApi::Error => e
begin
discourse_errors = JSON.parse(e.message.gsub('=>',':'))['errors']
discourse_errors.each { |error| errors.add(:field, error) }
@kdiogenes
kdiogenes / gist:baf6988c7e73fd04b9ef
Created May 25, 2015 13:42
AUR: Update upwork PKGBUID to 4.0.67.0 (amd64 only)
# Maintainer: Lev Lybin <lev.lybin@gmail.com>
pkgname=upwork
pkgver=4.0.67.0
pkgrel=1
pkgdesc="Team App (ex. oDesk)"
arch=('x86_64')
url="https://www.upwork.com/downloads/new-team-application"
license=('unknown')
depends=('gtk2' 'gcc-libs-multilib' 'nss' 'gconf' 'alsa-lib' 'glu' 'libxtst' 'gtkglext' 'libgcrypt15' 'libudev.so.0')
@kdiogenes
kdiogenes / gist:ebbf7593eb048f123cc7
Last active September 8, 2015 19:13
iugu: customer syncronization
class User < ActiveRecord::Base
after_create :create_iugu_customer
after_update :update_iugu_customer, if: 'name_changed? or email_changed?'
private
def create_iugu_customer
iugu_customer = Iugu::Customer.create({
email: self.email,
name: self.name
@kdiogenes
kdiogenes / gist:2dff4c89b1709ef0ca08
Created December 19, 2015 13:42
Rails: redirect_to in ajax request
POST /machines HTTP/1.1
Host: localhost:3000
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:43.0) Gecko/20100101 Firefox/43.0
Accept: */*;q=0.5, text/javascript, application/javascript, application/ecmascript, application/x-ecmascript
Accept-Language: pt-BR,pt;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
X-CSRF-Token: ZGycdXyHsJMo0jpmmGhQRsTZheMgq0ZIJ2rSPC6Iw8N6+h7triN6zg5h9Kgh7yZXFDCuLtACYY3nBN74xK28FA==
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
X-Requested-With: XMLHttpRequest
Referer: http://localhost:3000/calls/new
@kdiogenes
kdiogenes / br-tzinfo-zone_names.rb
Last active February 23, 2016 11:56
rails: Brazil TZInfo time zone names
br = TZInfo::Country.get('BR')
br.zone_names => [
"America/Noronha", "America/Belem", "America/Fortaleza", "America/Recife",
"America/Araguaina", "America/Maceio", "America/Bahia", "America/Sao_Paulo",
"America/Campo_Grande", "America/Cuiaba", "America/Santarem", "America/Porto_Velho",
"America/Boa_Vista", "America/Manaus", "America/Eirunepe", "America/Rio_Branco"
]
@kdiogenes
kdiogenes / brazilian-time-zones.rb
Last active February 23, 2016 11:50
rails: add brazilian time zones to ActiveSupport::TimeZone
ActiveSupport::TimeZone::MAPPING['Fernando de Noronha'] = 'America/Noronha'
ActiveSupport::TimeZone::MAPPING['Amazônia'] = 'America/Manaus'
ActiveSupport::TimeZone::MAPPING['Acre'] = 'America/Rio_Branco'
ActiveSupport::TimeZone.instance_variable_set('@zones', nil)
ActiveSupport::TimeZone.instance_variable_set('@zones_map', nil)
module ActiveSupport
class TimeZone
def self.br_zones
@br_zones ||= all.find_all { |z| z.name =~ /Brasilia|Noronha|Amazônia|Acre/ }
@kdiogenes
kdiogenes / named.fish
Created February 27, 2016 12:47
fish: functions to switch named forwaders
function named_home
sudo sed -e 's/ \/\/forwarders { 8.8.8.8; 8.8.4.4; };/ forwarders { 8.8.8.8; 8.8.4.4; };/' /etc/named.conf | sed -e 's/ forwarders { corporate_dns_1; corporate_dns_2; };/ \/\/forwarders { corporate_dns_1; corporate_dns_2; };/' > /tmp/named.conf.tmp; sudo mv /tmp/named.conf.tmp /etc/named.conf
sudo systemctl stop named
sudo systemctl start named
end
function named_unioeste
sudo sed -e 's/ forwarders { 8.8.8.8; 8.8.4.4; };/ \/\/forwarders { 8.8.8.8; 8.8.4.4; };/' /etc/named.conf | sudo sed -e 's/ \/\/forwarders { corporate_dns_1; corporate_dns_2; };/ forwarders { corporate_dns_1; corporate_dns_2; };/' > /tmp/named.conf.tmp; sudo mv /tmp/named.conf.tmp /etc/named.conf
sudo systemctl stop named
sudo systemctl start named
@kdiogenes
kdiogenes / configNetwork.sh
Created February 27, 2016 13:32
bash: update named and cntlm configurations
#!/bin/sh
case "$2" in
up|vpn-up)
IP=`/sbin/ifconfig | grep 'inet '| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $2}'`
case $IP in
10.*)
logger "configNetwork.sh - setting configurations for enterprise net"
forwarders=" forwarders { corporate_dns_1; corporate_dns_2; };"
NoProxy="NoProxy localhost, 127.0.0.*, 10.*, 192.168.*, *.mydomain.dev.br, *.myenterprise.br"
;;
@kdiogenes
kdiogenes / direnv.fish
Created March 15, 2016 20:58
fish: direnv plugin using same event as rvm, causing it to execute first
function init --on-event init_direnv
if available direnv
function __direnv_export_eval --on-variable PWD
status --is-command-substitution; and return
eval (direnv export fish)
end
else
echo "📂 Please install 'direnv'!"
end
end