Skip to content

Instantly share code, notes, and snippets.

View antic183's full-sized avatar

Antic Marjan antic183

View GitHub Profile
@antic183
antic183 / even-or-odd.js
Last active May 19, 2016 10:58
is number even or odd
function isEven(number) {
return !(number & 1);
}
function isOdd(number) {
return !!(number & 1);
}
isOdd(5); // true
@antic183
antic183 / random-text.js
Last active March 5, 2020 14:31
generate random text with javascript
var text = "";
var alphabet = "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,r,s,t,u,v,w,x,y,z".split(",");
var wordCount = 256;
for(var i=0; i<wordCount; i++) {
var rand = null;
for (var x=0; x<7; x++) {
rand = Math.floor(Math.random() * alphabet.length);
text += alphabet[rand];
}
if (i<wordCount-1)
@antic183
antic183 / remove-utf8-bom.js
Last active March 13, 2024 08:45
remove utf-8 bom with javascript
// remove utf-8 BOM from ressource "res"
// res.charCodeAt(0) === 0xFEFF | res.charCodeAt(0) === 65279
if (res.charCodeAt(0) === 0xFEFF) {
res = res.substr(1);
}
<?php
$arr1 = array(
"a" => ["x", "d" => "override me..", "d2" => ["q"], "v" => "NOT-IN-B"],
"b" => ["d" => 155, "fff" => ["aa"=>551]],
5, 8, 9
);
$arr2 = array(
"a" => ["v", "d" => "overrided!", "qq" => "ONLY-IN-B"],
@antic183
antic183 / _encript-decript-from-console.php
Last active April 24, 2020 00:47
encrypt and decrypt files and folders with php (AES-256) trought command line
<?php
/*
> composer install
# encript:
php _encript-decript-from-console.php enc "password" file.pdf
=> result = timestamp-file.pdf.enc
php _encript-decript-from-console.php enc "password" image.jpg
=> result = timestamp-mage.jpg.enc
php _encript-decript-from-console.php enc "password" folderA
@antic183
antic183 / json-cleaner.js
Last active June 26, 2016 20:18
clean json (remove undefined nodes)
var jsonDummy = {
key: 'val',
underobj: {
ewssswww: undefined,
asdas: 45105,
ssswww: undefined,
errwew: undefined,
ssswww: 0,
sdfsd: 'dfsdf',
uuunt: {
@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
@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 / 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 / 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());