This is a generic guidline that applies mostly to Ruby on Rails and Postgres, but can be usefull for running any database migrations in CI.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'resolv' | |
url = 'www.diagnofy.in' | |
begin | |
r = Resolv::DNS.open do |dns| | |
dns.timeouts = 1 | |
dns.getresource(url, Resolv::DNS::Resource::IN::CNAME) | |
end | |
r.name.to_s # => return alias domain | |
rescue Resolv::ResolvError => e |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
sudo apt update | |
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https | |
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg | |
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list | |
sudo apt update | |
sudo apt install caddy | |
caddy version | |
sudo systemctl status caddy | |
sudo systemctl enable caddy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var printPage = (function () { | |
var style = document.createElement('style'); | |
$(".columns").append(style) | |
return function (rule) { | |
style.innerHTML = rule; | |
}; | |
}()); | |
printPage.size = function (marginTop) { | |
printPage('@media print { @page {margin-top: ' + marginTop + 'cm} }'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user nginx; | |
worker_processes 5; | |
error_log /var/log/nginx.error.log; | |
pid /var/run/nginx.pid; | |
events { | |
worker_connections 1024; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# ----------------------------------------------------------------------- | |
# Installs Ruby 2.3 using rbenv/ruby-build on the Raspberry Pi (Raspbian) | |
# | |
# Run from the web: | |
# bash <(curl -s raw_script_url_here) | |
# ----------------------------------------------------------------------- | |
# Set up variables |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SubdomainValidator < ActiveModel::EachValidator | |
# http://matthewhutchinson.net/2010/10/27/rails-3-subdomain-validation-activemodeleachvalidator | |
# http://www.rails-dev.com/custom-validators-in-ruby-on-rails-4 | |
def validate_each(object, attribute, value) | |
return unless value.present? | |
reserved_names = %w(www ftp mail pop smtp admin ssl sftp) | |
reserved_names = options[:reserved] if options[:reserved] | |
if reserved_names.include?(value) | |
object.errors[attribute] << 'cannot be a reserved name' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def flatten_hash(hash, results = {}, parent_key = '') | |
return results unless hash.kind_of?(Hash) | |
hash.keys.each do |key| | |
# current_key = "#{parent_key}[#{key}]" # uncomment this if you want to keep parent key as a partof key for flattened hash (csv column name) | |
current_key = key | |
if hash[key].kind_of?(Hash) | |
results = flatten_hash(hash[key], results, current_key) | |
else | |
if hash[key].kind_of?(Array) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
heroku pg:backups:capture --app sushi | |
curl -o latest.dump `heroku pg:backups public-url --app sushi` | |
curl -o latest.dump `heroku pg:backups:url b001 --app sushi` | |
pg_restore --verbose --clean --no-acl --no-owner -d <app_name>_development latest.dump | |
# Restore data from trial server | |
curl -o latest.dump `heroku pg:backups public-url --app labsmart-trial` | |
be rake db:drop db:create | |
pg_restore --verbose --clean --no-acl --no-owner -d azurite_development latest.dump |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var offset = 4; | |
$(window).scroll(function() { | |
if($(window).scrollTop() + $(window).height() > ($(document).height() - 150)) { | |
loadMore(offset); | |
offset = offset + 4; | |
} | |
}); | |
function loadMore(offset) { |
NewerOlder