Skip to content

Instantly share code, notes, and snippets.

View antic183's full-sized avatar

Antic Marjan antic183

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / passwordGenerator.php
Created February 21, 2018 08:08
php random password generator
<?php
function getRandomPassword($passwordLength = 4) {
$alphabet = 'abcdefghijklmnopqrstuvwxyz';
$characterCollection = array_merge(str_split($alphabet), str_split(strtoupper($alphabet)), str_split('1234567890'), str_split('!~@#-_+<>[]{}'));
$randomPassword = '';
for($i = 0; $i < $passwordLength; $i++) {
$randomPassword .= $characterCollection[array_rand($characterCollection)];
}
@antic183
antic183 / RegexExampleNumberOfHits.java
Last active May 23, 2018 11:16
java regex examples find number of hits
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegexExampleNumberOfHits {
public static void main(String[] args) {
String txt = "dfsd weqwe asdasdw und \nsch\nqschwexs xsdad\nschaber\n\reewwww dxddasdfsf\n\rsch\n\r dfsgfgd bieeewwwww";
// word content
Matcher matchSentence = Pattern.compile("sch", Pattern.CASE_INSENSITIVE).matcher(txt);
int hits = 0;
@antic183
antic183 / example.html
Last active April 5, 2019 11:30
fancybox gallery groups
<!DOCTYPE html>
<html>
<head>
<title>fancybox</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.5.7/jquery.fancybox.min.css">
@antic183
antic183 / encode-decode-email.php
Last active March 13, 2024 08:21
a very simple and effectively way to hide email from spam bots
<?php
$email = '[email protected]'; // when email-domain-part contains umlauts, use the idn format: idn_to_ascii('your-email@example-äöü.com');
$emailLength = mb_strlen($email);
$randomFactor = '';
$encodedMail = '';
for ($ix = 0; $ix < $emailLength; $ix++) {
$randomFactor .= rand(1, 9);
}