Skip to content

Instantly share code, notes, and snippets.

View brianjriddle's full-sized avatar

Brian Riddle brianjriddle

View GitHub Profile
@brianjriddle
brianjriddle / citerus.rb
Created February 1, 2011 10:22
citerus utmaning for jfokus http://www.citerus.se/jfokus
input = "VOCDIITEIOCRUDOIANTOCSLOIOCVESTAIOCVOLIOCENTSU"
LONGEST = %r{TDD|DDD|ANT|IOC|LOC}
SHORTEST = %r{DI|DO|OO|UI|CV|SU|VO}
def compact!(string, times = 2)
[LONGEST, SHORTEST].cycle(times) do |regex|
string.gsub!(regex, "")
end
string
end
puts compact!(input)
@brianjriddle
brianjriddle / dynamic_class_include.rb
Created February 18, 2011 15:06
example of how to dynamically add java classes from a jar file to jruby
module CmsPolicies
java_import java.util.jar.JarFile
tv4_jar_file = JarFile.new(Polopoly::POLOPOLY_HOME + "/custom/client-lib/tv4.jar")
tv4_jar_file.entries.each do |entry|
if (entry.to_s =~ /.*(article|department|resource).*/ && entry.directory? )
include_package entry.to_s.gsub(/\/$/, '').gsub('/', '.')
end
end
end
@brianjriddle
brianjriddle / polopoly_colorizer.user.js
Created March 18, 2011 12:28
color indication of whether you are in produciton or stage environment
// ==UserScript==
// @name polopoly colorizer
// @match *://*/polopoly/*
// ==/UserScript==
if (document.URL.indexOf('userSession') > 0 || document.URL.indexOf('Login.jsp') > 0) {
if(document.URL.indexOf('stage') > 0 ) {
document.body.style.backgroundColor="#1E90FF";
document.body.style.color="white";
} else if(document.URL.indexOf('localhost')) {
//do nothing
@brianjriddle
brianjriddle / irb_session.rb
Created September 23, 2011 14:25
polopoly mbeans via jruby & jmx4r
jruby-1.6.4 :001 > require 'rubygems'
=> true
jruby-1.6.4 :002 > require 'jmx4r'
=> true
jruby-1.6.4 :003 > JMX::MBean.establish_connection :host => "localhost", :port => 10107
=> #<JMX::MBeanServerConnectionProxy:0x6063f5af @connection=#<#<Class:0x166bb1ead>:0x4c9d22fc>, @connector=#<Java::JavaxManagementRemoteRmi::RMIConnector:0x5ab6b2a5>>
jruby-1.6.4 :004 > polopoly_mbeans = JMX::MBean.find_all_by_name "com.polopoly:*"
=> [#<JMX::MBean:0x2e1ed620>, #<JMX::MBean:0x6a7be687>, #<JMX::MBean:0x6c5bdfae>, #<JMX::MBean:0x3ba5016>, #<JMX::MBean:0x3cdfd643>, #<JMX::MBean:0xb6be7ee>, #<JMX::MBean:0x5947c01d>, #<JMX::MBean:0x7595ddb5>, #<JMX::MBean:0x420ed262>, #<JMX::MBean:0x5b1641cf>, #<JMX::MBean:0x123aabc1>, #<JMX::MBean:0x49e21540>, #<JMX::MBean:0x19e142a5>, #<JMX::MBean:0x13de6be9>, #<JMX::MBean:0x6f7e982f>, #<JMX::MBean:0x60396ed8>, #<JMX::MBean:0x5a9c5842>, #<JMX::MBean:0x4e668387>, #<JMX::MBean:0x75787005>, #<JMX::MBean:0x36029483>, #<JMX::MBean:0x63644028>, #<JMX::MBean:0x4ab03512>, #<JMX::MBean:0x76
#if you have an directory with a .rvmrc in like
#/home/user/src/my_ruby_gem
#and are on the master brach
#this will create a gemset named
#my_ruby_gem-master
rvm --create ruby-1.9.2-p180@$(basename $(pwd)$(if [ -d .git ]; then echo "-$(git branch | grep '* '| sed -e 's/ //')"; fi))
#from 3.1
ModelAndViewResolverMethodReturnValueHandler
SimpleBeanFactoryAwareAspectInstanceFactory
SimpleRemoteStatelessSessionProxyFactoryBean
SingletonMetadataAwareAspectInstanceFactory
TransactionAwarePersistenceManagerFactoryProxy
UriComponentsBuilderMethodArgumentResolver
AbstractDependencyInjectionSpringContextTests
#from a clean install av rails 3.1.3
gems# egrep -ro "module (\w+)" . > ../blah
gems cat ../blah |awk '{print length, $0}'|sort -unr| head
42 NextNodeHeightIsDeterministicSharedContext
31 PalindromicFixtureSharedContext
27 AssociationBuilderExtension
26 BacktraceFilterForTestUnit
@brianjriddle
brianjriddle / ccs not cached
Created January 30, 2012 12:47
trulytherese
HTTP/1.1 200 OK
Date: Mon, 30 Jan 2012 12:45:58 GMT
Server: Apache/2.2.20 (FreeBSD) PHP/5.3.3 with Suhosin-Patch mod_ssl/2.2.20 OpenSSL/0.9.8q
Vary: Cookie
X-Powered-By: PHP/5.3.3
X-Pingback: http://trulytherese.se/xmlrpc.php
Connection: close
Transfer-Encoding: chunked
Content-Type: text/css
@brianjriddle
brianjriddle / file_count.rb
Created January 31, 2012 06:32
really simple and completely wrong loc statistics program
#!/usr/bin/ruby
file_map = {}
Dir["**/*.{rb,java,erb,js,html,css,jsp,xml}"].each do |path|
ext = File.extname(path)
if file_map.has_key? ext
current_count = file_map[ext]
count = current_count + File.open(path).readlines.size
file_map[ext] = count
else
file_map[ext] = File.open(path).readlines.size
@brianjriddle
brianjriddle / git-checkout-date.sh
Created January 31, 2012 06:36
git checkout source code to a specific date
git checkout "`git rev-list master -n 1 --first-parent --before=2008-03-02`"