Skip to content

Instantly share code, notes, and snippets.

View gpr's full-sized avatar

Grégory Romé gpr

View GitHub Profile
@gpr
gpr / OutlookMonitoring.py
Last active September 4, 2021 19:43
Outook mail monitoring and processing with Python
# Origin: http://stackoverflow.com/users/1259292/yusumishi
import win32com.client
import pythoncom
import re
class Handler_Class(object):
def OnNewMailEx(self, receivedItemsIDs):
# RecrivedItemIDs is a collection of mail IDs separated by a ",".
# You know, sometimes more than 1 mail is received at the same moment.
@gpr
gpr / myssl_controller.rb
Created November 4, 2013 08:30
How to get email from X509 certificate used for client authentication. The email could be used for setting the current user in Devise or Omniauth (considering that the user has been authenticated) Common name could be used instead of email by using SSL_CLIENT_S_DN_CN. request.env["SSL_CLIENT_S_DN_Email"] could be used by enabling +StdEnvVars but…
def get_ssl_username
request.env["REMOTE_USER"]
end
@gpr
gpr / csvget
Last active December 27, 2015 15:59
How to get a specific field value with csvkit
#!/bin/bash
#
# csvget -- use csvkit too get a specific field value
#
# Usage: csvget <field_name> <line_number>
# get the field <field_name> value at the <line_number>th line
FieldName=${1:?}
N=${2:?}
@gpr
gpr / application.rb
Created February 21, 2014 08:29
Manage Rails application version number with rake tasks (includes git-flow support)
# config/application.rb
require File.expand_path('../boot', __FILE__)
require 'rails/all'
Bundler.require(:default, Rails.env)
module App
class Application < Rails::Application
@gpr
gpr / gist:5f08a40d7bb3bd80ba78
Created January 12, 2015 10:50
Generate random bytes with Ruby
# Nothing to require
# You can define your seed or generate one using system random function
seed = srand
prng = Random.new(seed)
# Generate X bytes
X = 16
bin_str = prng.bytes(X)
@gpr
gpr / gist:03af2823eab9f9e7d867
Created January 19, 2015 08:48
Desktop memory cleanup task
# crontab -e
0 4 * * * sync; echo 3 > /proc/sys/vm/drop_caches
@gpr
gpr / process_mail_attachments.rb
Created March 3, 2015 11:34
Process email attachments in Rails
# message is Mail::Message
# see http://www.rubydoc.info/github/mikel/mail/Mail/Message
message.attachments.each do |attch|
f = Tempfile.new(attch.filename, Rails.root.join('tmp'))
puts " - Save #{attch.filename} to #{f.path}"
begin
f.binmode
f.write attch.decoded
ensure
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
@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
@gpr
gpr / README.md
Last active August 29, 2015 14:20
Paperclip warning

WARNING

The model must be created before to attach a file.