Skip to content

Instantly share code, notes, and snippets.

View aruld's full-sized avatar
🎯
Focusing

Arul Dhesiaseelan aruld

🎯
Focusing
View GitHub Profile
@aruld
aruld / YFact.java
Created October 27, 2012 20:12 — forked from jonbodner/YFact.java
Generic Y Combinator in Java 8 using lambdas
//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
@aruld
aruld / simple-5.0.4.patch
Created January 7, 2013 20:33
Patch for JERSEY-1641 (Upgrade to Simple 5.0.4 in Jersey 1.x)
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
@aruld
aruld / StreamingProvider.java
Created February 8, 2013 08:07
Jetty ContentProvider
public interface StreamingProvider extends ContentProvider {
void write(OutputStream out) throws IOException;
}
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]);
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
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++) {
Parallel.ForEach(students, student => {
student.GradePointAverage = student.Tests.Select(test => test.Grade * test.Weight).Sum();
} );
addresses.parallelStream().forEach(address -> sendMail(address));
@aruld
aruld / install_jdk5_mtn_lion.sh
Last active December 13, 2015 18:49 — forked from bric3/install_jdk5_post_lion.sh
This is a fork from https://gist.github.com/bric3/1163008 # 2013/06/10 Tested on Mountain Lion 10.8.4 # 2013/02/14 Updated to run on Mountain Lion 10.8.2
#!/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.
students.parallelStream().forEach(student -> {
student.GradePointAverage = student.Tests.parallelStream().mapToDouble(test -> test.Grade * test.Weight).sum();
});