Skip to content

Instantly share code, notes, and snippets.

Pavel Vlasov pvlasov

Block or report user

Report or block pvlasov

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@pvlasov
pvlasov / AesEncryptionDecryption.java
Created Nov 7, 2019
An example of AES encryption and decryption in Java
View AesEncryptionDecryption.java
// --- Encryption ---
// Init cipher
String encryptionKey = ...;
MessageDigest md = MessageDigest.getInstance("SHA-256");
md.update(encryptionKey.getBytes(StandardCharsets.UTF_8));
byte[] digest = md.digest();
SecretKey secretKey = new SecretKeySpec(Arrays.copyOf(digest, 16), "AES");
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING");
String ivStr = ...; // Shared string or unencrypted part of message, or empty string.
IvParameterSpec iv = new IvParameterSpec(Arrays.copyOf(ivStr.getBytes(StandardCharsets.UTF_8), 16));
@pvlasov
pvlasov / PicoCliQuickStart.java
Created Nov 4, 2019
Shows basic usage of a command hierarchy in PicoCli
View PicoCliQuickStart.java
import java.util.concurrent.Callable;
import picocli.CommandLine;
import picocli.CommandLine.Command;
import picocli.CommandLine.IVersionProvider;
import picocli.CommandLine.Model.CommandSpec;
import picocli.CommandLine.ParameterException;
import picocli.CommandLine.Spec;
public class PicoCliTest {
@pvlasov
pvlasov / QrCodec.java
Last active Nov 4, 2019
Shows how to use Zxing to write/read QR codes
View QrCodec.java
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.Base64;
import java.util.Random;
import javax.imageio.ImageIO;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.BinaryBitmap;
import com.google.zxing.LuminanceSource;
@pvlasov
pvlasov / ereference-item-provider.java
Created Oct 27, 2019
Shows how to use EReferenceItemProvider to create tree nodes (folders) for EReferences
View ereference-item-provider.java
@Override
public Collection<?> getChildren(Object object) {
List<EReferenceItemProvider> children = eReferenceItemProviders.get(object);
if (children == null) {
children = new ArrayList<>();
eReferenceItemProviders.put(object, children);
children.add(new EReferenceItemProvider(this, (EObject) object, AppPackage.Literals.CONTAINER__ELEMENTS));
children.add(new EReferenceItemProvider(this, (EObject) object, AppPackage.Literals.ABSTRACT_ACTION__ACTION_MAPPINGS));
children.add(new EReferenceItemProvider(this, (EObject) object, AppPackage.Literals.ACTION_BASE__CONTENT));
}
@pvlasov
pvlasov / Item-property-descriptor.java
Last active Oct 27, 2019
Shows how to use NasdanikaItemProvider.createItemPropertyDescriptor method
View Item-property-descriptor.java
/**
* This adds a property descriptor for the Color feature.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated NOT
*/
protected void addColorPropertyDescriptor(Object object) {
itemPropertyDescriptors.add
(createItemPropertyDescriptor
(getResourceLocator(),
@pvlasov
pvlasov / jGit.md
Last active Sep 16, 2019
Working with jGit
View jGit.md

Maven dependency

<dependency>
  <groupId>org.eclipse.jgit</groupId>
  <artifactId>org.eclipse.jgit</artifactId>
  <version>5.4.2.201908231537-r</version>
</dependency>

Resources

@pvlasov
pvlasov / editorcustomization.java
Last active Jul 29, 2019
Shows how to replace object selection dialog in a reference property editor
View editorcustomization.java
/**
* @generated NOT
*/
protected void addXXXPropertyDescriptor(Object object) {
EMFEditUIPropertyEditorFactory editorFactory = new EMFEditUIPropertyEditorFactory(null) {
@Override
public CellEditor createEditor(Object object, IItemPropertyDescriptor propertyDescriptor, Composite composite) {
ILabelProvider labelProvider = new org.eclipse.emf.edit.ui.provider.PropertyDescriptor(object, propertyDescriptor).getLabelProvider();
@pvlasov
pvlasov / generate-sirius-diagram-images-with-maps.md
Last active Jul 18, 2019
Headless generation of diagram images from Sirius representations (.aird) with image maps
View generate-sirius-diagram-images-with-maps.md
@pvlasov
pvlasov / constraint.ecore
Created Apr 23, 2019
Ecore constraint annotation for generation of validation methods
View constraint.ecore
<eAnnotations source="http://www.eclipse.org/emf/2002/Ecore">
<details key="constraints" value="nonNegativeBalance"/>
</eAnnotations>
@pvlasov
pvlasov / clear-targets.bat
Created Jan 8, 2019
Recursively remove target directories in multiple Maven projects
View clear-targets.bat
for /f %i in ('dir /a:d /s /b target') do rd /s /q %i
You can’t perform that action at this time.