Skip to content

Instantly share code, notes, and snippets.

View VictorTpo's full-sized avatar

Victor Thépaut VictorTpo

View GitHub Profile
@yannvery
yannvery / log_level.rb
Created June 25, 2014 07:54
Manage log level in a Rails console
#To turn it off
old_logger = ActiveRecord::Base.logger
ActiveRecord::Base.logger = nil
#To turn it back on
ActiveRecord::Base.logger = old_logger
@francois-blanchard
francois-blanchard / 0_backup_server.md
Last active April 16, 2022 08:27
Backup server with gem Backup and Whenever

Backup server with gem Backup and Whenever

Config Backup

Install backup gem

$ gem install backup

Generate Backup files see doc for genrate's options

##Merge many has_many

def get_fb_users
	FacebookUser.from("
		(
			(
				#{self.facebook_recipients_users.to_sql}
			) union (
				#{self.facebook_users.to_sql}
			)
@francois-blanchard
francois-blanchard / mysqlcheck.md
Last active July 26, 2020 16:23
Check and Repair MySQL Tables Using Mysqlcheck

Check and Repair MySQL Tables Using Mysqlcheck

Check a Specific Table in a Database

$ mysqlcheck -c database_name table_name -u root -p

Check All Tables in a Database

class MyKlass
  include
  CONSTANTS
  belongs_to
  has_one
  has_many
  accepts_nested_attributes_for
  attr_accessible
 validates
gid = class_instance.to_global_id # method allowing to get a string with both model name and id
GlobalID::Locator.locate(gid) # method of getting the object by its global id (very useful for collections of multiple type of objects, e.g. for polymorphic associations)
Example :
In the model that has a polymorphic attribute detailable:
getter:
def global_detailable
detailable.to_global_id if detailable.present?

Use Capybara as genius

Purpose

Capybara uses selector css to find elements, we can do more than ".my-class" or "#my-id". XPath can be used to look for elements using different syntax, see above exemple.

Exemples

@francois-blanchard
francois-blanchard / lolcommits.md
Created November 4, 2015 17:23
# Lolcommit : git + webcam

Lolcommit : git + webcam

Gem for take gif when you commit with git

Install

$ brew install imagemagick
$ brew install ffmpeg
$ gem install lolcommits
@francois-blanchard
francois-blanchard / view_log_with_crontab_tasks.md
Last active December 10, 2015 10:18
View log with crontab tasks

View log with crontab tasks

# 1. Open crontab
$ crontab -e

# 2. Add output log file
30 03 * * * /bin/bash -l -c 'backup perform -t my_backup' >> ~/crontab/backuplog

# 3. Open log file

Sublime hidden Shortcut, macro

All shortcuts

You can find all shortcut in Preferences -> Key bindings - Default

Usefull shortcut

super+k, super+b -> Toggle side bar

super+k, super+v -> Get more paste