Skip to content

Instantly share code, notes, and snippets.

View cristianbica's full-sized avatar

Cristian Bica cristianbica

View GitHub Profile
# You'll need activerecord-import gem installed in your app
class BackupService
def initialize(path: nil)
@path = path || Rails.root.join('tmp', "backup-#{Time.now.to_i}.sqlite")
end
def backup(*scopes)
with_db do
prepare
{
"modelId": "000004q1vq",
"services": [
{
"actions": [
],
"code": "",
"description": "",
"events": [
require 'bundler/inline'
gemfile(true) do
source 'https://rubygems.org'
gem 'rails'
gem 'sqlite3', platform: 'ruby'
end
require 'active_record'
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do
source "https://rubygems.org"
gem "rails", github: "rails/rails"
@cristianbica
cristianbica / setup_swap.rb
Last active August 29, 2015 13:58
Creates swap file on linux
# Usage:
# curl -s https://gist.githubusercontent.com/cristianbica/10347658/raw/setup_swap.rb | sudo ruby - multiplier [remove_current_swap]
# multiplier - when creating the swap will multiply the current RAM with the multiplier
# remove_current_swap - true to remove current swap in /swapfile (default false)
# Ex: curl -s https://gist.githubusercontent.com/cristianbica/10347658/raw/setup_swap.rb | sudo ruby - 2
# Ex: curl -s https://gist.githubusercontent.com/cristianbica/10347658/raw/setup_swap.rb | sudo ruby - 2 true
if ARGV[1] and ARGV[1]=="true"
puts "Removing swap from swapfile as requested ..."
@cristianbica
cristianbica / install_ffmpeg.sh
Last active August 30, 2021 12:03
Install FFmpeg, x264, aac
#!/bin/bash
dpkg -l x264 fdk-aac libvpx libaacplus ffmpeg 2>/dev/null >/dev/null && echo "Packages are already installed" && exit
#cleanup
cd
sudo rm -rf fdk-aac-0.1.0* ffmpeg* libaacplus-2.0.2* libvpx* x264*
sudo apt-get -y remove ffmpeg fdk-aac libaacplus x264 libav-tools libvpx-dev libx264-dev libvpx
sudo apt-get update
sudo apt-get -y install build-essential checkinstall git libfaac-dev libgpac-dev \
@cristianbica
cristianbica / add_swap.sh
Last active August 29, 2015 13:57
Adds swap to a linux system
# for 1G of swap run
# curl https://gist.githubusercontent.com/cristianbica/9594944/raw/add_swap.sh | bash -v -s 128M 8
# it will build a swapfile of 1G (8 blocks of 128M) and make it swap
BLOCK_SIZE=$1
BLOCKS_COUNT=$2
dd if=/dev/zero of=/swapfile bs=$BLOCK_SIZE count=$BLOCKS_COUNT
sudo chown root:root /swapfile
sudo chmod 0600 /swapfile
mkswap /swapfile
swapon /swapfile