Skip to content

Instantly share code, notes, and snippets.

View scratchoo's full-sized avatar
🎯
Focusing

scratchoo

🎯
Focusing
View GitHub Profile
@scratchoo
scratchoo / bucket_sync_service.rb
Created December 6, 2020 17:54 — forked from edwardsharp/bucket_sync_service.rb
ruby class to copy from one aws s3 bucket to another based on bantic/bucket_sync_service.rb
require 'aws-sdk'
class BucketSyncService
attr_reader :from_bucket, :to_bucket, :logger
attr_accessor :debug
DEFAULT_ACL = "public-read"
def initialize(from_bucket, to_bucket)
@scratchoo
scratchoo / sanitize.rb
Created November 30, 2020 11:29 — forked from AleksandrKudashkin/sanitize.rb
Loofah custom scrubber for youtube and vimeo iframes
class CustomScrubber < Loofah::Scrubber
ALLOWED_IFRAME_ATTRS = %w[allowfullscreen frameborder height src width].freeze
ALLOWED_VIDEO_REGEX = %r{\A(?:https?:)?//(?:www\.)?youtube|vimeo(?:-nocookie)?\.com/}
def scrub(node)
if node.name == 'iframe' && node['src'] =~ ALLOWED_VIDEO_REGEX
node.attribute_nodes.each { |a| a.remove unless ALLOWED_IFRAME_ATTRS.include?(a.name) }
return CONTINUE
end
return CONTINUE if html5lib_sanitize(node) == CONTINUE
@scratchoo
scratchoo / deploy.rb
Created October 28, 2020 14:42 — forked from andruby/deploy.rb
Start and Stop tasks for resque workers, with capistrano deploy hook (without God)
after "deploy:symlink", "deploy:restart_workers"
##
# Rake helper task.
# http://pastie.org/255489
# http://geminstallthat.wordpress.com/2008/01/27/rake-tasks-through-capistrano/
# http://ananelson.com/said/on/2007/12/30/remote-rake-tasks-with-capistrano/
def run_remote_rake(rake_cmd)
rake_args = ENV['RAKE_ARGS'].to_s.split(',')
cmd = "cd #{fetch(:latest_release)} && #{fetch(:rake, "rake")} RAILS_ENV=#{fetch(:rails_env, "production")} #{rake_cmd}"
@scratchoo
scratchoo / script.sh
Created July 28, 2019 15:54
Remove Git tracking from a project
rm -rf .git
rm -rf .gitkeep
@scratchoo
scratchoo / precompile.md
Last active August 17, 2019 11:18 — forked from mrbongiolo/precompile.md
HOW TO: add xampp launch icon to ubuntu 18
  1. Go to terminal and create the icon file :
gedit ~/.local/share/applications/xampp-control-panel.desktop
  1. Add the following to it :
[Desktop Entry]
@scratchoo
scratchoo / gist:e88f8c5ab5f55c941b416cfefb13356f
Last active October 22, 2018 17:22 — forked from pitch-gist/gist:2999707
HTML: Simple Maintenance Page
<!doctype html>
<title>Site Maintenance</title>
<style>
body { text-align: center; padding: 20px; }
@media (min-width: 768px){
body{ padding-top: 150px; }
}
h1 { font-size: 50px; }
body { font: 20px Helvetica, sans-serif; color: #333; }
article { display: block; text-align: left; max-width: 650px; margin: 0 auto; }
@scratchoo
scratchoo / db.rake
Created September 30, 2018 13:44 — forked from hopsoft/db.rake
Rails rake tasks for dump & restore of PostgreSQL databases
# lib/tasks/db.rake
namespace :db do
desc "Dumps the database to db/APP_NAME.dump"
task :dump => :environment do
cmd = nil
with_config do |app, host, db, user|
cmd = "pg_dump --host #{host} --username #{user} --verbose --clean --no-owner --no-acl --format=c #{db} > #{Rails.root}/db/#{app}.dump"
end
puts cmd
@scratchoo
scratchoo / database_semaphore.rb
Created September 14, 2018 14:41 — forked from rtekie/database_semaphore.rb
Database semaphore mechanism used for example to guarantee that only one instance of a job will run
# Please refer to http://ctoinsights.wordpress.com/2011/10/17/running-distributed-cron-jobs-in-the-cloud/
class DatabaseSemaphore < ActiveRecord::Base
validates_presence_of :name, :message => "can't be blank"
def self.open?(name, lock_duration = 600)
# only one requestor can get open semaphore at a time
# sempahore can be locked in a closed position for lock_duration in seconds
semaphore_open = false
now = Time.now
# insert record if it does not exist yet
@scratchoo
scratchoo / Upgrading rails 5.0 to 5.1
Created February 28, 2018 19:18 — forked from kirankarki/Upgrading rails 5.0 to 5.1
Notes on upgrading rails 5.0 to 5.1
1. Change rails version in Gemfile
> gem 'rails', '~> 5.1', '>= 5.1.4'
2. Remove Gemfile.lock
> git rm Gemfile.lock
3. Run bundle install command
> bundle install --jobs=5
4. Run rails' app update to apply changes to app
@scratchoo
scratchoo / gist:dfa29fee0a3e6ab967081e318adde521
Created December 29, 2017 02:57 — forked from esbanarango/gist:6629748
HTML <input> required attribute and Rails form with remote true.

<input> with attribute required

This attribute specifies that the user must fill in a value before submitting a form. It cannot be used when the type attribute is hidden, image, or a button type (submit, reset, or button). The :optional and :required CSS pseudo-classes will be applied to the field as appropriate.

How to show a spinner only when the required validations pass? (Without using any validation plugin, only the required attribute).

Form with a required input

= form_for @person, remote: true do |f|
 = f.text_field, :first_name, required: true