Skip to content

Instantly share code, notes, and snippets.

View mtparet's full-sized avatar

Matthieu Paret mtparet

View GitHub Profile
#je récupère un objet "sequence" qui a de multiples "sequence_liste"
@sequence = Sequence.where(:name => params[:sequence_name]).first
sequence_listes = @sequence.sequence_liste.order("order_sequence")
#ici je veux un tableau de string de image.name de chaque sequence_liste
tab_ordered = sequence_listes.each { |i| i.image.name}
#et ensuite je compte le transférer dans mon code javascript
tab_correct = <%= array_or_string_for_javascript(@tab_correct) %>;
@mtparet
mtparet / gist:5217c21f0b6aebae6c27
Last active August 29, 2015 14:24
Segfault iwith ruby 2.2.2
/home/deployer/ruby/2.2.0/gems/celluloid-0.16.0/lib/celluloid/actor_system.rb:77: [BUG] Segmentation fault at 0x00000000000000
ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-linux]
-- Control frame information -----------------------------------------------
c:0011 p:---- s:0044 e:000043 CFUNC :each
c:0010 p:0065 s:0041 e:000040 BLOCK /home/deployer/ruby/2.2.0/gems/celluloid-0.16.0/lib/celluloid/actor_system.rb:77
c:0009 p:0036 s:0039 E:000258 BLOCK /usr/local/rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/timeout.rb:89
c:0008 p:0008 s:0034 e:000033 BLOCK /usr/local/rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/timeout.rb:34 [FINISH]
c:0007 p:---- s:0032 e:000031 CFUNC :catch
c:0006 p:0047 s:0028 e:000027 METHOD /usr/local/rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/timeout.rb:34
@mtparet
mtparet / config.md
Last active December 29, 2015 11:03 — forked from darK-Zi0n-te4am-cr3vv/etc..init..openvpn-instance.conf
Starting OpenVPN using Systemd

As root:

Copy your config file .ovpn to /etc/openvpn/config.ovpn

Add a file /etc/openvpn/auth.txt with two lines:

your_username
your_password
@mtparet
mtparet / .travis.yml
Last active September 13, 2016 09:01
Travis yml to install mysql 5.7
before_install:
- chmod +x ./scripts/* #thanks https://medium.com/@psaunders
- ./script/travis_mysql_5.7.sh
- ./script/mysql-reset-root-password.sh
@mtparet
mtparet / travis_mysql_5.7.sh
Last active December 2, 2016 10:24
Install mysql 5.7
#!/usr/bin/env bash
sudo service mysql stop || echo "mysql not stopped"
sudo stop mysql-5.6 || echo "mysql-5.6 not stopped"
echo mysql-apt-config mysql-apt-config/select-server select mysql-5.7 | sudo debconf-set-selections
wget http://dev.mysql.com/get/mysql-apt-config_0.7.3-1_all.deb
sudo dpkg --install mysql-apt-config_0.7.3-1_all.deb
sudo apt-get update -q
sudo apt-get install -q -y -o Dpkg::Options::=--force-confnew mysql-server
sudo mysql_upgrade
@mtparet
mtparet / mysql-reset-root-password.sh
Last active December 2, 2016 10:23
Reset password mysql 5.7
#!/usr/bin/env bash
set -x
set -e
sudo service mysql stop || echo "mysql not stopped"
sudo stop mysql-5.6 || echo "mysql-5.6 not stopped"
sudo mysqld_safe --skip-grant-tables &
sleep 4
sudo mysql -e "use mysql; update user set authentication_string=PASSWORD('') where User='root'; update user set plugin='mysql_native_password';FLUSH PRIVILEGES;"
sudo kill -9 `sudo cat /var/lib/mysql/mysqld_safe.pid`
sudo kill -9 `sudo cat /var/run/mysqld/mysqld.pid`
@mtparet
mtparet / gist:60679c5de398136cca9ceb1121bb3800
Last active December 4, 2017 10:41
Useful OPS commands
find swap process
find /proc -maxdepth 2 -path "/proc/[0-9]*/status" -readable -exec awk -v FS=":" '{process[$1]=$2;sub(/^[ \t]+/,"",process[$1]);} END {if(process["VmSwap"] && process["VmSwap"] != "0 kB") printf "%10s %-30s %20s\n",process["Pid"],process["Name"],process["VmSwap"]}' '{}' \; | awk '{print $(NF-1),$0}' | sort -hr
find parent of process
pstree -aps
display docker pid and name
docker ps -q | xargs docker inspect --format '{{.State.Pid}}, {{.Name}}'
@mtparet
mtparet / activerecord_test_works.rb
Created February 2, 2018 13:56
Test which works for children validation
# frozen_string_literal: true
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do
@mtparet
mtparet / gist:fd34d820a862e3390cfbbfd3f28618e6
Created February 2, 2018 17:22
Test nested validations
# frozen_string_literal: true
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do
@mtparet
mtparet / test_validation.rb
Created February 2, 2018 17:25
Polymorphic relation validation
# frozen_string_literal: true
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do