Skip to content

Instantly share code, notes, and snippets.

public class Promises {
private static class PageMetrics {
Integer visits;
Long avgMsOnPage;
@Override
public String toString() {
return String.format("{ avgMsOnPage=%d, visits=%d }", avgMsOnPage, visits);
}
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;
<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 net.branchandbound.builder;
public class PizzaOrderNewStyle {
private int size;
private boolean pepperoni;
private boolean chicken;
private boolean mushroom;
private boolean peppers;
private String cheese;
<?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");
/**
* ```
* Does JDK8's Optional class satisfy the Monad laws?
* =================================================
* 1. Left identity: true
* 2. Right identity: true
* 3. Associativity: true
*
* Yes, it does.
* ```
@esfand
esfand / CovarianceTest.java
Last active August 29, 2015 14:02 — forked from mallipeddi/gist:74274
Demonstrates the concepts of covariance and contravariance in the Java type system
import java.util.*;
/*
* Covariance and contravariance.
*
* A type operator (an operator which takes as input a type and returns another type as output) is
* said to be
* 1) `covariant` if it preserves the ordering of types and orders types
* from more specific ones to more generic ones.
* 2) `contravariant` if it preserves the ordering of types and orders types