Skip to content

Instantly share code, notes, and snippets.

View 3014zhangshuo's full-sized avatar
🎯
Coding

张硕 3014zhangshuo

🎯
Coding
View GitHub Profile
@3014zhangshuo
3014zhangshuo / _user.html.erb
Created May 3, 2017 13:06 — forked from Joseph-N/_user.html.erb
Rails - Load more with jQuery and Ajax Code snippets - Tutorial link http://josephndungu.com/tutorials/rails-load-more-results-using-jquery-ajax
<div class="record" data-id="<%= user.id %>">
<p><b>ID: </b> <%= user.id %></p>
<p><b>Name: </b> <%= user.name %></p>
<p><b>Location: </b> <%= user.location %> </p>
<p><%= link_to 'Show', user %> | <%= link_to 'Edit', edit_user_path(user) %> | <%= link_to 'Destroy', user, method: :delete, data: { confirm: 'Are you sure?' } %> </p>
</div>
@3014zhangshuo
3014zhangshuo / jquery.editable.js
Created August 8, 2017 05:53 — forked from tom--/jquery.editable.js
jquery plugin to make contenteditable text trigger a change event when it changes
(function ($) {
'use strict';
/**
* Makes contenteditable elements within a container generate change events.
*
* When you do, e.g. $obj.editable(), all the DOM elements with attribute contenteditable
* that are children of the DOM element $obj will trigger a change event when their
* contents is edited and changed.
*
* See: http://html5demos.com/contenteditable
@3014zhangshuo
3014zhangshuo / operations_range_of_numbers.md
Created September 20, 2017 04:48 — forked from CodeRecipez/operations_range_of_numbers.md
Sass 101 - A newb's guide: Operations range of numbers

The @for directive repeatedly outputs a set of styles. For each repetition, a counter variable is used to adjust the output. The directive has two forms: @for $var from <start> through <end> and @for $var from <start> to <end>.

Note the difference in the keywords through and to. $var can be any variable name, like $i; <start> and <end> are SassScript expressions that should return integers.

The @for statement sets $var to each successive number in the specified range and each time outputs the nested styles using that value of $var. For the form from <start> through <end>, the range includes the values of <start> and <end>, but the form from <start> to <end> runs up to but not including the value of <end>.

from <start> through <end>

$cols: 2;
@3014zhangshuo
3014zhangshuo / yield.rb
Created September 27, 2017 14:27 — forked from cowboy/yield.rb
An example using "yield self if block_given?"
# No yielding
class NormPerson
attr_accessor :first, :last
def initialize(first = nil, last = nil)
@first = first
@last = last
end
def hello
puts "#{@first} #{@last} says hello!"
# config/routes.rb
resources :documents do
scope module: 'documents' do
resources :versions do
post :restore, on: :member
end
resource :lock
end
end
# config/routes.rb
resources :documents do
scope module: 'documents' do
resources :versions do
post :restore, on: :member
end
resource :lock
end
end
@3014zhangshuo
3014zhangshuo / README.md
Created October 11, 2017 03:29 — forked from timcheadle/README.md
Make /robots.txt aware of the Rails environment

Make /robots.txt aware of the Rails environment

You probably don't want Google crawling your development staging app. Here's how to fix that.

$ mv public/robots.txt config/robots.production.txt
$ cp config/robots.production.txt config/robots.development.txt

Now edit config/routes.rb to add a route for /robots.txt, and add the controller code.

@3014zhangshuo
3014zhangshuo / gist:c48eb2bd10afeb8eaae93a3f7ddacec2
Created October 16, 2017 13:17 — forked from dhh/gist:1014971
Use concerns to keep your models manageable
# autoload concerns
module YourApp
class Application < Rails::Application
config.autoload_paths += %W(
#{config.root}/app/controllers/concerns
#{config.root}/app/models/concerns
)
end
end
@3014zhangshuo
3014zhangshuo / 500-404-apache-error-report.sh
Created October 30, 2017 05:38 — forked from jrumbut/500-404-apache-error-report.sh
Get 404 and 500 errors from apache error log
cat access.log.1 | grep " 500 " | awk -F'"' '{print $2,",",$4,",",$6}' > /home/ubuntu/500.log
cat access.log.1 | grep " 404 " | awk -F'"' '{print $2,",",$4,",",$6}' > /home/ubuntu/404.log
@3014zhangshuo
3014zhangshuo / gist:f7b8653530fd93df7864fd2863c749c5
Created October 31, 2017 01:14 — forked from ruckus/gist:3124445
Rails Single Table Inheritance example
create_table :media_items do |t|
t.string :type, :null => false, :limit => 32
t.string :name
t.timestamps
end
class MediaItem < ActiveRecord::Base
validates_presence_of :kind
end