This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//based on code from http://www.arcfn.com/2009/03/y-combinator-in-arc-and-java.html and the generic version https://gist.github.com/2571928 | |
class YFact { | |
// T function returning a T | |
// T -> T | |
public static interface Func<T> { | |
T apply(T n); | |
} | |
// Higher-order function returning a T function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: contribs/jersey-simple-server/src/main/java/com/sun/jersey/simple/impl/container/SimpleContainer.java | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
--- contribs/jersey-simple-server/src/main/java/com/sun/jersey/simple/impl/container/SimpleContainer.java (revision 5823) | |
+++ contribs/jersey-simple-server/src/main/java/com/sun/jersey/simple/impl/container/SimpleContainer.java (revision ) | |
@@ -65,7 +65,7 @@ | |
* This is the container that handles all HTTP requests. Requests are adapted | |
* for the enclosed {@link WebApplication} instances. This container can |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface StreamingProvider extends ContentProvider { | |
void write(OutputStream out) throws IOException; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.LinkedHashMap; | |
import java.util.Map; | |
import java.util.concurrent.*; | |
public class Parallel { | |
public static abstract class ForEach<O, K, I> { | |
protected static final Exception CONTINUE = new Exception("forEach Continue"); | |
static { | |
CONTINUE.setStackTrace(new StackTraceElement[0]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.LinkedHashMap; | |
import java.util.Map; | |
import java.util.concurrent.*; | |
public class Parallel { | |
static final Exception CONTINUE = new Exception("forEach Continue"); | |
static { | |
CONTINUE.setStackTrace(new StackTraceElement[0]); | |
} // Delete irrelevant stack trace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void MyParallelForEach<T>(IEnumerable<T> source, Action <T> body) | |
{ | |
int numProcs = Environment.ProcessorCount; | |
int remainingWorkItems = numProcs; | |
using(var enumerator = source.GetEnumerator()) | |
{ | |
using(ManualResetEvent mre = new ManualResetEvent(false)) | |
{ | |
// Create each of the work items. | |
for (int p = 0; p < numProcs; p++) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Parallel.ForEach(students, student => { | |
student.GradePointAverage = student.Tests.Select(test => test.Grade * test.Weight).Sum(); | |
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
addresses.parallelStream().forEach(address -> sendMail(address)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This script is edited by Brice Dutheil. | |
# See there in french http://blog.arkey.fr/2012/07/30/script-pour-installer-le-jdk-5-sur-macosx-lion/ | |
# Translate button is broken for now, please use Google to translate this website. | |
# 2013/06/10 Tested on Mountain Lion 10.8.4 | |
# 2013/02/14 Updated to run on Mountain Lion 10.8.2 | |
# | |
# 2012/08/25 This script didn't behave correctly when ran on 10.8.1 | |
# Added recommendation to always run this script after updates such as Java, XCode, OSX, etc. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
students.parallelStream().forEach(student -> { | |
student.GradePointAverage = student.Tests.parallelStream().mapToDouble(test -> test.Grade * test.Weight).sum(); | |
}); |