Skip to content

Instantly share code, notes, and snippets.

View frahugo's full-sized avatar

Hugo Frappier frahugo

  • Giverny Capital Inc.
  • Montreal, Quebec, Canada
View GitHub Profile
@frahugo
frahugo / api.yaml
Last active March 29, 2024 19:37
CFB Api
{
"openapi": "3.1.0",
"info": {
"version": "1.0",
"title": "api",
"summary": "API for bagging machines",
"description": "API to use to interact with the Canada First Bricks MOC application. \nThis API is meant to provide data to a bagging machine.",
"contact": {
"name": "Hugo Frappier",
"url": "",
@frahugo
frahugo / config.ex
Last active September 21, 2022 19:27
Experiment mixing DataTable and a global LiveView outside of table (as issues occurs when having liveview in each row of the table - duplicate phx-ids detected)
config :gccg_web, GccgWeb.Withdrawals.OutflowStateLive,
pubsub_subscriptions: [
GccgCore.Accounts.WorkflowApplicationService
]
@frahugo
frahugo / monit.exs
Created March 29, 2017 17:37
Experiment on process monitoring
defmodule Test do
def run() do
# Span a new process
pid = spawn(fn -> :timer.sleep(100) end)
# Monitor the process
Process.monitor(pid)
# Kill the process
Process.exit(pid, :shutdown)
@frahugo
frahugo / gist:8ceb262e929d4c0a9575
Last active August 31, 2020 10:28
Ransack with JSONB query
class Registration < ActiveRecord::Base
scope :nhb_consent_eq, -> (enum = "yes") {
where("document @> ?", { nhb_consent: { value: enum } }.to_json )
}
private
def self.ransackable_scopes(auth_object = nil)
%i(nhb_consent_eq)
end

RouteTranslator gem is wrapping the current locale assignment in an around_filter set_locale_from_url and then resets it to the previous value.

Devise has a FailureApp to deal with unauthenticated requests, and it uses I18n to build the flash message and the redirection URL. But at that stage, the I18n default locale is set and the messages and URL are not localized in the context of the request (i.e. if the request URL is in French, and the default locale of the app is English, Devise will redirect to the English URL with an english flash message).

This is a solution for propagating the application locale to the the Devise middleware.

@frahugo
frahugo / service.exs
Last active August 29, 2015 14:23
Elixir experiments
defmodule Listener do
def on(event, message)
def on(:do_this, message) do
IO.puts "Yes #{message}"
end
def on(:do_that, _message) do
IO.puts "No, I'm ignoring the message"
end
@frahugo
frahugo / gist:7159276
Created October 25, 2013 18:13
Ruby tips
nil.nil? => true
"".nil? => false
nil.blank? => true
"".blank? => true
[].blank? => true
{}.blank? => true
[1,2].blank? => false
true.blank? => false
false.blank? => true
@frahugo
frahugo / deploy.rb
Last active December 25, 2015 19:59
namespace :deploy do
# Restart passenger on deploy
desc "Restarting mod_rails with restart.txt"
task :restart, :roles => :app, :except => { :no_release => true } do
run "touch #{current_path}/tmp/restart.txt"
solr.server.restart
end
end
@frahugo
frahugo / gist:4548208
Created January 16, 2013 15:53
Notes for the BackTrack and Armitage demo I did at Montreal.rb (www.montrealonrails.com) (2013-01-15)

BackTrack and Armitage demo at Montreal.rb (2013-01-15)

To start using BackTrack, either download a VM image or downlaod the ISO and configure a brand new virtual image (or your computer):

BackTrack login/password is: root/toor. Start X by typing startx.

To experiment with Metasploit, you can use the Armitage GUI: Applications > Backtrack > Exploitation Tools > Network Exploitation Tools > Metasploit Framework > armitage