Skip to content
{{ message }}

Instantly share code, notes, and snippets.

# Ivan Vergiliev IvanVergiliev

Created Jun 21, 2021
Fold a list of predicates
View predicate_fold.scala
 val andPredicates: Array[Column] = parseAndPredicates(...) val compositePredicate: Column = andPredicates.foldLeft(lit(true))((x, y) => x && y)
Created Jun 21, 2021
Exponential Tree Transformation Complexity
View exponential_tree_transform
 f(H) = f(H - 1) // for the first transform call + f(H - 1) // for the second transform call = 2 * f(H - 1) = = 2 * 2 * f(H - 2) = ... = 2 ^ (H - 1) * f(1) // unfolding further
Created Jun 17, 2021
Balanced fold
View tree_fold.scala
 import org.apache.spark.sql.Column def treeFold( columns: List[Column], initialValue: Column, op: (Column, Column) => Column ): Column = { if (columns.isEmpty) { initialValue } else if (columns.length == 1) {
Created Jun 17, 2021
Tree Transformation Algorithm with Code Reuse
View tree_transform_dry.scala
 def transformTree(tree: Tree): Option[Tree] = { // Notice that there's no `canTranform` - we're using // `transform().isDefined` to check for transformability! val transformedLeft = if (transform(tree.left).isDefined) { transform(tree.left) } else None ... }
Created Jun 17, 2021
Tree Transformation Algorithm
View transform.scala
 def transformTree(tree: Tree): Option[Tree] = { val transformedLeft = if (canTransform(tree.left)) { transform(tree.left) } else None val transformedRight = if (canTransform(tree.right)) { transform(tree.right) } else None val result = if (transformedLeft.isDefined && transformedRight.isDefined) {
Last active Mar 16, 2017
View to_string.cc
 #include #include // All of the below are not really standards-compliant, but good enough // for experiments. void* operator new(std::size_t size) { printf("Calling new(%zu).\n", size); return std::malloc(size); }
Last active May 16, 2016
View NonVolatileFlag.java
 package io.github.ivanvergiliev; public class NonVolatileFlag { private static boolean flag = false; public static class FlagChecker implements Runnable { public void run() { long iter = 0; while (flag == false) { ++iter;
Created Jul 12, 2015
Compile time Fibonacci
View power.cc
 #include #include using std::array; const int MOD = 1000; class ArrayWrapper { const array& value;
Created Aug 13, 2014
View gist:bb62c1af502fdfa800fd
 var HelloMessage = React.createClass({ render: function() { return ; } });
Last active Jun 9, 2020
C++ Tuple implementation
View tuple.cpp
 #include template struct Tuple: public Tuple { Tuple(First first, Rest... rest): Tuple(rest...), first(first) {} First first; }; template