Skip to content

Instantly share code, notes, and snippets.

View frankyston's full-sized avatar
🎯
Ruby on Rails is Fun

Frankyston Lins frankyston

🎯
Ruby on Rails is Fun
View GitHub Profile
@frankyston
frankyston / create-ruby-gem.md
Created November 27, 2016 23:22 — forked from kelvinst/create-ruby-gem.md
Como criar uma gem ruby?

Como criar uma gem ruby?

Escolhi tratar sobre esse assunto hoje simplesmente porque foi uma das primeiras coisas que me perguntei "como eu faço isso?" no mundo ruby. Acredito que muita gente se pergunte a mesma coisa e espero que eu possa ajudar em algo para elas. 😀

O que é uma gem?

Bem, se você é um programador java, você chama sua gem de jar, se você é um programador C#, você chama de dll. Resumindo, é uma lib, uma biblioteca contendo códigos que você pode reaproveitar importando em outros projetos.

E usar gems no ruby é muito fácil, se você já deu uma brincada com rails por exemplo, é só você adicionar o código gem 'nome_da_gem' no arquivo Gemfile que está no root, depois executar o comando bundle install para baixar sua gem do repositório e pronto, só sair usando a biblioteca!

@frankyston
frankyston / page_scrapper.rb
Created December 26, 2016 18:07 — forked from joaomdmoura/page_scrapper.rb
Pure Old Ruby Object (PORO) HTML scraper with a simple DSL
require 'nokogiri'
require 'open-uri'
class PageScrapper
attr_accessor :url, :selector
IMG_SRC_REGEX = /src="([a-zA-Z\/0-9:.-_]+\.[a-zA-Z]{3})/
URL_REGEX = /http[s]?:\/\/[a-zA-Z0-9].+\.[a-z]{2,3}(\.[a-z]{2})?/
def initialize(url)
@frankyston
frankyston / gist:24819d586dc1d342705e25ccd6145897
Last active February 26, 2017 19:07 — forked from nternetinspired/gist:7482445
Load Disqus comments only on demand if you give a shit about page weight and your visitors.Even with no comments, i.e. an empty comment form, calling Disqus will load an extra 226Kb. If your page has comments this can be far higher.This Gist accompanies my blog post: http://internet-inspired.com/wrote/load-disqus-on-demand/
// Requires jQuery of course.
$(document).ready(function() {
$('.show-comments').on('click', function(){
var disqus_shortname = 'YOUR-DISQUS-USERNAME'; // Replace this value with *your* username.
// ajax request to load the disqus javascript
$.ajax({
type: "GET",
url: "//" + disqus_shortname + ".disqus.com/embed.js",
dataType: "script",
@frankyston
frankyston / subdomain-localhost-rails-5.md
Created February 27, 2017 22:49 — forked from indiesquidge/subdomain-localhost-rails-5.md
how to access subdomains locally with Rails 5

Subdomaining Localhost with Rails 5

I've been following this blog post on how to set up an api-only Rails 5 application. One of the sections talks about creating a subdomain for your api

Rails.application.routes.draw do
  constraints subdomain: "api" do
    scope module: "api" do
@frankyston
frankyston / 1_ubuntu_terminal_command
Created March 13, 2017 20:32 — forked from lucasdavila/1_ubuntu_terminal_command
Installing Source Code Pro fonts in ubuntu
# to execute this gist, run the line bellow in terminal
\curl -L https://raw.github.com/gist/3875946/install_source_code_pro.sh | sh
@frankyston
frankyston / subdomains.rb
Created March 24, 2017 12:25 — forked from turadg/subdomains.rb
Drop-in utility to test your app subdomains with Capybara, Rspec, and a Javascript driver (Poltergeist, Webkit, or Selenium)
# Support for Rspec / Capybara subdomain integration testing
# Make sure this file is required by spec_helper.rb
# (e.g. save as spec/support/subdomains.rb)
def switch_to_subdomain(subdomain)
# lvh.me always resolves to 127.0.0.1
hostname = subdomain ? "#{subdomain}.lvh.me" : "lvh.me"
Capybara.app_host = "http://#{hostname}"
end
@frankyston
frankyston / inflections.rb
Created April 9, 2017 19:44 — forked from mateusg/inflections.rb
pt-BR inflections file for Ruby on Rails applications
# encoding: utf-8
# Be sure to restart your server when you modify this file.
# Add new inflection rules using the following format
# (all these examples are active by default):
# ActiveSupport::Inflector.inflections do |inflect|
# inflect.plural /^(ox)$/i, '\1en'
# inflect.singular /^(ox)en/i, '\1'
# inflect.irregular 'person', 'people'
# inflect.uncountable %w( fish sheep )
sudo apt-get install virtualenv python-pip libpq-dev python-dev
cd
virtualenv pgadmin4
cd pgadmin4
source bin/activate
wget https://ftp.postgresql.org/pub/pgadmin3/pgadmin4/v1.3/pip/pgadmin4-1.3-py2.py3-none-any.whl
pip install pgadmin4-1.3-py2.py3-none-any.whl
@frankyston
frankyston / install-docker.sh
Created July 31, 2017 18:47 — forked from bisubus/install-docker.sh
Installation script for docker and docker-compose, Debian and Ubuntu
#!/bin/sh
confirm () {
read -r -p "${1:-Are you sure? [y/N]} " response
case $response in
[yY][eE][sS]|[yY])
# true
echo 1;
;;
*)
@frankyston
frankyston / postgres_app_and_gem_install.md
Created August 20, 2017 11:31 — forked from jonahoffline/postgres_app_and_gem_install.md
How to install the pg gem with Postgres.app

Install PG gem with Postgres.app

gem install pg -v '0.18.4' -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.5/bin/pg_config