Skip to content

Instantly share code, notes, and snippets.

Avatar

Vincent Durand madwork

View GitHub Profile
@madwork
madwork / deploy.rb
Created Nov 7, 2013
Capistrano (version 2), deploy with Bower. Install into shared directory
View deploy.rb
before "bower:install", "bower:symlink"
after "bower:install", "bower:prune"
before "deploy:assets:precompile", "bower:install"
namespace :bower do
desc "Symlink shared components to current release"
task :symlink, roles: :app do
run "mkdir -p #{shared_path}/components"
run "ln -nfs #{shared_path}/components #{latest_release}/vendor/assets/components"
@madwork
madwork / attachment.rb
Last active Jul 25, 2021
Polymorphic attachments with CarrierWave and nested_attributes
View attachment.rb
class Attachment < ActiveRecord::Base
mount_uploader :attachment, AttachmentUploader
# Associations
belongs_to :attached_item, polymorphic: true
# Validations
validates_presence_of :attachment
@madwork
madwork / gem-public_cert.pem
Created Oct 17, 2013
RubyGems certificate use to sign my gems
View gem-public_cert.pem
-----BEGIN CERTIFICATE-----
MIIDkjCCAnqgAwIBAgIBATANBgkqhkiG9w0BAQUFADBHMRcwFQYDVQQDDA52aW5j
ZW50LmR1cmFuZDEXMBUGCgmSJomT8ixkARkWB21hZHdvcmsxEzARBgoJkiaJk/Is
ZAEZFgNvcmcwHhcNMTMwOTE4MTY0MDEwWhcNMTQwOTE4MTY0MDEwWjBHMRcwFQYD
VQQDDA52aW5jZW50LmR1cmFuZDEXMBUGCgmSJomT8ixkARkWB21hZHdvcmsxEzAR
BgoJkiaJk/IsZAEZFgNvcmcwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIB
AQDzlsghBvfbH4yPzi3dXyfkmxjy/uksOkYwzqwbZ6z/TvJdIjY9Xqi/gLe2AxGF
kuVxDuxih84WDG8qxCnAfUxt2nDGAVEspmTXHBAsyZqLLDRiP5LvmH/eAKsJY+rU
ERSJOaLAotMqHHqXiWnpRgFnzE6RM3Cnqq8LH0jIGF9F8gZVLZeRD+VXK4IX1Vyd
HgZKgTPL15k92u7bzqBw7niPCBa9LfYxID6E1bnSHw/kb+7hWarVd/sxpgeH0jgb
View database.yml.example mysql2
# MySQL. Versions 4.1 and 5.0 are recommended.
#
# Install the MySQL driver:
# gem install mysql2
#
# And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
development:
adapter: mysql2
encoding: utf8
@madwork
madwork / powrc
Created Jun 9, 2013
powrc with chruby
View powrc
export SSL_CERT_FILE=/usr/local/share/ca-bundle.crt
source /usr/local/share/chruby/chruby.sh
chruby $(cat .ruby-version)
@madwork
madwork / gemrc
Created May 14, 2013
rubygems configuration file
View gemrc
---
:verbose: true
gem: --no-ri --no-rdoc --prerelease
:update_sources: true
:sources:
- https://rubygems.org
:backtrace: false
:bulk_threshold: 1000
:benchmark: false
@madwork
madwork / cipher.rb
Created Apr 17, 2013
Cipher implementation
View cipher.rb
#!/usr/local/bin/ruby
#
# http://www.ruby-doc.org/stdlib-2.0/libdoc/openssl/rdoc/OpenSSL/Cipher.html
require 'base64'
require 'openssl'
# create the cipher for encrypting
cipher = OpenSSL::Cipher::Cipher.new("aes-256-cbc")
cipher.encrypt
@madwork
madwork / install.sh
Last active Dec 14, 2015
Max OS X 10.8 + chruby + Ruby 2.0
View install.sh
brew install chruby readline openssl libyaml
brew link openssl --force
export ARCHFLAGS="-arch x86_64"
export CFLAGS="-g -O2"
export LDFLAGS="-L/usr/local/lib -L/usr/local/opt/readline/lib"
export CPPFLAGS="-I/usr/local/include -I/usr/local/opt/readline/include"
mkdir ~/.rubies
wget http://cache.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p353.tar.gz
@madwork
madwork / bench.rb
Created Mar 12, 2013
String prepend FTW
View bench.rb
require 'benchmark'
require 'benchmark/ips'
Benchmark.ips do |x|
x.report("String::prepend") { "foo".prepend "tmp/" }
x.report("File.join") { File.join "tmp", "foo" }
end
puts
Benchmark.bm do |x|
x.report("String::prepend") { 1000000.times{"foo".prepend "tmp/"} }
@madwork
madwork / README.md
Last active Dec 14, 2015
Various method to add dynamic accessors (getters/setters)
View README.md

Various method to add dynamic accessors (getters/setters)

Make it yourself way

foo = Foo1.new
foo.build1 :a, :b
foo.a = 1
foo.a

foo = Foo1.new