Skip to content

Instantly share code, notes, and snippets.

View jeantessier's full-sized avatar

Jean Tessier jeantessier

View GitHub Profile
@jeantessier
jeantessier / CopyMatcher.groovy
Last active August 29, 2015 14:03
Example of stripped down notation for Groovy, compared to Java.
import org.apache.commons.lang.StringUtils
class CopyMatcher {
def triggerWord
def matches(product) {
product.productCopy.any { StringUtils.containsIgnoreCase it.copy, triggerWord }
}
@jeantessier
jeantessier / Histogram.groovy
Created October 21, 2014 05:11
Building a histogram from a Grails criteria search.
Employee.withCriteria {
projections {
groupProperty "gender"
rowCount()
}
}.inject([:]) { histo, row ->
histo[row[0]] = row[1]
histo
}
@jeantessier
jeantessier / User.groovy
Last active September 5, 2015 22:57
Replace complicated Java microservice with trivial Grails 3 app.
package springpack.model
import grails.rest.*
@Resource(uri='/users', formats=['json', 'xml'])
class User {
String username
String email
@jeantessier
jeantessier / handler.groovy
Created January 19, 2017 07:29
A listener class has a series of handlers, each with a `match` and a `handle` closure. Each closure has an optional `origin` parameter.
handlers.findAll { name, handler ->
if (handler.match.maximumNumberOfParameters == 1) {
handler.match notification
} else {
handler.match notification, origin
}
}.each { name, handler ->
if (handler.handle.maximumNumberOfParameters == 1) {
handler.handle notification
} else {
@jeantessier
jeantessier / gitpull.cgi
Last active January 30, 2019 23:10
This CGI script in Perl can be the target of a GitHub webhook to automatically pull the latest version from the repo.
#!/usr/bin/perl
use Digest::SHA qw(hmac_sha1_hex);
open(KEYFILE, "gitpull.secret");
chomp($secret = <KEYFILE>);
close(KEYFILE);
print "Content-type: text/plain\n";
print "\n";
@jeantessier
jeantessier / some_class_under_test.rb
Last active April 24, 2020 21:01
Data-Driven tests in RSpec
class SomeClassUnderTest
def some_method_under_test(input)
input.to_s
end
end
@jeantessier
jeantessier / rspec_template.rb
Last active January 2, 2024 07:48
Rails [Application Template](https://guides.rubyonrails.org/rails_application_templates.html) to add RSpec as the testing framework
#
# To use this temlate, which sets RSpec as the testing framework:
#
# rails new my-app --skip-test -m ~/rspec_template.rb
#
gem_group :development, :test do
gem "rspec-rails"
end