Skip to content

Instantly share code, notes, and snippets.

View wende's full-sized avatar

Krzysztof Wende wende

  • Neon Tree Solutions Ltd.
  • Gdańsk, Poland
View GitHub Profile
loadAll = fn(dir) ->
dir
|> Path.join("**/*.ex")
|> Path.wildcard()
|> Enum.map(&Code.require_file/1)
end
formatResult = fn({exists, one, multi}) ->
[exists, one, Enum.join(multi, ",")] |> (&(Enum.join(&1, "|"))).()
end
formatResult = fn({exists, one, multi}) ->
[exists, one, Enum.join(multi, ",")] |> (&(Enum.join(&1, "|"))).()
end
send(msg, date) ->
DB.add(msg, date)
poll(lastMsgDate) ->
return DB.getAll.filter( _.data > lastMsgDate)
object LogicSFK extends Logic {
type FK[R] = () => R
type SK[A,R] = (A, FK[R]) => R
trait T[A] { def apply[R](sk: SK[A,R], fk: FK[R]): R }
def fail[A] =
new T[A] {
def apply[R](sk: SK[A,R], fk: FK[R]) = fk()
}
val time = System.currentTimeMillis();
val colors = List('red, 'yellow, 'green, 'blue, 'white)
val nations = List('brit, 'swede, 'dane, 'german, 'norwegian)
val beverages = List('tea, 'coffee, 'milk, 'water, 'beer)
val cigars = List('pallmall, 'dunhill, 'blend, 'bluemaster, 'prince)
val pets = List('fish, 'dog, 'bird, 'cat, 'horse)
def thingToPerson(ordering: Seq[Symbol]): Map[Symbol, Int] =
ordering.zip(0 until 5).toMap
def ownagePerms(stuff: List[Symbol]) =
persons(0, []) :- !.
persons(N, [(_Men,_Color,_Drink,_Smoke,_Animal)|T]) :- N1 is N-1, persons(N1,T).
person(1, [H|_], H) :- !.
person(N, [_|T], R) :- N1 is N-1, person(N1, T, R).
% The Brit lives in a red house
hint1([(brit,red,_, _, _)|_]).
hint1([_|T]) :- hint1(T).
% The Swede keeps dogs as pets
hint2([(swede,_,_,_,dog)|_]).
final Vibrator v = (Vibrator) MainActivity.getInstance().getSystemService(Context.VIBRATOR_SERVICE);
new Thread(new Runnable() {
@Override
public void run() {
while(true) {
v.vibrate(100);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();

// Lambda's / delegates in different languages

##Java < 8

  Adder adder = new Adder(){
    @Override
    public int add(int a, int b){
      return a + b;
    }
 })
val x = 10
val k = 2
val iloscKul = 3
var suma = 0.0
var mnożnik = 1000
do {
suma = k*mnożnik * (1- Math.pow(2,iloscKul)) / (-1)
mnożnik/=2
} while(suma > x*1000)
object Helpers {
def time[R](block: => R): (R, Long) = {
val t0 = System.nanoTime()
val result = block // call-by-name
val t1 = System.nanoTime()
(result, t1 - t0)
}
}
case class Memoize[-T , +R : ClassTag](duration : Duration, refreshOnGet : Boolean = false)(f: T => R)
(implicit app : Application) extends (T => R) {