Skip to content

Instantly share code, notes, and snippets.

View freegenie's full-sized avatar

Fabrizio Regini freegenie

View GitHub Profile
@freegenie
freegenie / mongo_backup.rb
Created August 18, 2010 09:04
Backup solution for mongodb which dumps gridfs items on filesystem
#!/usr/bin/env ruby
# This script is a backup tool for mongodb.
#
# The main purpose is to dump files from gridfs to filesystem,
# to take advantage of backup solutions based on tools like
# rsync.
# Developed against mongo 1.6.0
var mapping = {
'last_lp_brand' : 'SEAT'
} ;
window.addEventListener('message', event => {
if(event.data.type === 'hsFormCallback' && event.data.eventName === 'onFormReady') {
console.log(">> Form is ready!");
Object.keys( mapping).forEach(function(key) {
var mapping = {
'last_lp_brand' : 'SEAT'
} ;
window.addEventListener('message', event => {
if(event.data.type === 'hsFormCallback' && event.data.eventName === 'onFormReady') {
console.log(">> Form is ready!");
Object.keys( mapping).forEach(function(key) {
@freegenie
freegenie / gist:4e08e299c0878bc110d3f00d900e2ffb
Created September 29, 2016 09:43
must have server shell setup
## color bash
PS1='\e[33;1m\u@\h: \e[31m\W\e[0m\$ '
## Git lg
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
#Deploy and rollback on Heroku in staging and production
task :deploy_staging => ['deploy:set_staging_app', 'deploy:push', 'deploy:restart', 'deploy:tag']
task :deploy_production => ['deploy:set_production_app', 'deploy:push', 'deploy:restart', 'deploy:tag']
namespace :deploy do
PRODUCTION_APP = 'YOUR_PRODUCTION_APP_NAME_ON_HEROKU'
STAGING_APP = 'YOUR_STAGING_APP_NAME_ON_HEROKU'
task :staging_migrations => [:set_staging_app, :push, :off, :migrate, :restart, :on, :tag]
task :staging_rollback => [:set_staging_app, :off, :push_previous, :restart, :on]
@freegenie
freegenie / migration.rb
Created March 12, 2013 11:25
Rails migration set null to false with no default
class AddPrivacyToSubscription < ActiveRecord::Migration
def change
add_column :subscriptions, :privacy, :boolean, :default => false, :null => false
change_column_default(:subscriptions, :privacy, nil)
end
end
@freegenie
freegenie / remote_git_collab.bash
Created February 19, 2013 11:11
bounch of bash functions to speed up collaborations on git based project hostings (github and bitbucket for now). Source it to your shell environment and enjoy!
function last-commit() {
git log --format=%H -n 1
}
function last-file-change() {
git rev-list --max-parents=1 --max-count=1 --format=oneline HEAD -- $1 | cut -d " " -f 1
}
function annotate-file() {
@freegenie
freegenie / deploy.rb
Created January 23, 2013 17:14
Snipped of code to finally have capistrano run db:schema:load on cold deploys. Paste this in your capistrano recipe.
namespace :deploy do
task :load_schema, :roles => :db, :only => { :primary => true } do
rake = fetch(:rake, "rake")
rails_env = fetch(:rails_env, "production")
migrate_env = fetch(:migrate_env, "")
migrate_target = fetch(:migrate_target, :latest)
directory = case migrate_target.to_sym
when :current then current_path
when :latest then latest_release
@freegenie
freegenie / unicorn.conf.rb
Created December 13, 2012 00:14
Unicorn after_fork block to have Rails write logs to a separare file for each worker.
after_fork do |server, worker|
log_path = Rails.root.join('log',"#{Rails.env}.#{worker.nr}.log")
new_logger = Logger.new(log_path)
new_logger.level = Logger::INFO
Rails.logger.flush
Rails.logger.close
Rails.logger = Rails.application.config.logger = ActiveSupport::TaggedLogging.new(new_logger)
@freegenie
freegenie / gist:3917284
Created October 19, 2012 10:05
hardware specs on linux
#!/bin/bash
startline() {
echo ""
echo ""
echo "---------- $1 -------------------------"
echo ""
}
startline "CPU"