Skip to content

Instantly share code, notes, and snippets.

View vijedi's full-sized avatar

Tejus Parikh vijedi

View GitHub Profile
@vijedi
vijedi / active_admin_sorting_tables.rb
Created October 11, 2012 02:52
Active Admin Sorting Tables
content do
order = case(params[:order])
when 'user_email_desc'
'email DESC'
when 'user_email_asc'
'email ASC'
else
nil
end
@vijedi
vijedi / additions_to_table_for.rb
Created October 11, 2012 02:54
Additions to table_for
table_for users, {:sortable => true, :class => 'index_table'} do
...
end
@vijedi
vijedi / active_admin_sortable_column.rb
Created October 11, 2012 02:57
Active Admin Sortable Column
column('Email', :sortable => :user_email) {|user| user.email}
@vijedi
vijedi / active_admin_handling_sort_param.rb
Created October 11, 2012 03:00
Active Admin Handling Sort Param
order = case(params[:order])
when 'user_email_desc'
'email DESC'
when 'user_email_asc'
'email ASC'
else
nil
end
@vijedi
vijedi / gist:3880535
Created October 12, 2012 17:55
Force Less CSS into development mode.
<!-- The following lines force less into development mode -->
<script type="text/javascript">
var less = { env: 'development'};
</script>
<link rel="stylesheet/less" type="text/css" href="/less/bootstrap.less" >
<link rel="stylesheet/less" type="text/css" href="/less/responsive.less" >
<%= javascript_include_tag 'less-1.2.2.min' %>
@vijedi
vijedi / rails_migration_with_couchrest.sh
Created November 2, 2012 14:08
Generating a rails migration with couchrest
rails g migration migrationname --orm=active_record
@vijedi
vijedi / base_controller.rb
Created November 8, 2014 15:14
Pagination with angular-paginate-anything and kaminari
class Api::BaseController < ApplicationController
include Rivalry::OrganizationScope
respond_to :json
private
def self.paginated_action(options = {})
before_filter(options) do |controller|
if request.headers['Range-Unit'] == 'items' &&
request.headers['Range'].present?
@vijedi
vijedi / sentence_util.rb
Created November 26, 2014 03:41
Algorithm for comparing sentences
module ViJedi::SentenceUtil
SIMILARITY_PERCENTAGE = 0.4
# boolean check to see if the source and prime sentences are the same
def self.similar(source, prime)
return compute_values(source, prime)[:mismatch_percentage] < SIMILARITY_PERCENTAGE
end
# returns the word difference between the source and prime
def self.word_distance(source, prime)
@vijedi
vijedi / ng-show.html
Last active March 15, 2016 20:32
Code that showed the correct thing in the directive
<!-- has_alerts is true and view_opts.state is set to 'expired' -->
<div id='BriefAlert' class='alert alert-info' ng-show='has_alerts'>
<span ng-switch='view_opts.state'>
<span ng-switch-when='expired'>This thing was expired</span>
<span ng-switch-when='reassigend'>This thing was reassigned to someone else</span>
<span ng-switch-when='view_only'>You can only view this thing</span>
</span>
</div>
@vijedi
vijedi / ng-if.html
Last active March 15, 2016 20:40
Code that renders nothing witin the alert box
<!-- has_alerts is true and view_opts.state is set to 'expired' -->
<div id='BriefAlert' class='alert alert-info' ng-if='has_alerts'>
<span ng-switch='view_opts.state'>
<span ng-switch-when='expired'>Brief closed -- Not completed before expiration date</span>
<span ng-switch-when='reassigend'>Brief closed -- Reassignment of {{reassignmentPhrase()}}</span>
<span ng-switch-when='view_only'>You only have permissions to view the questions of this brief</span>
</span>
</div>