Skip to content

Instantly share code, notes, and snippets.

@ivarconr
ivarconr / gist:3878454
Created October 12, 2012 09:52
Start embedded Jetty 8 with web-context
//jetty.version 8.1.7.v20120910
public static void main(String[] args) throws Exception {
Server server = new Server(3000);
WebAppContext context = new WebAppContext();
context.setDescriptor(context+"/WEB-INF/web.xml");
context.setResourceBase("./src/main/webapp");
context.setContextPath("/");
context.setParentLoaderPriority(true);
/**
* Given we have a regex with one more matching groups.
* The regex should capture those groups from an 'input'
* string and replace the matched values in an 'template'
* string.
*
* Example:
* regex: /([1-9]{8})/([1-9]{8})?/
* input string: '/some-magic/path/12122211/22112211'
* template string: 'http://someurl?adId=$1&adId=$2'
'use strict';
function start () {
const startTime = process.hrtime();
return () => {
const elapsed = process.hrtime(startTime);
return elapsed[0] * 1e9 + elapsed[1];
};
}
const {User, AuthenticationRequired) = require('unleash-server');
const passport = require('passport');
const GoogleOAuth2Strategy = require('passport-google-auth').Strategy;
passport.use(
new GoogleOAuth2Strategy(
{
clientId: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
'use strict';
const auth = require('basic-auth');
const User = require('../user');
function basicAuthentication(app) {
app.use('/api/admin/', (req, res, next) => {
const credentials = auth(req);
if (credentials) {
// Create and add EventListner
const func = ev => {console.log(ev.detail)};
const listner = window.addEventListener('demo', func);
// Publish custom event
const event = new CustomEvent('demo', {detail: 'hello world'});
window.dispatchEvent(event);
// Remove EventListner
@ivarconr
ivarconr / podlet-xhr.js
Last active October 8, 2018 18:15
show-interest
const xhrBase = document.getElementById("showInterest").getAttribute('data-xhr-path');
const adId = document.getElementById("showInterest").getAttribute('data-ad-id');
fetch(`${xhrBase}save?adId=${adId}`).then(() => console.log('fetch'));
const http = require('http');
const fetch = require('node-fetch');
const async_hooks = require('async_hooks');
const context = new Map();
const middleware = (req, res) => {
const id = async_hooks.executionAsyncId();
const headers = req.headers;
context.set(id, headers);
const async_hooks = require('async_hooks');
const fs = require('fs');
const http = require('http');
const fetch = require('node-fetch');
const asyncHook = async_hooks.createHook({
init: (asyncId, type, triggerAsyncId, resource) => {
if(type === 'TCPCONNECTWRAP') {
process.nextTick(() => {
console.log('TCPCONNECTWRAP');
var unleashContext = {};
var fallbackVariant = {
enabled: false,
name: "disabled",
}
const varinat = getVariant('toggleName', unleashContext, fallbackVariant);
switch(variant.name) {