Skip to content

Instantly share code, notes, and snippets.

View doridori's full-sized avatar

Dorian Cussen doridori

View GitHub Profile
@doridori
doridori / DaggerPilotStack.java
Created March 31, 2017 12:53
Example of a Dagger wrapped pilot stack for Activity/Stack scoped DI.
/**
* A PilotStack that also holds a ref to a Dagger Component. This is useful for easy Activity-Scoped DI as the PilotStack has to already live
* on past the host-Activities config-change events by some mechanism (project dependent).
*
* @param <D> A Dagger Component to supply all deps for this stacks frames.
*/
//todo unused - here for dagger activity scope refactor (See trello)
public class DaggerPilotStack<D> extends PilotStack
{
D scopedDaggerComponent;
@doridori
doridori / explicit_iv.java
Last active September 14, 2023 14:24
Beware of the default IV blog post example
public byte[] encrypt(byte[] in)
{
...
byte[] iv = new byte[IV_LENGTH];
new SecureRandom().nextBytes(iv);
cipher.init(Cipher.ENCRYPT_MODE, key, new IvParameterSpec(iv));
byte[] cipherBytes = cipher.doFinal(s.getBytes("UTF-8"));
return concat(iv, cipherBytes);
}
@doridori
doridori / RuntimeKernel.kt
Last active January 5, 2022 20:20
Runtime Centric Thinking Blog post snippts
val commandHandler: CommandHandler
var runtimeData: RuntimeData
fun RuntimeKernel.receive(action) {
//the runtime maintains its own main loop
marshallToRuntimeMainThread {
val transition = reduce(action, runtimeData)
runtimeData = transition.runtimeData
//effect system, describes commands and runtimeData state change operations
val transitionOperations = describe(transition)
@doridori
doridori / reduce.kt
Last active January 20, 2023 19:30
Application as a function blog post code
fun reduce(action: Action, state: State): Effect