Skip to content

Instantly share code, notes, and snippets.

View gpr's full-sized avatar

Grégory Romé gpr

View GitHub Profile
@gpr
gpr / Vagrantfile
Created February 20, 2018 08:35
Sample Vagrantfile with Ansible provisionning
# Vagrantfile
Vagrant.require_version ">= 1.7.0"
Vagrant.configure(2) do |config|
config.vm.define "ubuntu_xenial", primary: true do |host|
host.vm.box = "ubuntu/xenial64"
end
config.vbguest.auto_update = true
@gpr
gpr / README.md
Last active November 23, 2017 09:10
This README describe how to setup sshd and pam to authorize people to login through ssh if they have either a valid publickey or a valid password AND they have a valid google authenticator code.

README

Install the PAM module

sudo apt install libpam-google-authenticator

Enable google-authenticator for your sessions:

@gpr
gpr / docker_rm_all
Created February 15, 2016 15:31
rm all Docker containers
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
@gpr
gpr / guard
Created July 24, 2015 12:41
Script for launching Guard in RubyMine (to avoid minitest output issue)
#!/usr/bin/env ruby
ENV.delete('RUBYLIB')
ENV.delete('RM_INFO')
exec 'bundle exec guard'
@gpr
gpr / validates.rb
Last active March 29, 2016 13:14
Validate only in production environment. In order to accelerate some test I should bypass some validation steps.
validates_numericality_of :key_size, greater_than: 1024, unless: "Rails.env.test?"
@gpr
gpr / README.md
Last active August 29, 2015 14:24
Dynamic nested attributes belongs_to with simple_form

README

This gist shows how to create a dynamic subform for nested belongs_to association with simple_form.

Models

We have two models, Product and Component where:

@gpr
gpr / gui.rb
Last active November 4, 2019 19:11
How to use Glade resource with Ruby Gtk3
#!/usr/bin/env ruby
require 'gtk3'
def not_yet_implemented(object)
puts "#{object.class.name} sent a signal!"
end
def on_main_window_destroy(object)
Gtk.main_quit()
@gpr
gpr / README.md
Last active August 29, 2015 14:20
Paperclip warning

WARNING

The model must be created before to attach a file.

@gpr
gpr / PolymorphicAssociationWithSimpleForm.md
Last active August 29, 2018 11:47
How to manage polymorphic associations with simple_form and JQuery

Introduction

How to manage polymorphic associations with simple_form and JQuery?

This is a solution.

.
├── app
│   ├── assets
class RouteRecognizer
attr_reader :paths
# To use this inside your app, call:
# `RouteRecognizer.new.initial_path_segments`
# This returns an array, e.g.: ['assets','blog','team','faq','users']
INITIAL_SEGMENT_REGEX = %r{^\/([^\/\(:]+)}
def initialize