Skip to content

Instantly share code, notes, and snippets.

@yannvery
yannvery / extract_events_from_bugsnag.md
Created February 23, 2021 11:13
Extract events from a search error in Bugsnag
@yannvery
yannvery / mysql2_load_error.md
Created September 5, 2016 08:55
Load error Mysql2 with an old rails application

When you encounter

/Users/kernel/.gem/ruby/2.0.0/gems/mysql2-0.3.16/lib/mysql2.rb:8:in 
  `require': dlopen(/Users/kernel/.gem/ruby/2.0.0/gems/mysql2-0.3.16/lib/mysql2/mysql2.bundle, 9): 
    Library not loaded: 
      /usr/local/lib/libmysqlclient.18.dylib (LoadError)

Try gem pristine mysql2, this command restores installed gems to pristine condition from files located in the gem cache

@yannvery
yannvery / uuid_on_rails.md
Last active April 29, 2016 12:22
Use uuid on Rails with PostgreSQL

Use uuid on rails with PostgreSQL

This guide is a sort of extract of official rails guide: Official rails guide

Here I describe an implementation of uuid with PostgreSQL >= 9.4. This requires to enable pgcrypto

Example with a creation of a table named trackers:

class CreateTrackers < ActiveRecord::Migration[5.0]
@yannvery
yannvery / postgre_cheatsheet.md
Last active April 19, 2016 08:57
postgre cheatsheet

Export database

pg_dump database_name > database_name.dump

Export Structure

pg_dump -s database_name > database_name.dump

Restore/Import Database with pg_dump

pg_restore --verbose --clean --no-acl --no-owner -h localhost -d database_name database_file.dump

@yannvery
yannvery / RSpec_cheatsheet.md
Last active February 22, 2018 20:32
RSpec cheatsheet

RSpec Cheatsheet

Specs layers

 +-----------------------------------------------------------------------------------------+

   +----------+                                                       +------------------+
   |          |                                                       |                  |
   |  View    |                                                       |                  |
   |  Specs   |            View                                       |                  |
@yannvery
yannvery / rvm_cron_config.md
Created March 24, 2016 16:09
Set a rake task on crontab with rvm

How to set a rake task in crontab with RVM

Introduction

It seems there is multiple ways to configure rvm and use it on a crontab. Here I describe a method which be used on a client app

Let assume you want to launch rake stats on production_app application and write the results on a file

Find the wrapper app

@yannvery
yannvery / finding_sql_queries.md
Last active March 18, 2016 10:39
Finding sql queries

Finding caller of sql query in a Rails App

I've been wanted to know where some sql queries are coming from. I worked on a Rails app with some tests which have been executed slowly. In the log file I saw this request a bunch of time :

SELECT `roles`.* FROM `roles` INNER JOIN `users_roles` ON `roles`.`id` = `users_roles`.`role_id` WHERE `users_roles`.`user_id` = 8 AND (((roles.name = 'admin') AND (roles.resource_type IS NULL) AND (roles.resource_id IS NULL)))

So I've decided to use a Ryan Bigg tips. I've included this snippet in my test suite :

@yannvery
yannvery / create_an_api_in_5_minutes.md
Last active February 17, 2016 15:05
Fake API in 5 minutes

Create a fake api in 5 minutes

I dont't find yet how to do this with ruby, so I use a npm package.

Install json-server

github repository: https://github.com/typicode/json-server

Note: g option has been used to install the package globally (for all users).

@yannvery
yannvery / tracepoint_and_rails_reload!.md
Created February 8, 2016 23:31
TracePoint and Rails reload!

TracePoint and Rails reload! / startup

On a specific rails application (4.2), when a developper call reload! method on a console he'll see:

Engine Load (0.3ms)  SELECT  `engines`.* FROM `engines` WHERE `engines`.`label` = 'influencer' LIMIT 1
Engine Load (0.3ms)  SELECT  `engines`.* FROM `engines` WHERE `engines`.`label` = 'speaker' LIMIT 1
Engine Load (0.3ms)  SELECT  `engines`.* FROM `engines` WHERE `engines`.`label` = 'animator' LIMIT 1
Engine Load (0.2ms)  SELECT  `engines`.* FROM `engines` WHERE `engines`.`label` = 'ambassador' LIMIT 1
Engine Load (0.2ms) SELECT `engines`.* FROM `engines` WHERE `engines`.`label` = 'private_show' LIMIT 1
@yannvery
yannvery / regexp_ruby.md
Created January 26, 2016 15:32
Regular expressions in Ruby

Regexp and match groups in ruby

There is multiple ways to use regular expressions with ruby.

Simple example

We're going to use the following pattern: /\A\d{3}-[\w-]+\.\w{3,4}\z/

pattern = /\A\d{3}-[\w-]+\.\w{3,4}\z/
pattern =~ "215-hello-world.avi"     # => 0
pattern =~ "test.mp3"                # => 0