Skip to content

Instantly share code, notes, and snippets.

Jose C Fernandez Joseworks

Block or report user

Report or block Joseworks

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View 20160307172445_change_paperclip_attachment_path.rb
class MoveAttachmentsToNewLocation < ActiveRecord::Migration
def initialize(name = self.class.name, version = nil)
access_key = Rails.application.secrets.g3_access_key_id
secret_key = Rails.application.secrets.g3_secret_access_key
storage = Fog::Storage::Google.new google_storage_access_key_id: access_key,
google_storage_secret_access_key: secret_key
@bucket_name = Rails.application.secrets.g3_bucket
@bucket = storage.directories.get(@bucket_name)
super(name, version)
@Joseworks
Joseworks / ruby array #subtract
Created Jan 27, 2018 — forked from karatedog/ruby array #subtract
Ruby Array's subtract method which subtracts the values of the elements not the elements themselves
View ruby array #subtract
# Ruby Array's "-" (minus) method removes elements from the receiver which exist in the parameter Array
[5, 6, 1] - [2, 3, 5]
# => [6, 1]
# this #subtract method will subtract the value of the parameter Array from the value of the receiver Array, defined by the actual index.
# type mismatch, Nil, and different Array length are not handled
class Array
View react - show hide element.jsx
class Child extends React.Component {
render () {
return (<div>I'm the child</div>);
}
}
class ShowHide extends React.Component {
constructor () {
super ();
this.state = {
@Joseworks
Joseworks / 1.rb
Created Dec 29, 2017 — forked from stevegraham/1.rb
Symbol#to_proc
View 1.rb
%w(john paul ringo george).map { |p| p.capitalize }
# => ["John", "Paul", "Ringo", "George"]
@Joseworks
Joseworks / OSX UTC Time Zone
Created Nov 14, 2017 — forked from nick-desteffen/OSX UTC Time Zone
Set Time zone in OSX to UTC
View OSX UTC Time Zone
sudo ln -sf /usr/share/zoneinfo/UTC /etc/localtime
@Joseworks
Joseworks / user.rb
Created Nov 10, 2017 — forked from harlow/user.rb
Extract a validator in Rails. Zip code validation.
View user.rb
# app/models/user.rb
class User < ActiveRecord::Base
validates :zip_code, presence: true, zip_code: true
end
@Joseworks
Joseworks / multiple_ssh_setting.md
Created Oct 17, 2017 — forked from jexchan/multiple_ssh_setting.md
Multiple SSH keys for different github accounts
View multiple_ssh_setting.md

Multiple SSH Keys settings for different github account

create different public key

create different ssh key according the article Mac Set-Up Git

$ ssh-keygen -t rsa -C "your_email@youremail.com"
@Joseworks
Joseworks / rendering_helper.rb
Created Aug 10, 2017 — forked from tylerhunt/rendering_helper.rb
Override Rails' #render helper to fix an issue with rendering partials based on an object within a namespace.
View rendering_helper.rb
module RenderingHelper
# Override Rails' #render helper to fix an issue with it not honoring objects
# with #to_partial_path definitions that return absolute paths, which is
# problematic when rendering partials within a namespaced controller.
def render(options={}, locals={}, &block)
return super unless options.respond_to?(:to_partial_path)
object = options
path = object.to_partial_path
@Joseworks
Joseworks / securing_rails_updates.md
Created Aug 1, 2017 — forked from peternixey/securing_rails_updates.md
How Homakov hacked GitHub and how to protect your application by Peter Nixey
View securing_rails_updates.md

##How Homakov hacked GitHub and the line of code that could have prevented it


Please note: THIS ARTICLE IS NOT WRITTEN BY THE GITHUB TEAM or in any way associated with them. It's simply hosted as a Gist because the markdown formatting is excellent and far clearer than anything I could manage on my personal Tumblr at peternixey.com.

If you'd like to follow me on twitter my handle is @peternixey


View render_and_redirect.markdown

Render and Redirect

The normal controller/view flow is to display a view template corresponding to the current controller action, but sometimes we want to change that. We use render in a controller when we want to respond within the current request, and redirect_to when we want to spawn a new request.

Render

The render method is very overloaded in Rails. Most developers encounter it within the view template, using render :partial => 'form' or render @post.comments, but here we'll focus on usage within the controller.

:action

You can’t perform that action at this time.