Skip to content

Instantly share code, notes, and snippets.

@xnopre
xnopre / MockFileList.ts
Last active August 7, 2019 07:10
Une classe MockFileList pour mocker une FileList dans les tests unitaires (avec TypeScript)
export class MockFileList implements FileList {
[index: number]: File;
length: number;
private files: File[];
constructor(files: File[]) {
this.files = files;
this.length = files.length;
for (let i = 0; i < files.length; i++) {
@xnopre
xnopre / pre-commit
Last active May 10, 2017 10:58
Git hook to prevent acciental commits on branch 'master' (or other)
#!/bin/bash
# Prevent accidental commits to 'master' branch. https://gist.github.com/xnopre/a30946cbacf9d857db6192cb45c860f1
# Commit with -n to bypass this pre-commit hook
# Install:
# cd path/to/git/repo
# curl -fL -o .git/hooks/pre-commit https://gist.githubusercontent.com/xnopre/a30946cbacf9d857db6192cb45c860f1/raw/4a83dcbe17e7a324f7f2773415e7079328caab10/pre-commit
# chmod +x .git/hooks/pre-commit
BRANCH=`git rev-parse --abbrev-ref HEAD`
'use strict';
// Karma configuration
module.exports = function (config) {
config.set({
// base path, that will be used to resolve files and exclude
basePath: '',
// Frameworks to use
frameworks: ['jasmine'],
@xnopre
xnopre / Address.java
Created May 3, 2013 12:11
Quelles annotations JPA pour une relation multiple vers le même type d'objet ? Exemple : 1 Person contenant 2 attributs de type Address Lien uni-directionnel ou bi-directionnel, du moment que les mises à jour ne laissent pas des "Address" non utilisées dans la base de donnée ...
@Entity
public Address {
// ... other attributes for an address
@???(???)
public Person person;
}
@xnopre
xnopre / Bad_SocketConnectionPowermockTest .java
Last active December 11, 2015 02:08
Problem using PowerMock with SocketConnection Solution : - in "whenNew" : specify instance parameter rather thant class type - use "PrepareForTest" with class that creates the new instance (i.e. SocketConnectionPowermockTest)
import junit.framework.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.simpleframework.http.core.Container;
import org.simpleframework.transport.connect.SocketConnection;
@xnopre
xnopre / assembly-final-classic.xml
Created November 28, 2012 22:04
[Maven] Générer un ZIP contenant un autre ZIP généré
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>final</id>
<baseDirectory>/</baseDirectory>
<formats>
<format>zip</format>
@xnopre
xnopre / pom.xml
Created November 28, 2012 21:39
Ordered unpack dependencies with copy-maven-plugin
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>xno</groupId>
<artifactId>test-unpack</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
@xnopre
xnopre / UserWithEquals.java
Created November 17, 2012 22:48
Exemple d'un objet User avec ajout d'implémentation pour la méthode equals()
package xnopre.javasamples;
class UserWithEquals {
private final String login;
private final int month;
UserWithEquals(String login, int month) {
this.login = login;
this.month = month;
@xnopre
xnopre / TestsEqualsString
Created November 17, 2012 22:42
Exemples de comparaison de String
package xnopre.javasamples;
public class TestsEqualsString {
public static void main(String[] args) {
System.out.println("toto" == "toto"); // true
System.out.println("toto".equals("toto")); // true
System.out.println(new String("toto") == "toto"); // false
String str1 = "toto";
String str2 = "toto";
@xnopre
xnopre / User.java
Created November 17, 2012 22:38
Exemple simple d'objet User
package xnopre.javasamples;
class User {
private final String login;
private final int month;
User(String login, int month) {
this.login = login;
this.month = month;