Skip to content

Instantly share code, notes, and snippets.

View miguelperez's full-sized avatar
🏠
Working from home

Miguel miguelperez

🏠
Working from home
View GitHub Profile
@miguelperez
miguelperez / README.md
Created September 8, 2023 16:19
Use the same IAM assumed roles to connect to AWS S3 without having to pass credentials.

Intro

when using activestorage, one could set the ec2 instance with a role with access to certain aws s3 buckets.

In this case, we only define the region and bucket name to allow activestorage to connect to s3.

# in config/storage.yml
some_files:
 service: S3
@miguelperez
miguelperez / README.md
Last active January 4, 2016 17:19
Setting new mac checklist

Basic Checklist

Development

  1. Setup your icloud account (if any)
  2. Instalar chrome
  3. instalar dropbox
  4. instalar onepassword
  5. Bajar xcode
  6. instalar iterm2
@miguelperez
miguelperez / form_to_ajax.js
Created January 12, 2013 18:41
Whenever you want to send a form as ajax, include this small snipet of code for that...
// Receives the selector of a form and return the params as an array
// Example:
// ["date=2013-01-11", "transactions[][transaction_type]=withdrawal", "transactions[][ammount]=", "transactions[][description]="]
function formAsParams(formSelector){
var array = $(formSelector).serializeArray(),
params = _.reduce(array, function(memo, elem){ memo.push(elem.name + "=" + elem.value); return memo; }, []);
return params;
}
// Given a form with data-attributes data-post-to and data-method, it will do an ajax request to the url
@miguelperez
miguelperez / query_params.rb
Created July 16, 2012 20:04
Query params. Given a hash|array it will return a query string for a url.
#This module lets us create a query string from a hash or array.
module QueryParams
def self.encode(value, key = nil, sep = '&')
case value
when Hash then value.map { |k,v| encode(v, append_key(key,k), sep) }.join(sep)
when Array then value.map { |v| encode(v, "#{key}[]", sep) }.join(sep)
when nil then ''
else
if value.to_s.present?
"#{key}=#{CGI.escape(value.to_s)}"
#!/usr/bin/env ruby
LETTERS = {
:a => 'ka',
:b => 'zu',
:c => 'mi',
:d => 'te',
:e => 'ku',
:f => 'lu',
:g => 'ji',
@miguelperez
miguelperez / README
Created June 5, 2012 18:46
Controller conventions
Given a controller file, with some actions in it... This gist defines how I like to organize the rspec controller file.
@miguelperez
miguelperez / README
Created June 5, 2012 18:39
Model Conventions
This conventions are the ones I use when developing models.
Basically all the rspec generated file is separated in sections depending on the things the model does, validates and sets.
Validations
Relations
instance methods
scopes
All of those tested separately.
@miguelperez
miguelperez / README
Created June 5, 2012 13:44
Localization guidelines
This are some common conventions for localization files in ruby on rails.
Most of this can be found in the rails guides.
I basically separate the files in directories related to where they will be used. Adding this line to config/application.rb so the files gets loaded correctly.
config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**/*.{rb,yml}').to_s]
Models
Views
@miguelperez
miguelperez / application.css
Created April 14, 2012 16:19
Adding flash messages to headers upon xhr requests with ICanHaz and Jquery
//this is for the preloader gif
.loading{
position: fixed;
right: 5px;
bottom: 5px;
display:none;
}
@miguelperez
miguelperez / Blueprint debug.
Created May 26, 2011 13:26
Blueprint debug script. Just append this to the head of the HTML file that should be including the blueprint files.
<!-- I took this code from somewhere, just can recall now. -->
<script type="text/javascript">
function toggleGrid() {
var toggle = document.getElementById('toggleGrid');
var container;
if(toggle.innerHTML == 'Hide Grid') {
toggle.innerHTML = 'Show Grid';
ripClass('');
}