Skip to content

Instantly share code, notes, and snippets.

@esfand
esfand / MonadicJava.md
Last active August 29, 2015 14:02
Monadic Java

What is a monad?

A monad is a triple (T, η, μ) where

  • T is an endofunctor T: X -> X and
  • η: I -> T and μ: T x T -> T are 2 natural transformations satisfying these laws:
    • Identity law: μ(η(T)) = T = μ(T(η))
    • Associative law: μ(μ(T × T) × T)) = μ(T × μ(T × T))

In other words:

a monad in X is just a monoid in the category of endofunctors of X, with

<?php
// src/Foobar/Controller/FooController.php
namespace Foobar\Controller;
class FooController
{
public function helloAction($request)
{
#!/bin/bash
mkdir -p bin sources/{config,twig,sql,lib/{Model,Controller}} web/{css,images,js} tests documentation log
chmod 777 log
> web/favicon.ico
cat > bin/generate_model.php <<"EOF"
<?php // bin/generate_model.php
$app = require(__DIR__."/../sources/bootstrap.php");
@esfand
esfand / completablefuture.md
Last active August 29, 2015 14:01
CompletableFuture

Class CompletableFuture Class

public class CompletableFuture<> extends `Object`
implements interface in Future, CompletionStage<>

A Future that may be explicitly completed (setting its value and status), and may be used as a CompletionStage, supporting dependent functions and actions that trigger upon its completion.

@esfand
esfand / finaldeser.md
Last active July 8, 2019 06:14
Java Final Field Deserialization with readobject

Java Serialization & final class attributes

The SmartWeb BusinessObject class defines a protected attribute named logger carrying the logger for subclasses. The BusinessObject class implements Serializable thus it needs to define the logger attribute as transient because Commons Logging loggers are non serializable.

The problem arises whenever you deserialize a BusinessObject subclass because the logger attribute will not be deserialized (it has not be serialized at all!)

package net.branchandbound.builder;
public class PizzaOrderNewStyle {
private int size;
private boolean pepperoni;
private boolean chicken;
private boolean mushroom;
private boolean peppers;
private String cheese;
<iframe src="https://www.google.com/maps/embed?pb=!1m14!1m8!1m3!1d56790.47490202523!2d78.042155!3d27.175014999999924!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x39747121d702ff6d%3A0xdd2ae4803f767dde!2sTaj+Mahal!5e0!3m2!1sen!2s!4v1398864446719" width="800" height="600" frameborder="0" style="border:0"></iframe>
package testlargestarray;
import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.*;
import java.util.stream.*;
/*
Problem: Given a list of random numbers, both positive and negative, find the
largest sum of a sublist.
package com.hanhuy.android.common.concurrent;
import android.os.AsyncTask;
import com.google.common.base.Function;
import com.google.common.base.Preconditions;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.Callable;