Skip to content

Instantly share code, notes, and snippets.

View amolpujari's full-sized avatar
💭
I may be slow to respond.

Amol amolpujari

💭
I may be slow to respond.
  • Pune
  • 13:59 (UTC +05:30)
View GitHub Profile
@amolpujari
amolpujari / custom_columns.rb
Created October 23, 2013 04:49
activeadmin tweaks
module ActiveAdmin
module Views
class IndexAsTable < ActiveAdmin::Component
def editable_text_column resource, attr
val = resource.send(attr)
val = "&nbsp;" if val.blank?
html = %{
<div id='editable_text_column_#{resource.id}'
class='editable_text_column'
@amolpujari
amolpujari / article.rb
Created October 23, 2013 04:50
activeadmin tweaks
ActiveAdmin.register Article do
index do
selectable_column
id_column
column :name, :sortable => :name do |resource|
editable_text_column resource, :name
end
column :article_type
column :created_at
column :updated_at
@amolpujari
amolpujari / active_admin.css.scss
Created October 23, 2013 04:54
activeadmin tweaks
input.editable_text_column {
background-color: #FBFF8C;
border: 1px none #FBFF8C;
box-shadow: 0 2px 19px #AAAAAA;
color: black;
display: none;
font-family: serif;
font-size: 1em;
font-style: italic;
@amolpujari
amolpujari / article.rb
Created October 23, 2013 05:09
activeadmin tweaks
ActiveAdmin.register Article do
index do
selectable_column
id_column
column :name, :sortable => :name do |resource|
editable_text_column resource, :name
end
column 'Type', :sortable => :article_type do |resource|
column_select(resource, :article_type, ["News", "Story", "Case Study", "Business"])
end
@amolpujari
amolpujari / custom_columns.rb
Created October 23, 2013 05:12
activeadmin tweaks
module ActiveAdmin
module Views
class IndexAsTable < ActiveAdmin::Component
include CustomHelper
def column_select resource, attr, list
val = resource.send(attr)
html = _select list, val, { "attrs" => %{
data-path='#{resource.class.name.tableize}'
@amolpujari
amolpujari / custom_helper.rb
Created October 23, 2013 05:15
my custom select helper
module CustomHelper
def _select set, selected, options={}
style = "margin:0;padding:0;#{options["style"]}"
selected = options["default"] if selected.blank?
cache = options["cache"] || nil
id = options["id"] || nil
id ||= "ch#{ch_uniq_id}" unless cache.blank?
@amolpujari
amolpujari / active_admin.js
Created October 23, 2013 05:19
activeadmin tweaks
var admin = {
init: function(){
admin.set_admin_selectable_events();
},
set_admin_selectable_events: function(){
$("select.admin-selectable").live("change", function(e){
var path = $( e.currentTarget ).attr("data-path");
@amolpujari
amolpujari / thread_pool.rb
Last active August 7, 2020 06:38
smallest thread pool in ruby
class ThreadPool
attr_accessor :threads, :max_size, :wait_time_to_free, :name
def initialize max_size=4
@max_size = max_size
@threads = []
@wait_time_to_free = 0.1
end
def start *args, &block
@amolpujari
amolpujari / admin.lightbox.js.coffee
Created December 19, 2013 10:41
admin.lightbox.js.coffee
window.admin ||= {}
$.extend window.admin,
lightbox:
show: (options) ->
options = {} unless options
buttonDone = options.buttonDone or "Done"
buttonCancel = options.buttonCancel or "Cancel"
focus = options.focus or "input"
@amolpujari
amolpujari / admin.lightbox.css.scss
Created December 19, 2013 10:50
admin.lightbox.css.scss
body.active_admin #modal_shadow{
z-index: 999998;
position:fixed;
top: 0px; left: 0px;
height:100%; width: 100%;
background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQIW2NsampKAwAFAgHu04pC4AAAAABJRU5ErkJggg==) repeat;
display:none;
padding: 0; margin: 0;
}