Skip to content

Instantly share code, notes, and snippets.

View francois-blanchard's full-sized avatar
😁

François Blanchard francois-blanchard

😁
View GitHub Profile
@francois-blanchard
francois-blanchard / datetime_and_time_helpers.md
Last active January 13, 2016 14:15
DateTime and Time Rails Helpers

DateTime and Time Rails Helpers

Time.current.beginning_of_day
=> Tue, 12 Jan 2016 00:00:00 CET +01:00
Time.current.beginning_of_hour
=> Tue, 12 Jan 2016 18:00:00 CET +01:00
Time.current.beginning_of_minute
=> Tue, 12 Jan 2016 18:12:00 CET +01:00
Time.current.end_of_day
@francois-blanchard
francois-blanchard / rescue.md
Last active December 16, 2015 11:24
Begin rescue with ruby ☔

Begin rescue with ruby ☔

Basic

begin
  # something which might raise an exception
rescue SomeExceptionClass => some_variable
  # code that deals with some exception
rescue SomeOtherException => some_other_variable
@francois-blanchard
francois-blanchard / top_10_largest_files.md
Created December 1, 2015 08:06
Find top 10 largest file/directories

Find top 10 largest file/directories

$ sudo du -ha /home | sort -n -r | head -n 50
@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
@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 / cannot_delete_or_update_parent_row.md
Created August 18, 2015 09:52
Error Mysql when you try to delete row - Cannot delete or update a parent row: a foreign key constraint fails

Error Mysql when you try to delete row - Cannot delete or update a parent row: a foreign key constraint fails

You can't delete this row because any other is link to her with a foreign key

Find errors

  1. Try to delete
  2. View log with SHOW ENGINE INNODB STATUS;

Force delete row

  1. Disable foreign key SET FOREIGN_KEY_CHECKS=0;
@francois-blanchard
francois-blanchard / error_capistrano_deploy_could_not_parse_object.md
Last active January 13, 2021 10:05
Error Capistrano deploy - fatal: Could not parse object 'xx...xx'

Error Capistrano deploy - fatal: Could not parse object 'xx...xx'

  1. Connect you to your server $ ssh user@myserver
  2. Go to your deploy path and select the shared directorycd /your/directory/deploy/shared
  3. Remove the git cache rm -rf cached-copy
  4. Retry to deploy & have fun ;)
@francois-blanchard
francois-blanchard / checkbox_nested.md
Created April 3, 2015 14:45
Create nested attributes with checkbox

Create nested attributes with checkbox

# Class
has_many :sc_invited_celebrities
accepts_nested_attributes_for :proposed_posts, :sc_invited_celebrities, :answer_to_questions
# Controller
def new
 @social_campaign = SocialCampaign.new
@francois-blanchard
francois-blanchard / drop_mongodb.md
Last active January 14, 2016 09:00
Drop mongoDB table (collection)

DROP mongoDB collection

$ mongo
> show dbs
> use lolrate_development
> show collections
> db.games.drop()
> db.participants.drop()
> db.banned_champions.drop()
@francois-blanchard
francois-blanchard / import_bson.md
Last active August 29, 2015 14:16
Import mongoDB bson files

Import mongoDB bson files

$ mongorestore -d db_name -c collection_name path/collection_name.bson

Options

delete with restore

-- drop