Skip to content

Instantly share code, notes, and snippets.

View joeRinehart's full-sized avatar

Joe Rinehart joeRinehart

  • Asheville, NC
View GitHub Profile
/*
See https://github.com/jquery-validation/jquery-validation/issues/379.
The maintainors of jQuery validate are OK validating whether or not 1,000,000 and 1.000.000 are numbers,
but aren't getting into parsing their values (because of international formats), so the min, max, and range
rules don't support anything formatted.
*/
$.validator.addMethod('min', function( value, element, param ) {
value = numeral(value).value();
return this.optional(element) || value >= param;
@joeRinehart
joeRinehart / thing.js
Created April 18, 2018 15:12
Why the heck is it always catching?!?! Oh...derp.
class Thing {
doStuffWithFile( file ) {
return new Promise( ( reject, resolve ) => {
/*
do shit...
*/
resolve(stuff)
})
}
}
@Grapes([
@Grab(group='org.apache.poi', module='poi', version='3.15'),
@Grab(group='org.apache.poi', module='poi-ooxml', version='3.15'),
])
import org.apache.poi.ss.usermodel.*
import org.apache.poi.xssf.usermodel.XSSFWorkbook
// input file: make sure we can read it
File inFile = new File('../input/contacts.xlsx')
@joeRinehart
joeRinehart / test-comparison.groovy
Last active December 5, 2017 16:55
Test in Groovy+Spock vs Java
def "Should return 200 when sending request to controller"() {
when:
ResponseEntity<Map> entity = testRestTemplate.getForEntity("http://localhost:" + this.port + "/hello-world", Map.class)
then:
entity.statusCode == HttpStatus.OK
}
@Test
void shouldReturn200WhenSendingRequestToController() {
.config(['$httpProvider', function($httpProvider) {
// Create a new definition for the httpProvider's factory function that allows us to intercept the
// $http service it creates
var originalFactoryFunction = $httpProvider.$get[ $httpProvider.$get.length - 1 ]
var newFactoryFunction = function($browser, $httpBackend, $$cookieReader, $cacheFactory, $rootScope, $q, $injector, $sce) {
var $http = originalFactoryFunction( $browser, $httpBackend, $$cookieReader, $cacheFactory, $rootScope, $q, $injector, $sce )
// Decorate the definition of .get()
@joeRinehart
joeRinehart / mbr-current-month.js
Last active March 29, 2017 12:21
MBR Calendar "Go to current month" on load
// get a reference to jQuery that shouldn't interfere with wordpressy bits
var ___safejQueryRef = ( $ == undefined ? jQuery : $ );
___safejQueryRef( function() {
// locally make all right with the universe, jQuerywise
var $ = ___safejQueryRef
// get tabs and panes
var tabs = $('.cherry-tabs-nav').children();
var panes = $('.cherry-tabs-pane');
/*
Adds a SQL-server specific callRows() method to Groovy Sql that functions like rows() against stored
procedures that perform DML before doing a select.
Essentially, it's just a set nocount on/off wrapper.
Usage:
sql.callRows(
"someProcName",
package com.boyzoid
class ScottsRoundRobiner {
static final DEFAULT_TEAM_COUNT = 7
static final DEFAULT_HOLE_COUNT = 9
List makeSchedule( List teams, Integer holeCount ) {
List schedule = []
// Checked against http://stackoverflow.com/questions/6648512/scheduling-algorithm-for-a-round-robin-tournament
def someKindaClassProcessorMap = [
(String) : new StringProcessor(),
(Date) : new DateProcessor()
]
@joeRinehart
joeRinehart / ErrorController.groovy
Created November 29, 2012 08:51
Grails Error Handling
import org.codehaus.groovy.grails.commons.GrailsApplication
import grails.util.GrailsUtil
class ErrorController {
def index() {
if ( GrailsApplication.ENV_PRODUCTION == GrailsUtil.environment ) {
// Production: show a nice error message
render(view:'production')
} else {