Skip to content

Instantly share code, notes, and snippets.

View crivotz's full-sized avatar
🏠
Working from home

Mauro Locatelli crivotz

🏠
Working from home
View GitHub Profile
@ahamid
ahamid / ImageUploader
Created May 27, 2011 16:51
CarrierWave mixed content upload processing
require 'carrierwave/processing/mini_magick'
class ImageUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
IMAGE_EXTENSIONS = %w(jpg jpeg gif png)
DOCUMENT_EXTENSIONS = %w(exe pdf doc docm xls)
def store_dir
"files/#{model.id}"
@yellowled
yellowled / ffmpeg-html5
Created December 6, 2011 19:39
Convert videos to proper formats for HTML5 video on Linux shell using ffmpeg. Will probably convert this to a bash script later, but for the time being, here's some examples. Not sure there have actually sensible dimensions and bitrates for web video.
# webm
ffmpeg -i IN -f webm -vcodec libvpx -acodec libvorbis -ab 128000 -crf 22 -s 640x360 OUT.webm
# mp4
ffmpeg -i IN -acodec aac -strict experimental -ac 2 -ab 128k -vcodec libx264 -vpre slow -f mp4 -crf 22 -s 640x360 OUT.mp4
# ogg (if you want to support older Firefox)
ffmpeg2theora IN -o OUT.ogv -x 640 -y 360 --videoquality 5 --audioquality 0 --frontend
@patrickberkeley
patrickberkeley / pages_controller.rb
Created December 7, 2008 02:10
using Paperclip for multiple attachments and displaying them using the method described in Advanced Rails Recipe #13
class PagesController < ApplicationController
before_filter :login_required, :except => [ :show ]
# GET /pages
# GET /pages.xml
def index
@pages = Page.find(:all)
respond_to do |format|
format.html # index.html.erb
@mariozig
mariozig / migrate_repo.sh
Last active December 22, 2022 08:32
Migrate repo from GitLab to GitHub Full blog post @ http://ruby.zigzo.com/2015/03/23/moving-from-gitlab-to-github/
# Assume we are in your home directory
cd ~/
# Clone the repo from GitLab using the `--mirror` option
$ git clone --mirror git@your-gitlab-site.com:mario/my-repo.git
# Change into newly created repo directory
$ cd ~/my-repo.git
# Push to GitHub using the `--mirror` option. The `--no-verify` option skips any hooks.
@yalab
yalab / bootstrap-memo.md
Last active July 20, 2022 20:29
rails5 + webpacker + bootstrap
$ echo 'gem "webpacker"' >> Gemfile
$ bundle install
$ rails webpacker:install
$ yarn add bootstrap@4.0.0-beta jquery popper.js
diff --git a/config/webpack/environment.js b/config/webpack/environment.js
index d16d9af..86bf1a7 100644
@dideler
dideler / upgrade-postgres-9.3-to-9.4.md
Last active June 8, 2020 03:24
Upgrading PostgreSQL from 9.3 to 9.4 when upgrading Ubuntu 14.04 to 14.10

TL;DR

Create a backup:

pg_dumpall > mybackup.sql

Perform the upgrade:

sudo pg_dropcluster 9.4 main --stop
@x1wins
x1wins / application_controller.rb
Last active December 12, 2019 14:53
model user_id onwer check
class ApplicationController < ActionController::Base
def is_owner user_id
unless user_id == current_user.id
render json: nil, status: :forbidden
return
end
end
def is_owner_object data
if data.nil? or data.user_id.nil?
return render status: :not_found
@VimleshS
VimleshS / jenkins-rails-ec2
Created April 11, 2016 07:27
Jenkins setup for Rails on EC2
Based on these:
https://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkins+on+Ubuntu
http://www.intridea.com/blog/2013/5/21/howto-install-setup-jenkins-ci-for-rails-projects
Setup an EC2 instance with Ubuntu (14.04)
Open port 8080
Install Jenkins
wget -q -O - http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add -
# CAVEAT: I have not run this code
require 'rails/generators/erb/scaffold/scaffold_generator'
module Erb
module Generators
class ScaffoldGenerator < Base
protected