Skip to content

Instantly share code, notes, and snippets.

View carousel's full-sized avatar
🏠
Working from home

MiroslavTrninic carousel

🏠
Working from home
View GitHub Profile
@carousel
carousel / .vimrc.java.api.docs
Last active October 14, 2020 18:33
Use vim to search Java docs API
#read the comment below first
#paster this line into your .vimrc file
#<leader> is mapped to ,
map ,g gx u
@carousel
carousel / digits.java
Created January 31, 2020 17:17
Count number of digits in integer with Java
public static int stringBased(int number) {
return String.valueOf(number).length();
}
public static int logarithmBased(int number) {
return (int) Math.log10(number) + 1;
}
public static int repeatedMultiplication(int number) {
int length = 0;
@carousel
carousel / logarithm.java
Created December 18, 2019 10:12
calculate logarithm for any base in java
int num = 8;
int base = 2;
double log = Math.log(num) / Math.log(base);
System.out.println(log);
@carousel
carousel / dynamicArray.java
Last active December 17, 2019 13:58
Caclulate new size for dynamic array in Java
private Integer newSize(Integer currentSize, Integer inputSize) {
if (currentSize > inputSize) {
return currentSize * 2;
} else if (currentSize < inputSize) {
return (inputSize % currentSize == 0) ? (currentSize + inputSize) : (currentSize + inputSize + 1);
} else {
return currentSize + inputSize;
}
}
@carousel
carousel / Dockerfile
Last active July 13, 2018 08:20
Dockerfile reference with explanation
#.dockerignore
#Sets the Base Image for subsequent instructions.
FROM
#(deprecated - use LABEL instead) Set the Author field of the generated images.
MAINTAINER
#execute any commands in a new layer on top of the current image and commit the results.
RUN
@carousel
carousel / money.php
Created May 26, 2018 12:00
Money pattern implemented in PHP
<?php
class Money
{
private function __construct($currency, $amount)
{
$this->currency = $currency;
$this->amount = $amount;
}
public static function fromString($currency, $amount)
@carousel
carousel / TypedCollection.php
Created March 26, 2018 18:40
Typed collection in php (collection of objects) for usage in DDD projects.
<?php
interface Vehicle{}
class Car implements Vehicle{}
class Track implements Vehicle{}
class Fruit{}
class Collection
{
protected $items = [];
@carousel
carousel / snake-to-camel.php
Last active May 27, 2024 10:56
Convert snake to camel case and back with PHP
<?php
function camel_to_snake($input)
{
return strtolower(preg_replace('/(?<!^)[A-Z]/', '_$0', $input));
}
function snakeToCamel($input)
{
return lcfirst(str_replace(' ', '', ucwords(str_replace('_', ' ', $input))));
}
<?php
namespace SomeApp\Application\DTO;
use Symfony\Component\OptionsResolver\OptionsResolver;
abstract class AbstractRequest
{
public function __construct(array $data)
@carousel
carousel / hexagon.php
Created March 5, 2018 20:54
PHP hexagon + CQRS example
<?php
interface ReadPostRepository
{
public function byId(PostId $id);
public function all();
public function byCategory(CategoryId $categoryId);
public function byTag(TagId $tagId);
public function withComments(PostId $id);
public function groupedByMonth();