Skip to content

Instantly share code, notes, and snippets.

View yosiyuki's full-sized avatar

Yoshiyuki Sugimoto yosiyuki

  • Kaito Wings
  • Ho Chi Minh City, Vietnam
  • X @saigon
View GitHub Profile
@yosiyuki
yosiyuki / gist:d84ef5f76f9a56ba2e3d9f48c076000d
Last active March 21, 2024 03:46
Serverside setup to capistrano restart puma

On server

> loginctl enable-linger [username]
> sudo loginctl enable-linger [username]
> vi .config/systemd/user/xxx_puma_production.service
> systemctl --user enable xxx_puma_production.service
> systemctl --user daemon-reload
@yosiyuki
yosiyuki / gist:623f92dc1eb4e9fefd71
Created August 14, 2014 08:41
Create page in RefineryCMS with ruby command
p = Refinery::Page.create(
title: '北海道',
custom_slug: 'hokkaido',
parent_id: 40,
layout_template: 'application',
view_template: 'show'
)
Refinery::PagePart.create!([
{refinery_page_id: p.id, title: 'Body', body: "<p>北海道のページ</p>"}
@yosiyuki
yosiyuki / user.rb
Last active August 29, 2015 14:03 — forked from kelhusseiny/user.rb
before_save :encrypt_password
after_save :clear_password
def encrypt_password
if password.present?
salt = BCrypt::Engine.generate_salt
self.encrypted_password= BCrypt::Engine.hash_secret(password, salt)
end
end
def clear_password
self.password = nil
@yosiyuki
yosiyuki / gist:7210527
Created October 29, 2013 07:47
update all objects into public in s3 from rails console
s3 = AWS::S3.new(access_key_id: 'YOUR_ACCESS_KEY_ID', secret_access_key: 'YOUR_SECRET_ACCESS_KEY')
bucket = s3.buckets['bucket_name']
bucket.objects.each{|obj| obj.acl = :public_read }
@yosiyuki
yosiyuki / application_helper.rb
Created April 5, 2013 03:34
rails helper for jQuery lazy load plugin * http://www.appelsiini.net/projects/lazyload
module ApplicationHelper
def lazy_image_tag source, options = {}
options['data-original'] = source
if options[:class].blank?
options[:class] = "lazy"
else
options[:class] = options[:class].to_s + " lazy"
end
image_tag 'image_grey.jpg', options
end
@yosiyuki
yosiyuki / gist:4239579
Created December 8, 2012 09:35
nesting content_tag on rails
content_tag :ul do
items.each do |item|
concat content_tag(:li, item.name)
end
end
@yosiyuki
yosiyuki / gist:3965495
Created October 27, 2012 17:51
automatically add link text to link_to (though this code force-update original link_to)
module ActionView
module Helpers
module UrlHelper
alias original_link_to link_to
def link_to(*args, &block)
if block_given?
options = args.first || {}
html_options = args.second
link_to(capture(&block), options, html_options)
@yosiyuki
yosiyuki / gist:3959466
Created October 26, 2012 15:34
jQuery in local namespace
;(function(window, $) {
var document = window.document;
$(document).ready(function() {
// ...write some code...
});
}(this, jQuery));
@yosiyuki
yosiyuki / application_controller.rb
Created October 12, 2012 16:31
Do something with translating client's ip address to locale in Rails
class ApplicationController < ActionController::Base
before_filter :set_locale_from_remote_addr
private
def set_locale_from_remote_addr
return do_something(session[:locale] if session[:locale]
raise UnknownIPAddessError unless request.remote_addr
geoip = GeoIP.new(Rails.root + "db/GeoLiteCountry.dat").country(request.remote_addr)
@yosiyuki
yosiyuki / application_controller.rb
Created October 12, 2012 16:31
Do something with translating client's ip address to locale in Rails
class ApplicationController < ActionController::Base
before_filter :set_locale_from_remote_addr
private
def set_locale_from_remote_addr
return do_something(session[:locale] if session[:locale]
raise UnknownIPAddessError unless request.remote_addr
geoip = GeoIP.new(Rails.root + "db/GeoLiteCountry.dat").country(request.remote_addr)