Skip to content

Instantly share code, notes, and snippets.

View antic183's full-sized avatar

Antic Marjan antic183

View GitHub Profile
@antic183
antic183 / xss-atack.php
Created December 8, 2017 09:21
php htmlspecialchars is not enough to prevent an xss attack
<h1>php htmlspecialchars()</h1>
<h3>without END_QUOTES flag is an xss attack possible:</h3>
<?php
echo "<a href='" . htmlspecialchars("'onmouseover='a()'") . "'>link</a><br/>";
echo "<textarea style='overflow: none; width: 350px; border: none; resize: none; line-break: none;'>";
echo "<a href=''onmouseover='a()''>link</a>";
echo "</textarea><br/>";
echo "<a href='" . htmlspecialchars("'onmouseover='alert(123)'") . "'>link</a><br/>";
echo "<textarea style='overflow: none; width: 350px; border: none; resize: none; line-break: none;'>";
@antic183
antic183 / WebsocketEndpoint.java
Last active March 24, 2022 18:01
J2EE Websockets example. Use it with javascript client.
package app;
import javax.websocket.OnClose;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
@antic183
antic183 / Dockerfile
Last active July 24, 2017 22:28
rest example with wildfly swarm and jersey
FROM java:openjdk-8-jdk
ADD target/demo-swarm.jar /opt/demo-swarm.jar
EXPOSE 8081
ENTRYPOINT ["java", "-jar", "/opt/demo-swarm.jar"]
@antic183
antic183 / low-level-rest-api.php
Last active April 23, 2020 22:39
php low level rest example
<?php
//print_r($_SERVER['REQUEST_METHOD']);
switch($_SERVER['REQUEST_METHOD']) {
case 'GET':
echo 'GET'; // do anything
break;
case 'POST':
echo 'POST'; // do anything
break;
case 'PUT':
@antic183
antic183 / ApplicationConfiguration.java
Last active March 31, 2017 09:46
Java EE RestFulService Simple example
// ******* JAVA PROJECT "1": *******
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
@ApplicationPath("/api/v1")
public class ApplicationConfiguration extends Application { }
@antic183
antic183 / NestedCategories.java
Last active August 30, 2016 20:57
get all children of a node in tree hierarchy inklusiv root.
public class NestedCategories
{
public static void main(String[] args) {
new NestedCategories();
}
NestedCategories() {
List<Category> fullCategoryList = new ArrayList<>();
fullCategoryList.add(new Category(1, 0));
@antic183
antic183 / GoogleGuiceExample.java
Last active August 18, 2021 01:08
a simple google guice example
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Inject;
import com.google.inject.Injector;
import javax.inject.Singleton;
public class MainApp {
public static void main(String[] args) {
Injector injector = Guice.createInjector(new AppInjector());
@antic183
antic183 / GoolgeGuavaEventBus.java
Last active February 7, 2017 13:38
google guava eventbus example
import com.google.common.eventbus.EventBus;
public class GoolgeGuavaEventBus
{
public static void main(String[] args) {
EventBus eventBus = new EventBus();
//register the receiver
Listener1 l1 = new Listener1();
Listener2 l2 = new Listener2();
eventBus.register(l1);
@antic183
antic183 / App.java
Last active June 26, 2016 20:15
java dependency injection example
import anwendung.Bank;
import anwendung.Gescheaftskonto;
import anwendung.PrivatKonto;
public class App
{
public static void main(String[] args) {
// you can implement DI with setter injection or with constructor injection.
// below you see an example with constructor injection
@antic183
antic183 / java8-lambda-example.java
Last active December 16, 2017 12:45
java 8 lambda example
@java.lang.FunctionalInterface
interface Math
{
public int calc(int a, int b);
}
public class LambdaExample
{
public static void main(String[] args) {
// define your function