Skip to content

Instantly share code, notes, and snippets.

View atomgomba's full-sized avatar

Károly Kiripolszky atomgomba

View GitHub Profile
@atomgomba
atomgomba / findbymac.sh
Last active November 12, 2018 15:53
Find the IP of a Raspberry Pi (or any computer really) on the network by MAC
#!/bin/bash
#
# Find the IP address of a client by MAC on the same network. Sudo privilege and nmap required.
#
# usage: ./findbymac.sh <MAC_ADDRESS>
#
# The first argument to the script is the MAC address or part of the MAC address.
#
# example: sudo ./findbymac.sh "aa:b8"
#
from collections import namedtuple
from hashlib import sha256
from typing import List, Optional
def makehash(data: str) -> str:
return sha256(data.encode()).hexdigest()
Block = namedtuple("Block", ["data", "hash", "prevhash"])
@atomgomba
atomgomba / mocking-using-mock-android-jar.java
Created February 22, 2017 10:34
Mocking using mock android.jar
class TestContext extends MockContext {
@Override public MockResources getResources() {
return new TestResources();
}
}
class TestResources extends MockResources {
@Override public String getString(int id) {
return "foo is a bar";
}
@atomgomba
atomgomba / impossible-unit-test-on-android.java
Created February 22, 2017 10:32
Impossible unit test on Android
ArticleViewActivity a = new ArticleViewActivity();
Bundle b = new Bundle();
b.putString("articleId", "bab13");
a.onCreate(b);
assertTrue(a.hasArticle());
@atomgomba
atomgomba / dependency-injection-bad-practice.java
Created February 22, 2017 10:31
Dependency Injection bad practice
class Baby {
private Bottle mBottle;
public Baby() {
// rossz, nem tesztelhető kód
mBottle = new Bottle();
}
}
@atomgomba
atomgomba / two-ways-of-dependency-injection.java
Last active February 22, 2017 10:42
Two ways of Dependency Injection
// injection via constructor
Baby baby = new Baby(new MockBottle());
// injection via setter
Baby baby = new Baby();
baby.giveBottle(new MockBottle());
@atomgomba
atomgomba / assert-an-exception.java
Created February 22, 2017 10:30
Assert an exception
Baby baby = new Baby();
boolean exceptionWasThrown = false;
try {
baby.removeToy();
} catch (ToyNotExistsException e) {
exceptionWasThrown = true;
}
assertTrue(exceptionWasThrown);
@atomgomba
atomgomba / assert-change-in-dependency.java
Last active February 22, 2017 10:40
Assert change in dependency
Baby baby = new Baby();
Bottle bottle = new MockBottle();
// a csecsemőnek szüksége van egy üvegre a táplálkozáshoz
baby.feed(bottle);
assertTrue(bottle.isConsumeCalled());
class MockBottle extends Bottle {
@Override void consume() {
mConsumeCalled = true;
}
@atomgomba
atomgomba / assert-a-return-value.java
Created February 22, 2017 10:28
Assert a return value
Baby baby = new Baby();
boolean toyGiven = baby.giveToy(null);
assertFalse(toyGiven);
@atomgomba
atomgomba / assert-a-public-property.java
Created February 22, 2017 10:28
Assert a public property
Baby baby = new Baby();
baby.removeToy();
assertTrue(baby.isCrying());