Skip to content

Instantly share code, notes, and snippets.

View lucaswerkmeister's full-sized avatar

Lucas Werkmeister lucaswerkmeister

View GitHub Profile
@lucaswerkmeister
lucaswerkmeister / gist:5339933
Created April 8, 2013 19:53
Gets a robust view of any enumerable - this one will not break when you modify the underlying enumerable (e. g., modify the list). Originally written for lucaswerkmeister/wp_geohashing until I realized I didn't need it there.
/// <summary>
/// Gets a robust enumerator for the IEnumerable. A robust enumerator will function even when the collection is modified while enumerating.
/// </summary>
/// <typeparam name="T">The type.</typeparam>
/// <param name="coll">The collection.</param>
/// <param name="lookBehind">If <code>true</code>, elements inserted before the current element will still be returned.</param>
/// <returns>An IEnumerable that will not throw an IllegalOperationException if the underlying collection is modified.</returns>
public static IEnumerable<T> AsRobustEnumerable<T>(this IEnumerable<T> coll, bool lookBehind = false) where T : class
{
HashSet<T> alreadyReturned = new HashSet<T>();
#!/bin/sh
mkdir data/frames 2> /dev/null # create the images folder, but don't show an error message if it already exists
set i=1; # counter
set filename=; # file name, not used yet
i=1; # actually initialize counter
curl --silent geekwagon.net/projects/xkcd1190/data/data.txt | \
while read line; do # for each line in data.txt, do the following:
line=`echo $line | tr -d ' '`; # remove all spaces
if [ ! "$line" = "" ]; then # check that line is not empty
filename="data/frames/$i.png";
#!/bin/sh
# ceylon-dist, including ceylon-common, ceylon-compiler, ceylon-js, ceylon-module-resolver, ceylon-runtime, ceylon-spec and ceylon.language
cd ceylon-dist
echo "$0: Updating ceylon-dist"
printf "%$(tput cols)s\n" | tr ' ' '='
ant update-all publish-all
echo -e '\nDone.\n'
cd ..
# ceylon-sdk
cd ceylon-sdk
@lucaswerkmeister
lucaswerkmeister / cgdb-test.sh
Last active December 29, 2015 10:29
A test script for reading input in cgdb
#!/bin/sh
cd /tmp
cat > tmp.c <<EOF
#include <stdio.h>
int main() {
char str[4096];
fgets(str, 4096, stdin);
printf("%s\n", str);
return 0;
/**
 * description
 *
 * longer
 * description
 *
 * @author The Author
 * @throws Exception if this
 * or that happens
package tmp;
@.com.redhat.ceylon.compiler.java.metadata.Ceylon(major = 6)
@.com.redhat.ceylon.compiler.java.metadata.Method
final class foo_ {
private foo_() {
}
@.com.redhat.ceylon.compiler.java.metadata.TypeInfo("ceylon.language::Anything")
@lucaswerkmeister
lucaswerkmeister / explanation.md
Last active January 3, 2016 09:59
Ceylon comprehension compilation for the Java platform as I understand it

Take this Ceylon code:

{ for (x in foo) if (bar) for (y in baz) op(x, y) }

The compiler generates an anonymous AbstractIterable class for this with a chain of boolean "has thing" methods:

  • next() (the only non-boolean method) calls y() to get the next element, if possible
  • y() checks $iterator$2 to request an iterator for baz, then gets the next item – if it exists, y is set, else y$exhausted$ is set
  • $iterator$2() checks if the x iterator isn’t exhausted, if the y iterator exists and if it doesn’t, checks $next$1() to see if it should generate another iterator
  • $next$1() checks x() to see if it should even check the expression, then checks the expression (I abbreviated it below to bar)
  • x() checks if the "root" iterator isn’t exhausted, and sets x in that case
@lucaswerkmeister
lucaswerkmeister / changes.diff
Created January 15, 2014 23:20
Grammar changes for ceylon/ceylon-spec#869 – comprehensions beginning with if clause
diff --git a/Ceylon.g b/Ceylon.g
index 1ef1226..3dee8ef 100644
--- a/Ceylon.g
+++ b/Ceylon.g
@@ -1848,7 +1848,9 @@ anonymousFunction returns [Expression expression]
comprehension returns [Comprehension comprehension]
@init { $comprehension = new Comprehension(null); }
: forComprehensionClause
- { $comprehension.setForComprehensionClause($forComprehensionClause.comprehensionClause); }
+ { $comprehension.setInitialComprehensionClause($forComprehensionClause.comprehensionClause); }
@lucaswerkmeister
lucaswerkmeister / patch.diff
Created January 16, 2014 22:37
Fix ceylon/ceylon-compiler#986 for 'if' comprehension clauses
diff --git a/src/com/redhat/ceylon/compiler/java/codegen/ExpressionTransformer.java b/src/com/redhat/ceylon/compiler/java/codegen/ExpressionTransformer.java
index c95c00a..f4d815a 100755
--- a/src/com/redhat/ceylon/compiler/java/codegen/ExpressionTransformer.java
+++ b/src/com/redhat/ceylon/compiler/java/codegen/ExpressionTransformer.java
@@ -4597,6 +4597,8 @@ public class ExpressionTransformer extends AbstractTransformer {
if (transformedCond.hasResultDecl()) {
fields.add(make().VarDef(make().Modifiers(Flags.PRIVATE),
resultVarName.asName(), transformedCond.makeTypeExpr(), null));
+ valueCaptures.add(make().VarDef(make().Modifiers(Flags.FINAL),
+ resultVarName.asName(), transformedCond.makeTypeExpr(), resultVarName.makeIdentWithThis()));
@lucaswerkmeister
lucaswerkmeister / ceylon-compiler.patch
Created January 17, 2014 01:18
ceylon: allow comprehensions to start with ifs (ceylon/ceylon-spec#869) WIP (the ceylon-js patch is just to make ceylon-dist buildable)
diff --git a/src/com/redhat/ceylon/compiler/java/codegen/ExpressionTransformer.java b/src/com/redhat/ceylon/compiler/java/codegen/ExpressionTransformer.java
index f4d815a..3a54ba6 100755
--- a/src/com/redhat/ceylon/compiler/java/codegen/ExpressionTransformer.java
+++ b/src/com/redhat/ceylon/compiler/java/codegen/ExpressionTransformer.java
@@ -1401,7 +1401,7 @@ public class ExpressionTransformer extends AbstractTransformer {
public JCExpression comprehensionAsSequential(Tree.Comprehension comprehension, ProducedType expectedType) {
JCExpression sequential = iterableToSequential(transformComprehension(comprehension));
- ProducedType elementType = comprehension.getForComprehensionClause().getTypeModel();
+ ProducedType elementType = comprehension.getInitialComprehensionClause().getTypeModel();