Skip to content

Instantly share code, notes, and snippets.

Avatar

ton devton

View GitHub Profile
@devton
devton / Rakefile
Created Jun 1, 2018 — forked from schickling/Rakefile
Activerecord without Rails
View Rakefile
require "active_record"
namespace :db do
db_config = YAML::load(File.open('config/database.yml'))
db_config_admin = db_config.merge({'database' => 'postgres', 'schema_search_path' => 'public'})
desc "Create the database"
task :create do
ActiveRecord::Base.establish_connection(db_config_admin)
View gist:5c4b56a28ff503340cbaab37e5b4cd7f
Verifying my Blockstack ID is secured with the address 1JDwi1ANgzVi7LvQGg5iuoqyitqmpMXJc4 https://explorer.blockstack.org/address/1JDwi1ANgzVi7LvQGg5iuoqyitqmpMXJc4
@devton
devton / git-aliases.md
Created Mar 17, 2016 — forked from mwhite/git-aliases.md
The Ultimate Git Alias Setup
View git-aliases.md

The Ultimate Git Alias Setup

If you use git on the command-line, you'll eventually find yourself wanting aliases for your most commonly-used commands. It's incredibly useful to be able to explore your repos with only a few keystrokes that eventually get hardcoded into muscle memory.

Some people don't add aliases because they don't want to have to adjust to not having them on a remote server. Personally, I find that having aliases doesn't mean I that forget the underlying commands, and aliases provide such a massive improvement to my workflow that it would be crazy not to have them.

The simplest way to add an alias for a specific git command is to use a standard bash alias.

# .bashrc
@devton
devton / ubuntu_ec2_ruby_2.2.1_setup.sh
Last active Aug 29, 2015
ec2 ubuntu ruby 2.2.1 and small fullstack dependencies
View ubuntu_ec2_ruby_2.2.1_setup.sh
echo "installing depencies..."
sudo apt-get update
sudo apt-get install git-core curl zlib1g-dev nodejs rbenv ImageMagick libmagickwand-dev build-essential postgresql postgresql-common libpq-dev imagemagick nginx libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev -y
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
source ~/.bashrc
if [ ! -d ~/.rbenv/plugins/ruby-build ]; then git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build; fi
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
rbenv install 2.2.1 -s
View gist:eb179f6cbcf6fa20af49
How to setup Heroku Hostname SSL with GoDaddy SSL Certificate and Zerigo DNS
Heroku recently added an exciting new 'Hostname SSL' option. This option offers the broad compatibility of IP-based SSL, but at 1/5 the price ($20 / month at the time of this writing).
The following tutorial explains how to use Heroku's new 'Hostname SSL' option on your Heroku project. Before we begin, let's list what we're using here:
* Heroku Hostname SSL
* GoDaddy Standard SSL Certificate
* Zerigo DNS
View crawler.rake
namespace :crawler do
desc 'Start the crawler on a URL'
task :start, [:url] => [:environment] do |t, args|
Rails.logger.info "starting crawler on --> #{args[:url]}"
links = Crawler::Web.collect_links_from args[:url]
CrawledUrl.transaction do
links.each do |url|
CrawledUrl.persist_from url
end
end
@devton
devton / crawled_url.rb
Created Feb 10, 2015
CrawledUrl Model
View crawled_url.rb
class CrawledUrl < ActiveRecord::Base
# Persiste uma URL no banco de dados
# caso ela já não tenha sido persistida ou
# não tenha nenhuma expressão negativa
def self.persist_from url
self.find_or_create_by ::Crawler::UrlParser.parse(url) unless NegativeExpression.url_match?(url)
end
end
View crawled_url_spec.rb
require 'rails_helper'
RSpec.describe CrawledUrl, :type => :model do
describe ".persist_from" do
let(:url) { 'http://www.foo.bar.com/foo-bar#lorem?ipsum=dolor' }
let(:attributes) { ::Crawler::UrlParser.parse url }
subject { CrawledUrl.persist_from url }
context "when url already persisted" do
@devton
devton / url_parser.rb
Created Feb 10, 2015
Crawler::UrlParser
View url_parser.rb
module Crawler
class UrlParser
# Instancia a classe e já faz o parser
# retornando um hash com os atributos da URL
def self.parse url
_ = new url
_.parse!
end
def initialize url
@devton
devton / url_parser_spec.rb
Created Feb 10, 2015
Crawler::UrlParser spec
View url_parser_spec.rb
require "rails_helper"
RSpec.describe Crawler::UrlParser, :type => :service do
describe ".parse" do
subject { Crawler::UrlParser.parse url }
context "normal url" do
let(:url) { 'www.my-example.url.com' }
let(:url_attributes) {
{
You can’t perform that action at this time.