Skip to content

Instantly share code, notes, and snippets.

require 'capybara'
require 'capybara/poltergeist'
class Scraper
include Capybara::DSL
attr_accessor :text, :document, :metas, :title, :session, :globals, :globals_script
# settings for poltergeist driver
Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new app,
js_errors: false,
source "https://rubygems.org"
gem "rails", "4.2.5.2"
gem "sqlite3"
require 'active_record'
ActiveRecord::Base.establish_connection(
:adapter => 'sqlite3',
:database => 'benchmark.db'
)
# ActiveRecord::Migration.class_eval do
# create_table :users do |t|
# t.string :email
# t.string :name
@marktci
marktci / reprocess_paperclip_attachments.rake
Created June 27, 2017 20:07 — forked from giannafusaro/reprocess_paperclip_attachments.rake
Rake task to reprocesses all attachments for given class
namespace :paperclip do
desc "Reprocesses all attachments for given class"
# rake paperclip:reprocess[User,800,'where','some_sort_of_scope_or_filter IS true']
task :reprocess, [:class, :batch_size, :where, :clause] => :environment do |t, args|
klass = args[:class].constantize
batch_size = args[:batch_size]&.to_i || 100
records = klass.all
records = klass.send(args[:where], args[:clause]) if args[:where] && args[:clause]
records.find_in_batches(batch_size: batch_size) do |group|
@marktci
marktci / paperclip_reprocess_worker.rb
Created June 27, 2017 20:06 — forked from giannafusaro/paperclip_reprocess_worker.rb
Worker to take a group of records and reprocess all attachments
class PaperclipReprocessWorker
include Sidekiq::Worker
sidekiq_options retry: true
def perform(klass, group)
group.each do |id|
klass.constantize.attachment_definitions.keys.each do |attachment|
begin
klass.constantize.find(id).send(attachment).reprocess!
@marktci
marktci / postgres_queries_and_commands.sql
Created April 27, 2017 04:58 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(query_start, clock_timestamp()), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(query_start, clock_timestamp()), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@marktci
marktci / multiple_ssh_setting.md
Created April 27, 2017 04:53 — forked from jexchan/multiple_ssh_setting.md
Multiple SSH keys for different github accounts

Multiple SSH Keys settings for different github account

create different public key

create different ssh key according the article Mac Set-Up Git

$ ssh-keygen -t rsa -C "your_email@youremail.com"