Skip to content

Instantly share code, notes, and snippets.

@donilan
donilan / install_docker_ce.sh
Last active May 11, 2020 01:51
Install docker ce on centos7
#!/usr/bin/env bash
sudo yum install -y yum-utils \
device-mapper-persistent-data \
lvm2
sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
sudo yum makecache fast
@SylarRuby
SylarRuby / downloads_controller.rb
Last active August 25, 2022 06:43
Loop through all, zip and download from ActiveStorage
# In our gemfile:
# gem 'rubyzip'
require 'zip'
# private ?
def process_and_create_zip_file
# Simulation of an object with has_many_attached :documents
job = Job.first.documents
# Tmp folder to store the download files from S3
@iscott
iscott / simple_authentication_rails_5_bcrypt_and_has_secure_password.md
Last active March 15, 2024 03:23
Cheat Sheet: Simple Authentication in Rails 5 with has_secure_password

Cheat Sheet: Simple Authentication in Rails 6 with has_secure_password

The goal of this cheatsheet is to make it easy to add hand-rolled authentication to any rails app in a series of layers.

First the simplest/core layers, then optional layers depending on which features/functionality you want.

Specs
AUTHOR Ira Herman
LANGUAGE/STACK Ruby on Rails Version 4, 5, or 6
@bendo01
bendo01 / Caddyfile
Last active November 18, 2017 01:35
Caddy Web Server As Service on Centos 7
#cd /etc/caddy/Caddyfile
example.com {
root /usr/share/nginx/html
gzip
log /var/log/caddy/access.log
#fastcgi / unix:/var/run/php-fpm/php-fpm.sock php # Fast CGI php interpreter
#fastcgi / fastcgi / 127.0.0.1:9000 php # Fast CGI php interpreter
#using with laravel
fastcgi / unix:/var/run/php-fpm/php-fpm.sock php {
index index.php
@fernandoaleman
fernandoaleman / fix-libv8-mac.txt
Created May 5, 2016 15:14
Fixing libv8 and therubyracer on Mac
brew tap homebrew/versions
brew install v8-315
gem install libv8 -v '3.16.14.13' -- --with-system-v8
gem install therubyracer -- --with-v8-dir=/usr/local/opt/v8-315
bundle install
@christofluethi
christofluethi / gist:646ae60d797a46a706a5
Last active April 1, 2024 22:10
Convert m4a to mp3 on OS X command line using ffmpeg
brew update
brew link yasm
brew link x264
brew link lame
brew link xvid
brew install ffmpeg
ffmpeg wiki:
https://trac.ffmpeg.org/wiki/Encode/MP3
@hopsoft
hopsoft / db.rake
Last active April 3, 2024 13:13
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
def clean_for_action_based_url(url)
CGI.unescape(url || "").
gsub(/\/+/, "/").
tr('^a-z_-/', "")
end
def clean_url(url)
url = CGI.unescape(url || "")
url = url.gsub(/\A((https?:)?\/+)*/, "").gsub(/\/+/, "/")
url.split("/").map { |v| CGI.escape(v) }.
@nightire
nightire / Changes in Rails 4_1.md
Last active May 11, 2022 04:50
拥抱 Rails 4 —— 详述 Rails 4 的新变化

Routes

小心地使用 Match(Rails 3 已实现)

Rails 3 提供了 match 方法供我们自定义 routes,然而我们要小心使用它以避免“跨站脚本攻击”(XSS Attack)。比如像这样的 routes:

注:(r3 代表 Rails 3,r4 代表 Rails 4)

# routes.rb
@nightire
nightire / Rails 4 - Active Record Associations.md
Last active March 27, 2016 12:40
Rails 4 - Active Record Associations

Rails 4 - Active Record Associations

has_one

一对一关系:有 A 和 B,A 拥有且仅拥有一个 B

has_one

belongs_to