Skip to content

Instantly share code, notes, and snippets.

@apraditya
apraditya / regroup_gems
Last active August 6, 2021 09:58
Regroup outdated gems into major, minor & patch verions. Run `bundle outdated | regroup_gems`
#!/usr/bin/env ruby
outdated_gems = ARGF.read
hash = { major: [], minor: [], patch: [] }
group_hash = {}
outdated_gems.split("\r").each do |line|
line.delete!("\n")
gem_name, installed, newest, _requested, group_name = line.split(/\s{2,}/)
if gem_name.nil? || gem_name == 'Gem' || newest.nil? || newest.scan(/\./).empty?
{
"app/lib/publishers/*.rb": {
"command": "publisher",
"template": "class %S\nend"
},
"app/lib/listeners/*.rb": {
"command": "listener",
"template": "class %S\nend"
},
"app/resources/*_resource.rb": {
@apraditya
apraditya / components.css.scss
Created October 2, 2014 03:23
Display checkboxes by splitting into 3 columns in a Bootstrap vertical form using simple_form gem
// app/assets/stylesheets/components.css.scss
label.label-block {
display: block;
}
.checkboxes_in_column {
@extend .row;
span.checkbox {
@apraditya
apraditya / facebook_test_user.rb
Created December 12, 2012 16:29
A simple ruby script to generate Facebook [Test Users](https://developers.facebook.com/docs/test_users/).
require 'open-uri'
require 'json'
app_id = 'YOUR_FACEBOOK_APP_ID'
app_secret = 'YOUR_FACEBOOK_APP_SECRET'
full_name = 'John Smith'
token_request_url = "https://graph.facebook.com/oauth/access_token?client_id=#{app_id}"
token_request_url += "&client_secret=#{app_secret}&grant_type=client_credentials"
module OpengraphMethods
def og_site_name
"the site name"
end
#def og_title
# opengraph_from_method [:title, :full_name], use_postfix: true
#end
def og_description
class User < ActiveRecord::Base
include OpengraphMethods
def opengraph_title
opengraph_site_name # doesn't create the meta entry
# These don't create as well
send(:opengraph_site_name)
send(:opengraph_site_name).to_s
'this one works'
@apraditya
apraditya / Gemfile.lock
Created September 17, 2012 07:00
This email layout and sass files can be used to reproduce this issue https://github.com/Mange/roadie/issues/14
GIT
remote: git://github.com/radar/forem.git
revision: 515839e73bccbcb2f228e23082538bc86e7114fc
ref: 515839e73b
specs:
forem (1.0.0.beta1)
cancan
forem-redcarpet (= 1.0.0)
rails (~> 3.1)
simple_form
@apraditya
apraditya / users_factory.rb
Created May 25, 2012 04:40
factory definition
Factory.define :user do |u|
u.password 'password'
u.password_confirmation { |u| u.password }
u.confirmation_sent_at Time.new
u.confirmed_at Time.new
u.location 'US'
end
Factory.define :admin, :parent => :user do |admin|
admin.sequence(:name) { |n| "Admin #{n}" }
Failure/Error: @rateable_object = Fabricate :script
AWS::S3::Errors::AccessDenied:
Access Denied
# (eval):3:in `create_bucket'
# ./spec/models/user_spec.rb:140:in `block (5 levels) in <top (required)>'