Skip to content

Instantly share code, notes, and snippets.

View pvlasov's full-sized avatar

Pavel Vlasov pvlasov

View GitHub Profile
@pvlasov
pvlasov / httpd.conf
Created January 27, 2016 15:56
Apache configuration for NTLM authentication with mod_authn_ntlm and forwarding remote user name in a header to a proxied, say, servlet container
# Required modules
LoadModule proxy_module modules/mod_proxy.so
# Maybe this one is not needed
LoadModule proxy_html_module modules/mod_proxy_html.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule auth_ntlm_module modules/mod_authn_ntlm.so
... Skipped ... (or "Elided" for fancy folks)
@pvlasov
pvlasov / cdo.xcore
Last active February 21, 2016 03:05
GenModel configuration for XCore to generate CDO models and retain GenModel annotations (documentation)
@GenModel(
suppressGenModelAnnotations="false",
featureDelegation="Reflective",
modelPluginVariables="org.eclipse.xtext.xbase.lib org.eclipse.emf.ecore.xcore.lib CDO=org.eclipse.emf.cdo",
rootExtendsClass="org.eclipse.emf.internal.cdo.CDOObjectImpl",
rootExtendsInterface="org.eclipse.emf.cdo.CDOObject"
)
@pvlasov
pvlasov / user.js
Last active February 25, 2016 16:51
Extension for the DokuWiki Vector template to make the TOC remain visible when page scrolls. Put this file to the user directory of the Vector template and enable loading of user.js in the Configuration panel
jQuery(document).ready(function () {
var tocSelector = "#dw__toc";
var top = jQuery(tocSelector).offset().top - parseFloat(jQuery(tocSelector).css('marginTop').replace(/auto/, 0));
jQuery(window).scroll(function (event) {
// what the y position of the scroll is
var y = jQuery(this).scrollTop();
var toc = jQuery(tocSelector);
if (y >= top) {
// if so, ad the fixed class
@pvlasov
pvlasov / MultiPart.java
Created March 30, 2016 13:02
Code to enable multi-part request processing in Jetty in Equinox - adding multi-part config attribute to the request
if (request.getAttribute(org.eclipse.jetty.server.Request.__MULTIPART_CONFIG_ELEMENT) == null) {
request.setAttribute(org.eclipse.jetty.server.Request.__MULTIPART_CONFIG_ELEMENT, org.eclipse.jetty.util.MultiPartInputStreamParser.__DEFAULT_MULTIPART_CONFIG);
}
@pvlasov
pvlasov / MergingGenerator.java
Created November 14, 2016 01:34
Shows how use JMerger to merge generated and hand-crafted code
// --- Imports ---
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IWorkspace;
@pvlasov
pvlasov / ASTRewriter.java
Last active November 16, 2016 15:57
Shows how to rewrite Java source code
ICompilationUnit compilationUnit = null; // TODO - initialize
ICoreRunnable rewriteRunnable = new ICoreRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
// TODO - create sub-monitors for different steps.
ICompilationUnit workingCopy = compilationUnit.getWorkingCopy(monitor);
try {
@pvlasov
pvlasov / EcoreXMI.java
Last active December 14, 2016 15:39
Loading/Storing Ecore model to/from XMI file
// Dependencies: org.eclipse.emf.ecore, org.eclipse.emf.ecore.xmi
// Create a resource set to hold the resources.
// Create resource set or use existing
ResourceSet resourceSet = new ResourceSetImpl();
// Register the appropriate resource factory to handle all file extensions.
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl());
// Register the package to ensure it is available during loading.
@pvlasov
pvlasov / ssl.md
Last active January 24, 2017 20:07
Key points for working with SSL

Generation of certificate with Apache's OpenSSL

Root CA generation

openssl genrsa -des3 -out rootCA.key 2048
openssl req -x509 -new -nodes -key rootCA.key -sha256 -days 1024 -out rootCA.pem

Importing certificates

@pvlasov
pvlasov / DiagnosticHelper.java
Last active April 22, 2019 14:40
Helper class for EObject validations.
import java.util.ArrayList;
import java.util.List;
import org.eclipse.emf.common.util.BasicDiagnostic;
import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.common.util.DiagnosticChain;
import org.eclipse.emf.ecore.EStructuralFeature;
/**
* Helper class to reduce amount of diagnostic/validation code.
@pvlasov
pvlasov / guestGetIndexHtml.java
Created March 29, 2017 02:48
Guest getIndexHtml() method processing login
@RouteMethod(
path="index.html",
value = { RequestMethod.GET, RequestMethod.POST },
lock = @RouteMethod.Lock(type = Type.READ, path = ".."),
comment="Renders login form on GET, processes it on POST")
public Object indexHtml(
@ContextParameter CDOTransactionHttpServletRequestContext<LoginPasswordCredentials> context,
@TargetParameter Guest target,
@QueryParameter("url") String returnURL,
@QueryParameter("login") String login,