Skip to content

Instantly share code, notes, and snippets.

View rballen's full-sized avatar

robert b. allen rballen

View GitHub Profile
@rballen
rballen / gist:3084572
Created July 10, 2012 16:46
css: shapes
/*!
* shapes
*/
#square {
width: 100px;
height: 100px;
background: red;
}
#rectangle {
@rballen
rballen / gist:3084585
Created July 10, 2012 16:47
bash: virtualbox debian
sudo apt-get update
sudo apt-get install build-essential module-assistant linux-headers-`uname -r`
sudo m-a prepare
sudo sh VBoxLinuxAdditions.run
@rballen
rballen / gist:3084624
Created July 10, 2012 16:49
javascript: jQuery pubsub
(function($){
var o = $( {} );
$.each({
on: 'subscribe',
trigger: 'publish',
off: 'unsubscribe'
}, function( key, api) {
$[api] = function() {
o[key].apply( o, arguments );
@rballen
rballen / gist:3084629
Created July 10, 2012 16:50
javascript: jQuery plugin for random element
$.fn.random = function() {
var rand = Math.floor( Math.random() * this.length + 1 );
return this[rand];
};
@rballen
rballen / gist:3084635
Created July 10, 2012 16:50
bash: sed slug removal
# slug to capitalized words i.e for_whom_the_bell_tolls --> For Whom The Bell Tools and the-old-man-and-the-sea --> The Old Man And The Sea
#
sed -e 's/^./\U&/' -e 's/_./\U&/g' -e 's/_/ /g' slugs.txt
sed -e 's/^./\U&/' -e 's/-./\U&/g' -e 's/-/ /g' slugs.txt
@rballen
rballen / gist:3084642
Created July 10, 2012 16:51
encoding: edit, crop, normalize, split, join and encode
asfbin-bin -i myvideo.wmv -start 00:00 -stop 05:23 -o my.edited.video.wmv
asfbin-bin -i myvideo.wmv -start 02:13 -stop 04:01 -start 08:05 -stop 09:51 -o my.edited.video.wmv
mp3gain -r *.mp3
@rballen
rballen / gist:3084671
Created July 10, 2012 16:54
java: sl4j logging
//http://www.slf4j.org/docs.html
//http://www.slf4j.org/faq.html#string_or_object
final Logger logger = LoggerFactory.getLogger(MyClass.class);
// use message format to add to log.
logger.debug("Set {1,2} differs from {}", "3"); = "Set {1,2} differs from 3"
logger.debug("Set {1,2} differs from {{}}", "3"); = "Set {1,2} differs from {3}".
logger.debug("{}", complexObject); = invokes toString on complexObject
@rballen
rballen / gist:3084716
Created July 10, 2012 17:01
java: joda time & date
/**
use joda time instead of java Date.
http://joda-time.sourceforge.net/
http://www.ibm.com/developerworks/java/library/j-jodatime.html
All methods should pass a DateTime object instead of Date. Spring will detect if joda is present on the classpath
and handle all converstions to DateTime automagically.
If you do have to pass a date formated string via url, query param, method signature etc, it should always be:
yyyy-MM-dd
@rballen
rballen / gist:3084724
Created July 10, 2012 17:02
java: spring date adapter for jaxb and json output
/**
* Returns the movie title's next airing date.
*
* @return the airing date
*/
@XmlJavaTypeAdapter(XmlAiringDateAdapter.class)
public Date getDate() {
return date;
}
// we can custom format the output by implementing our own adapter in spring
@rballen
rballen / gist:3084729
Created July 10, 2012 17:03
java: spring, content negotiation for REST api as of Spring MVC 3.0.2
<!-- VIEW RESOLVERS IN NESTED ORDER
Looks first at file type then mime type
When the extension is
- '.xml', it will delegate to JAXB Marshalling view
- '.rss', it will delegate to the InternalResourceViewResolver's JstlView
- '.html', it will delegate to the InternalResourceViewResolver's JstlView
- '.json', it will delegate to the MappingJacksonJsonView
Second, delegates to BeanNameViewResolve to find a bean id matching the returned View
Third, delegates to InternalResourceViewResolver and tries to find a matching jsp
-->