The model must be created before to attach a file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/application.rb | |
require File.expand_path('../boot', __FILE__) | |
require 'rails/all' | |
Bundler.require(:default, Rails.env) | |
module App | |
class Application < Rails::Application |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# crontab -e | |
0 4 * * * sync; echo 3 > /proc/sys/vm/drop_caches |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
ENV.delete('RUBYLIB') | |
ENV.delete('RM_INFO') | |
exec 'bundle exec guard' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_ssl_username | |
request.env["REMOTE_USER"] | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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:?} |
OlderNewer