Skip to content

Instantly share code, notes, and snippets.

Vijay Dev vijaydev

Block or report user

Report or block vijaydev

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 users_controller.rb
@user.allotments.map &:destroy # delete old allotments
# format: [ ['role', 'human-role', [1,2,3]], ['role', 'human-role', [1,2,3]] ] defined in user model.
allots = []
params[:roles_divisions].each do |rd|
rd[2].each do |d|
allots << Allotment.create(:user_id => @user.id, :division_id => d.to_i, :role_name => rd[0])
end
end
View process.rb
def pie_to(val, r)
rads = (val*3.60) * Math::PI / 180 # 360 deg of val % in radians
sr = (r * Math.sin(rads)).to_i
cr = (r * Math.cos(rads)).to_i
arc = val <= 50 ? 0 : 1
[sr, r-cr, arc]
end
View mime_responds.rb
# Respond to also allows you to specify a common block for different formats by using any:
#
# def index
# @people = Person.all
#
# respond_to do |format|
# format.html
# format.any(:xml, :json) { render request.format.to_sym => @people }
# end
# end
View schools_controller.rb
if uploaded_file.instance_of?(Tempfile)
FileUtils.copy(uploaded_file.local_path, path_to_file)
else
File.open(path_to_file, "wb") { |f| f.write(uploaded_file.read) }
end
View gist:1038004
> 5000.times do |i|
| a[i] = i
| end
> a.symbolize_keys.reject { |k,v| k.class == Fixnum }.sort { |x,y| x[1] <=> y[1] }
=> [[:"!", 33], [:, 37], [:, 38], [:, 42], [:, 43], [:-, 45], [:, 47], [:, 60], [:, 62], [:, 94], [:, 96], [:, 124], [:, 126], [:, 317], [:-, 318], [:, 319], [:=>, 320], [:, 321], [:, 322], [:"!=", 323], [:, 324], [:, 325], [:, 328], [:"!~", 329], [:"..", 330], [:"...", 331], [:[], 332], [:[], 333], [:, 334], [:, 335], [:"::", 336], [:__autoload__, 2881], [:__autoload__, 2884], [:__classpath__, 2889], [:__classpath__, 2892], [:__tmp_classpath__, 2897], [:__tmp_classpath__, 2900], [:"Object=", 2908], [:Object, 2909], [:__classid__, 2913], [:__classid__, 2916], [:"Module=", 2924], [:Module, 2925], [:"Class=", 2932], [:Class, 2933], [:__attached__, 2937], [:__attached__, 2940], [:"Kernel=", 2948], [:Kernel, 2949], [:allocate, 2953], [:allocate, 2956], [:initialize, 2961], [:initialize, 2964], [:inherited, 2969], [:inherited, 2972], [:initialize_copy, 2977], [:initialize_copy, 2980], [:include
View gist:1078542
# h = ActiveSupport::OrderedOptions.new
# h.boy = 'John'
# h.girl = 'Mary'
# h.boy # => 'John'
# h.girl # => 'Mary'
View filter.js
$('div.news .pagination a').click(function() {
setTimeout(function() { Ghf.run(); }, 2000);
});
View gist:1183606
pdf, err = Open3.popen3(command) do |stdin, stdout, stderr|
#stdin.binmode
#stdout.binmode
#stderr.binmode
stdin.write(File.read('pdf_string.xhtml'))
stdin.close
[stdout.read, stderr.read]
end
View gist:1184309
Reduced Functionality:
This version of wkhtmltopdf has been compiled against a version of QT without
the wkhtmltopdf patches. Therefore some features are missing, if you need
these features please use the static version.
Currently the list of features only supported with patch QT includes:
* Printing more then one HTML document into a PDF file.
* Running without an X11 server.
* Adding a document outline to the PDF file.
View deploy.rb
desc "Make sure there is something to deploy"
task :check_revision, :roles => :web do
unless `git rev-parse HEAD` == `git rev-parse origin/production`
puts "WARNING: HEAD is not the same as origin/production"
puts "Run `git push` to sync changes."
exit
end
end
You can’t perform that action at this time.