Skip to content

Instantly share code, notes, and snippets.

View allaire's full-sized avatar

Mathieu Allaire allaire

View GitHub Profile
@allaire
allaire / Mac Apps
Created March 2, 2012 04:39
Most of my Mac apps
- Adobe Suite
- Adium (Multi IM app)
- Antidote
- Aperture (Photos management/Photography)
- App Cleaner (Delete apps)
- Burn (occasional burning)
- Colloquy (IRC)
- Divvy (Window management)
- Dropbox
- Droplr
@allaire
allaire / multi_array_key_exists.php
Created August 2, 2012 00:53
multi_array_key_exists
<?php
function multi_array_key_exists($needle, $haystack)
{
foreach ($haystack as $key => $value)
{
if ($needle === $key)
{
return $key;
}
{
"auto_complete": true,
"color_scheme": "Packages/User/Tomorrow-Night-Eighties.tmTheme",
"file_exclude_patterns":
[
"*.sublime-project",
"*.pyc",
"*.pyo",
"*.exe",
"*.dll",
@allaire
allaire / validations.rb
Created October 22, 2012 23:03
Field with errors
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
unless html_tag =~ /^<label/
%{<div class="field-with-errors">#{html_tag}<label for="#{instance.send(:tag_id)}" class="message">#{instance.error_message.first}</label> </div>}.html_safe
else
%{<div class="field-with-errors">#{html_tag}</div>}.html_safe
end
end
@allaire
allaire / web.pill
Last active March 22, 2016 15:39
Web app bluepill configuration file
ENV['RAILS_ENV'] = 'production'
web_path = '/home/deployer/apps/web/current'
Bluepill.application('web', :log_file => "#{web_path}/log/bluepill.log") do |app|
app.process('unicorn') do |process|
process.pid_file = "#{web_path}/tmp/pids/unicorn.pid"
process.working_dir = web_path
process.start_command = "/usr/local/bin/bundle exec unicorn -D -c #{web_path}/config/unicorn.rb -E #{ENV['RAILS_ENV']}"
@allaire
allaire / gist:5278796
Created March 30, 2013 23:25
Minitest setup and exemple
# Environment
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
# Factories
require File.expand_path('../factories', __FILE__)
# Minitest
require 'minitest/autorun'
@allaire
allaire / test.rake
Last active December 15, 2015 16:19
Rakefile
require 'rake/testtask'
Rake::TestTask.new('test:models' => ['db:test:prepare', 'db:seed']) do |t|
t.pattern = 'test/models/**/*_test.rb'
end
Rake::TestTask.new('test:controllers' => ['db:test:prepare', 'db:seed']) do |t|
t.pattern = 'test/controllers/**/*_test.rb'
end
PgSearch.multisearch_options = {
:using => { tsearch: { prefix: true } }
}
module PgSearch
class Document < ActiveRecord::Base
before_save do
self.organization_id = searchable.organization_id
end
end
# Encoding: UTF-8
SIG_REGEX = /(--|__|\w-$)|(^(\w+\s*){1,3} #{"Sent from my".reverse}$)|(^(\w+\s*){1,3} #{"Envoyé de mon".reverse}$)/n
has a non escaped non ASCII character in non ASCII-8BIT script (RegexpError)
@allaire
allaire / capistrano-template.rb
Created November 4, 2013 03:27
Ryan Bates template method adapted for Capistrano v3
def template(from, to)
template_path = File.expand_path("../templates/#{from}", __FILE__)
template = ERB.new(File.new(template_path).read).result(binding)
upload! StringIO.new(template), to
end