Skip to content

Instantly share code, notes, and snippets.

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

Andy Wang yorzi

🏠
Working from home
  • Xi'an, China
  • 16:03 (UTC +08:00)
View GitHub Profile
@yorzi
yorzi / get_params.js
Created June 15, 2011 09:08
JS: get params in url query string
function getParameterByName( name ) {
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( window.location.href );
if( results === null )
return "";
else
return decodeURIComponent(results[1].replace(/\+/g, " "));
}
@yorzi
yorzi / with_exclusive_scope.rb
Created June 23, 2011 04:41
default_scope will interrupt the update_attributes on the AR outside the default_scope, below solution will work.
#default_scope will interrupt the update_attributes on the AR outside the default_scope, below solution will work.
#with_exclusive_scope is protected, so you have to create a class method:
def self.include_deleted_in
Post.with_exclusive_scope { yield }
end
#then in your controller call
@yorzi
yorzi / rails_3_1_rc4_changes.md
Created June 24, 2011 02:08 — forked from ryanb/rails_3_1_rc4_changes.md
The Changelogs for Rails 3.1 Beta 1

Railties 3.1 RC4

  • The new rake task assets:clean removes precompiled assets. [fxn]

  • Application and plugin generation run bundle install unless --skip-gemfile or --skip-bundle. [fxn]

  • Fixed database tasks for jdbc* adapters #jruby [Rashmi Yadav]

  • Template generation for jdbcpostgresql #jruby [Vishnu Atrai]

@yorzi
yorzi / signInModal-cs.js.coffee
Created July 1, 2011 14:23
signInModal cs.js.coffee
signInModal = ->
console.log("in modal 01")
$( "#sign_in_modal" ).dialog
modal: true
autoOpen: $("body").hasClass("show_login")
resizable: false
minWidth: 400
$("a.login, a#login_link").click =>
console.log("in modal 02")
function signInModal(){
$( "#sign_in" ).dialog({
modal: true,
autoOpen: $("body").hasClass("show_login"),
resizable: false,
minWidth: 400
});
$("a.login, a#login_link").click(function(){
$( "#sign_in" ).dialog("open");
@yorzi
yorzi / jquery.myplugin.coffee
Created July 1, 2011 14:42 — forked from jimeh/jquery.myplugin.coffee
Example jQuery plugin written in CoffeeScript, and the resulting compiled JavaScript file.
$.fn.extend
myplugin: (options) ->
self = $.fn.myplugin
opts = $.extend {}, self.default_options, options
$(this).each (i, el) ->
self.init el, opts
self.log el if opts.log
$.extend $.fn.myplugin,
default_options:
@yorzi
yorzi / pageless_style_pagination_helper.rb
Created July 6, 2011 08:39
create a pageless page, click "more" for new paginated results.
# usage:
# link_to_next_page(@items)
# link_to_next_page(@items, :remote => true) # Ajax
def link_to_next_page(scope, name, options = {}, &block)
param_name = options.delete(:param_name) || Kaminari.config.param_name
link_to_unless scope.last_page?, name, {param_name => (scope.current_page + 1)}, options.merge(:rel => 'next') do
block.call if block
end
end
@yorzi
yorzi / error.log
Created July 11, 2011 01:45
full trace on group creation
RuntimeError in GroupsController#create
ProfilePhoto#content_type delegated to photo.content_type, but photo is nil: #<ProfilePhoto id: nil, user_id: 6, owner_id: 5, owner_type: "Group", title: nil, description: nil, upload_id: nil, status: "processed", created_at: nil, updated_at: nil, size: nil, height: nil, width: nil, filename: nil, content_type: nil, parent_id: nil, photo_id: nil>
Rails.root: /Users/andy/intridea.workspace/recnation
Application Trace | Framework Trace | Full Trace
vendor/gems/ss_photos/app/models/profile_photo.rb:26:in `rescue in content_type'
vendor/gems/ss_photos/app/models/profile_photo.rb:23:in `content_type'
(eval):25:in `image_content_type'
activemodel (3.1.0.rc4) lib/active_model/validator.rb:151:in `block in validate'
@yorzi
yorzi / datetime_picker.js
Created July 22, 2011 01:34
a simple improvement on jqueryUI datepicker to enable the time setting.
$(document).ready(function(){
date_obj = new Date();
date_obj_hours = date_obj.getHours();
date_obj_mins = date_obj.getMinutes();
if (date_obj_mins < 10) { date_obj_mins = "0" + date_obj_mins; }
if (date_obj_hours > 11) {
date_obj_hours = date_obj_hours - 12;
date_obj_am_pm = " PM";
@yorzi
yorzi / sass.rb
Created August 3, 2011 02:32 — forked from denmarkin/sass.rb
Rails 3 initializer for Heroku/SASS setup
# see http://forrst.com/posts/Setting_up_SASS_on_Heroku-4dZ
# You can put this in config/initializers/sass.rb
# Setup directory in tmp/ to dump the generated css into
require "fileutils"
FileUtils.mkdir_p(Rails.root.join("tmp", "stylesheets", "generated"))
# Tell SASS to use the .sass files in public/stylesheets/sass and
# output the css to tmp/stylesheets/generated