Skip to content

Instantly share code, notes, and snippets.

View augustl's full-sized avatar

August Lilleaas augustl

  • Oslo, Norway
View GitHub Profile
var items = mori.vector(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
var acc = 0;
var changedItems = mori.map(function (item) {
acc += item;
return item + acc;
}, items);
console.log(mori.toJs(mori.take(3, changedItems)));
@augustl
augustl / retry.js
Created September 4, 2015 21:52
retry
function retryIter(f, promise, n) {
return promise.then(
function (res) {
return res;
},
function (err) {
if (n === 0) {
return $q.reject(err);
} else {
return retryIter(f, f(), n - 1);
// Example of behaviour of CGLIB spring wrapped Grails services.
// The default behaviour of a plain class is `static transactional = true`, a backwards compatible
// default that creates a CGLIB spring wrapped bean.
// When generating services with "grails create-service", it will be annotated with
// @grails.transaction.Transactional and have different behaviour.
class MyAService() {
@augustl
augustl / client.js
Last active August 29, 2015 14:25
CometD for servlet setup
var fayeClient = new Faye.Client("/cometd");
fayeClient.publish("/client_info", {username: APP_CONFIG.currentUserUsername, userAgent: navigator.userAgent});
fayeClient.subscribe("/active_statuses", function (data) {
// ...
});
def init = { ServletContext servletContext ->
String cometdUrlMapping = "/cometd/*"
// This is the only way to let CometDServlet know about our bayeux instance
servletContext.setAttribute(BayeuxServer.ATTRIBUTE, bayeux)
bayeux.setOption("javax.servlet.ServletContext", servletContext)
bayeux.setOption("ws.cometdURLMapping", cometdUrlMapping)
CometDServlet cometDServlet = new CometDServlet()
ServletRegistration cometDServletRegistration = servletContext.addServlet("cometd", cometDServlet)
cometDServletRegistration.setLoadOnStartup(1)
function isDesktop(msg) {
return /^[a-z]/.test(msg)
}
function isMobile(msg) {
return /^[A-Z]/.test(msg)
}
var stopSlices = mori.pipeline(appState
function (it) { return mori.getIn(it, measureCursor.concat(["selectedStops"]))},
mori.keys,
mori.sort,
function (it) { return mori.interleave(it, it); },
function (it) { return mori.take((mori.count(it) * 2) - 1, it); },
function (it) { return mori.into(mori.vector(0), it); },
function (it) { return mori.partition(2, it); });
import javax.servlet.annotation.WebListener
import javax.servlet.ServletContextListener
import javax.servlet.ServletContextEvent
import org.springframework.web.context.support.GenericWebApplicationContext
import org.springframework.web.servlet.DispatcherServlet
@WebListener
class BootstrapWebApp implements ServletContextListener {
// This is the "programmatic web.xml" of the servlet 3.0 spec. This is annotation driven and
CREATE TABLE STRETCH_STOP (
id number(19, 0),
jbv_id varchar2(15 char),
parent_stop_id number(19, 0),
duration number(10, 0),
note varchar2(4000 char)
);
CREATE TABLE PLAN (
class MyService {
private final ThreadPoolExecutor myExecutor = new ThreadPoolExecutor(
1, 1,
0L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<Runnable>())
Map valueCache = [:]
def getCachedValue() {
myExecutor.submit({