Skip to content

Instantly share code, notes, and snippets.

View ciaoben's full-sized avatar
💭
I will be slow to respond.

Nicolò Benigni ciaoben

💭
I will be slow to respond.
  • qboxmail.com
  • Italia
View GitHub Profile
@zetter
zetter / Slow queries
Created February 8, 2011 09:23
Find the slowest queries lines in a rails development log
file=''
slow = []
File.readlines(file).each do |line|
if line =~ /Load\ \(([\d\.]*)ms\)/
time = $1.to_f
if time >= 500.0
slow << [time, line]
end
end
@kinopyo
kinopyo / custom_logger.rb
Created October 11, 2011 15:40
Custom logger file in Rails
# lib/custom_logger.rb
class CustomLogger < Logger
def format_message(severity, timestamp, progname, msg)
"#{timestamp.to_formatted_s(:db)} #{severity} #{msg}\n"
end
end
logfile = File.open("#{Rails.root}/log/custom.log", 'a') # create log file
logfile.sync = true # automatically flushes data to file
CUSTOM_LOGGER = CustomLogger.new(logfile) # constant accessible anywhere
@bendavis78
bendavis78 / db_backup.sh
Last active June 6, 2024 19:40
A simple database backup / rotation / prune script
#!/bin/bash
# for use with cron, eg:
# 0 3 * * * postgres /var/db/db_backup.sh foo_db
if [[ -z "$1" ]]; then
echo "Usage: $0 <db_name> [pg_dump args]"
exit 1
fi
@sunny
sunny / git-checkout.rake
Last active August 19, 2022 10:04 — forked from skyriverbend/rails_switch_branch.py
Task to checkout a branch in rails and apply or rollback the migrations between the two.
# encoding: UTF-8
#
# $ rake checkout new_branch_name
#
# Via https://gist.github.com/jonlemmon/4076864
#
# 1. Roll back any migrations on your current branch which do not exist on the
# other branch
# 2. Discard any changes to the db/schema.rb file
# 3. Check out the other branch
@johnkferguson
johnkferguson / rails_log_rotation.md
Created January 12, 2014 19:48
How to configure Rails to rotate your log files

To configure Rails to rotate your log files while in the development and test environments, add the following to your development.rb and test.rb files found within /config/environments/

# Keeps the Last 5 logfiles which are rotated at every 5MB
config.logger = Logger.new("#{Rails.root}/log/#{ENV['RAILS_ENV']}.log", 5, 5242880)

Found on Stack Overflow

@jjmu15
jjmu15 / in_viewport.js
Created January 27, 2014 10:19
check if element is in viewport - vanilla JS. Use by adding a “scroll” event listener to the window and then calling isInViewport().
// Determine if an element is in the visible viewport
function isInViewport(element) {
var rect = element.getBoundingClientRect();
var html = document.documentElement;
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || html.clientHeight) &&
rect.right <= (window.innerWidth || html.clientWidth)
);
@travisvalentine
travisvalentine / steps.md
Last active June 10, 2023 19:00
Setup Facebook app to test authentication locally (aka, setting up App Domain)

Note: I had issues with setting up my Facebook app so authentication would work. I'd receive the error at the bottom, and it took me a while to figure out what was wrong

Here are the steps I took:

  • Go to http://developers.facebook.com/, create, and setup your app
  • When inside the dashboard, click "Settings"
  • Click "Add Platform"
  • Choose website (for authentication via the web app)
  • Add http://localhost:3000/ as "Site URL" (and "Mobile URL" if necessary)
  • Add localhost to "App Domains" above
@thebucknerlife
thebucknerlife / authentication_with_bcrypt_in_rails_4.md
Last active January 17, 2024 23:54
Simple Authentication in Rail 4 Using Bcrypt

#Simple Authentication with Bcrypt

This tutorial is for adding authentication to a vanilla Ruby on Rails app using Bcrypt and has_secure_password.

The steps below are based on Ryan Bates's approach from Railscast #250 Authentication from Scratch (revised).

You can see the final source code here: repo. I began with a stock rails app using rails new gif_vault

##Steps

@staltz
staltz / introrx.md
Last active June 29, 2024 15:58
The introduction to Reactive Programming you've been missing
@jctosta
jctosta / screen_cheatsheet.markdown
Last active June 27, 2024 15:17
Screen Cheatsheet

Screen Quick Reference

Basic

Description Command
Start a new session with session name screen -S <session_name>
List running sessions / screens screen -ls
Attach to a running session screen -x
Attach to a running session with name screen -r