Skip to content

Instantly share code, notes, and snippets.

View scratchoo's full-sized avatar
🎯
Focusing

scratchoo

🎯
Focusing
View GitHub Profile
@scratchoo
scratchoo / widget.js
Created August 27, 2017 21:24 — forked from lukencode/widget.js
Starter template for creating jsonp embeddable widgets.
(function () {
var scriptName = "embed.js"; //name of this script, used to get reference to own tag
var jQuery; //noconflict reference to jquery
var jqueryPath = "http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js";
var jqueryVersion = "1.8.3";
var scriptTag; //reference to the html script tag
/******** Get reference to self (scriptTag) *********/
var allScripts = document.getElementsByTagName('script');
@scratchoo
scratchoo / ror-provisioning.sh
Last active October 24, 2017 14:37 — forked from arielcr/ror-provisioning.sh
Ruby on Rails Provisioning Script
#!/bin/bash
echo Provisioning Ruby on Rails...
echo =================================
echo - create a deployer user
addgroup admin
adduser deployer --ingroup admin
su deployer
cd
@scratchoo
scratchoo / .htaccess
Created December 15, 2017 18:02
CI: Simple .htaccess using mod_rewrite for CodeIgniter
<IfModule mod_rewrite.c>
RewriteEngine On
# !IMPORTANT! Set your RewriteBase here and don't forget trailing and leading
# slashes.
# If your page resides at
# http://www.example.com/mypage/test1
# then use
# RewriteBase /mypage/test1/
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
@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
@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 / 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 / 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 / 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 / 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 / script.sh
Created July 28, 2019 15:54
Remove Git tracking from a project
rm -rf .git
rm -rf .gitkeep