Skip to content

Instantly share code, notes, and snippets.

View swanandp's full-sized avatar
🖥️

Swanand Pagnis swanandp

🖥️
View GitHub Profile
module M
def test
puts "test"
end
end
class X
include M
def test
puts "instance"
@swanandp
swanandp / acts_as_list_position_test.rb
Created June 10, 2011 12:11
One issue on acts_as_list said that first.first? and first.last? both returned true
7.times do
ListMixin.create!
end
assert ListMixin.first.first?
assert ListMixin.last.last?
assert !ListMixin.last.first?
assert !ListMixin.first.last?
@swanandp
swanandp / regexp_blank_line_match.rb
Created July 15, 2011 07:35
Regular Expression to remove Blank Lines, but keep indentation on other lines
# Regular expression for removing blank lines from a text:
#Replace this regex
/(\s+)^\r?\n?$(\s+)/mix
# With
$2 # The second match
@swanandp
swanandp / authlogic_config_example.rb
Created August 4, 2011 13:17
Shows off a few samples for acts_as_authentic configuration
class User < ActiveRecord::Base
# gradual engagement is needed, to allow admin creation of users
# users should create authorization data only when they need to
# access some system feature that requires authentication
# So ... our gradual engagement scheme for authlogic:
# 1. admin creates user, setting only name and phone number (required)
# admin may set email address (optional)
# 2. user is sent email invitation with link to activate their account
# admin can re-send email at user's request
# 3. user sets login and password/password_confirmation using activation form
@swanandp
swanandp / swanand_rmagick_outputter.rb
Created January 13, 2012 18:10
An ugly extension to add text underneath the barcode image generated by Barby
module Barby
class SwanandRmagickOutputter < RmagickOutputter
register :to_jpg_2
def to_jpg_2(*a)
to_blob('jpg', *a)
end
#Returns a string containing a JPEG image
def to_blob(format, *a)
2012-03-29T10:25:10+00:00 app[app.1]: #bangalore-ruby <keyword> tweet - Returns a link to a tweet about <keyword>
2012-03-29T10:25:10+00:00 app[app.1]: <travis me> sferik/rails_admin - Returns the build status of https://github.com/sferik/rails_admin
2012-03-29T10:25:10+00:00 app[app.1]: <user> is a badass guitarist - assign a role to a user
2012-03-29T10:25:10+00:00 app[app.1]: <user> is not a badass guitarist - remove a role from a user
2012-03-29T10:25:10+00:00 app[app.1]: Find the build status of an open-source project on Travis
2012-03-29T10:25:10+00:00 app[app.1]: animate me <query> - The same thing as `image me`, except adds a few
2012-03-29T10:25:10+00:00 app[app.1]: convert me <expression> to <units> - Convert expression to given units.
2012-03-29T10:25:10+00:00 app[app.1]: help <query> - Displays all help commands that match <query>.
2012-03-29T10:25:1
0+00:00 app[app.1]: help - Displays all of the help commands that bangalorehubot knows about.
module HookMethodMissing
def method_missing(name, *args, &block)
puts name
super
end
end
class A
extend HookMethodMissing
end
@swanandp
swanandp / console.rake
Created April 28, 2014 07:38
Rake task to load up your gem in a pry repl
desc "Open an irb (or pry) session preloaded with this gem"
task :console do
begin
require 'pry'
gem_name = File.basename(Dir.pwd)
sh %{pry -I lib -r #{gem_name}.rb}
rescue LoadError => _
sh %{irb -rubygems -I lib -r #{gem_name}.rb}
end
end
javax.servlet.jsp.JspException: No bean found for attribute key WelcomeNote
at org.apache.struts.taglib.template.InsertTag.doEndTag(InsertTag.java:133)
at booking._0002fbooking_0002fplanner_0002ejspplanner_jsp_0._jspService(_0002fbooking_0002fplanner_0002ejspplanner_jsp_0.java:937)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:126)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.runtime.JspServlet$JspServletWrapper.service(JspServlet.java:174)
at org.apache.jasper.runtime.JspServlet.serviceJspFile(JspServlet.java:274)
at org.apache.jasper.runtime.JspServlet.service(JspServlet.java:387)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.broadvision.servlet.ServletContainer.service(ServletContainer.java:415)
@swanandp
swanandp / sequs_112.clj
Last active August 29, 2015 14:07
4Clojure 112 Sequs Horribilis
(ns fourclojure.sequs-112)
;; https://www.4clojure.com/problem/112
(declare sequs reducer)
(defn flatsum [v] (apply + (flatten v)))
(defn present? [_ el] (seq el))