Skip to content

Instantly share code, notes, and snippets.

@devton
devton / Rakefile
Created June 1, 2018 14:49 — forked from schickling/Rakefile
Activerecord without Rails
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)
Verifying my Blockstack ID is secured with the address 1JDwi1ANgzVi7LvQGg5iuoqyitqmpMXJc4 https://explorer.blockstack.org/address/1JDwi1ANgzVi7LvQGg5iuoqyitqmpMXJc4
@devton
devton / git-aliases.md
Created March 17, 2016 18:52 — forked from mwhite/git-aliases.md
The Ultimate Git Alias Setup

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 August 29, 2015 14:18
ec2 ubuntu ruby 2.2.1 and small fullstack dependencies
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
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
@devton
devton / crawler.rake
Created February 11, 2015 00:27
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 February 10, 2015 23:39
CrawledUrl Model
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
@devton
devton / crawled_url_spec.rb
Created February 10, 2015 23:34
CrawledUrlSpec
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 February 10, 2015 23:10
Crawler::UrlParser
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 February 10, 2015 22:59
Crawler::UrlParser spec
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) {
{