Skip to content

Instantly share code, notes, and snippets.

@marinhoarthur
marinhoarthur / get-img-format.js
Last active April 25, 2017 20:34
js code to retrieve the format of any given image (square, horizontal, vertical) *jquery free*
function getAspectRatio(img) {
return img.width / img.height;
}
function getImgFormat(img) {
var aspectRatio = getAspectRatio(img);
if(aspectRatio === 1) {
return 'square';
} else if (aspectRatio > 1) {
@marinhoarthur
marinhoarthur / Dois.java
Last active April 25, 2017 20:26
Coding Marathon I - UnP (challenges 2, 4, 6)
import java.util.Scanner;
public class Dois
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int n = in.nextInt();
@marinhoarthur
marinhoarthur / Even.java
Created September 6, 2014 16:38
Producer-Consumer problem with Threads
class Even extends Thread
{
Holder h;
Even(Holder h)
{
this.h = h;
}
public void run()
@marinhoarthur
marinhoarthur / Car.java
Last active August 29, 2015 14:06
Decorator pattern written in Java
package br.com.car.decorator;
interface Car
{
int getHp();
float getPrice();
}
@marinhoarthur
marinhoarthur / DR.java
Last active August 29, 2015 14:02
Duplicate elements remover
void removeDuplicate(List<?> l)
{
if(l.isEmpty() || l.size() == 1)
{
return;
}
List<Integer> toRemove = new ArrayList<Integer>();
for(int i = 0; i < l.size(); i++)
{
for(int j = i+1; j < l.size(); j++)
@marinhoarthur
marinhoarthur / Chain.java
Last active August 29, 2015 14:02
Simulation of airport/supermarket carts organization system behaviour.
public class Chain{
private List<Cart> carts = new ArrayList<Cart>();
private void attach(Cart c)
{
if(getSize() >= 2) // If chain has no more than 2 carts , then leave both carts edge field set to true
{
getLastCart().setEdge(false);
}
@marinhoarthur
marinhoarthur / Algorithm.py
Last active May 5, 2022 12:39
A simple genetic algorithm written in Python fully based on an article by Lee Jacobson from his blog theprojectspot.com
from Population import Population
from Individual import Individual
from random import random, randint
class Algorithm():
#Constants
Uniform_rate = 0.5
Mutation_rate = 0.015
Tournament_size = 5