Skip to content

Instantly share code, notes, and snippets.

View balopat's full-sized avatar
🎯
Focusing

Balint Pato balopat

🎯
Focusing
View GitHub Profile
@balopat
balopat / sum2DArray.io
Created November 6, 2011 01:51
Sum 2D arrays up with reduce
# initial value of sum := 0
sumItUp := method(reduce(sum, nextList, sum + nextList reduce(+), 0))
testList := list(list(1,2,34,5,3),list(1,23,412,32), list(2,3,4))
testList sumItUp
@balopat
balopat / fibRecursive.io
Created November 6, 2011 01:59
Recursive fibonacci series in Io
fibRecursive := method(num,
if(num<=2, 1, fibRecursive(num-1) + fibRecursive(num-2),0)
)
Range 1 to(10) foreach(v, fibRecursive(v) println)
@balopat
balopat / divideOperator.io
Created November 6, 2011 02:00
Extending an in-built operator
Number $ ::= Number getSlot("/") # saving the original operator as it's a CFunction
OperatorTable addOperator("$",2) # adding it to the OperatorTable, so we can use it in the new definition of /
Number / := method( b, if (b == 0, 0, self$b)) # redefining the Number / slot
@balopat
balopat / MinValueFinder.java
Created March 11, 2012 15:08
The 2nd step in the solution for the Parallel Design Patterns hands-on session
package org.lscc.minfinder;
import org.lscc.parallelpatterns.divideandconquer.DivideAndConquer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class MinValueFinder extends DivideAndConquer<MinValueFinderProblem, Integer>{
@balopat
balopat / MinValueFinder.java
Created March 11, 2012 15:15
The sequential solution (step 1 for the Parallel Design Patterns hands-on session)
package org.lscc.minfinder;
public class MinValueFinder {
private Function<Integer, Integer> f;
public MinValueFinder(Function<Integer, Integer> function) {
this.f = function;
}
@balopat
balopat / MinValueFinder.java
Created April 14, 2012 15:34
Removing DivideAndConquer class - The 3rd step in the solution for the Parallel Design Patterns hands-on session
package org.lscc.minfinder;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.*;
public class MinValueFinder {
private Function<Integer, Integer> f;
private ExecutorService executorService = Executors.newCachedThreadPool();
@balopat
balopat / MinValueFinder.java
Created April 16, 2012 19:56
Introducting the knob - The 4th step of the solution for the Parallel Design Pattern hands-on session
package org.lscc.minfinder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.*;
public class MinValueFinder {
private Function<Integer, Integer> f;
@balopat
balopat / ComplexNumberSpec.scala
Created May 18, 2012 00:16
ComplexNumberSpec
package com.balopat.qc;
import org.scalatest.FlatSpec
import org.scalatest.matchers.ShouldMatchers
import ComplexNumberRectangular._
class ComplexNumberSpec extends FlatSpec with ShouldMatchers {
"A Complex Number" should
"add to another Complex Number by components" in {
@balopat
balopat / ComplexNumberRectangular.scala
Created May 18, 2012 00:21
ComplexNumberRectangular
package com.balopat.qc
case class ComplexNumberRectangular(im: Int, r: Int) {
def i() = this
def +(b: ComplexNumberRectangular) = ComplexNumberRectangular(im + b.im, r + b.r)
def +(b: Int) = ComplexNumberRectangular(im, r + b)
@balopat
balopat / Wall.scala
Last active December 26, 2015 22:59
Hardcoded dependency on time
package com.balopat.timeinjection
import java.util.Date
class Wall {
var messages = List[Message]()
def message(message: String) {
messages ::= Message(message, new Date()) // hardcoded dependency on time!!!
}