Skip to content

Instantly share code, notes, and snippets.

View edofic's full-sized avatar

Andraž Bajt edofic

View GitHub Profile
@edofic
edofic / plonk.java
Created January 19, 2012 10:51
drawing
JButton, JCheckBox, JComboBox, JToolBar, JTextField, JRadioButton,
JScrollBar, JWindow, JFrame, JButton, JCheckBox, JComboBox, JRadioButton
narišemo črto od spodnjega levega do gornjega desnega oglišča risalne plošče:
paintComponent({0,maxHeight,maxWidth,0});
drawString(niz,x,y);
drawLine(x1,y1,x2,y2);
drawArc(x,y,sirina,visina,zackot,kot);
drawPolygon(p); Polygon p= new Polygon(); p.addPoint(10,10);
@edofic
edofic / math_repl.scala
Created August 25, 2012 20:00
very simple repl for math expressions(no variables)
package parsing
import util.parsing.combinator.RegexParsers
/**
* User: andraz
* Date: 8/25/12
* Time: 4:05 PM
*/
object ExpressionParsing {
@edofic
edofic / Atom.scala
Created November 24, 2012 12:03
Scala atom
/*
atoms
------------------------------------
non local lazy val
"write once var"
externally pure, interanally mutable
remote attributes
*/
class Atom[A] {
private var value: A = _
@edofic
edofic / Naloga3.scala
Created December 1, 2012 13:09
aps naloga 3 scala
import java.io.{BufferedWriter, PrintWriter, FileWriter, File}
import java.util.Scanner
object Naloga3s {
def Reader(filename: String) = {
val sc = new Scanner(new File(filename))
def loop(): Stream[Int] = {
if (sc.hasNextInt){
sc.nextInt() #:: loop
} else
@edofic
edofic / xy.java
Created December 11, 2012 14:35
coordinates transformer
class Point{
final double x,y;
Point(a,b){
x=a;
y=b;
}
.......
//transformx lat,lon to unit circle with hard limit
import java.util.Scanner
import collection.mutable.{Map,ListBuffer,Queue}
object Naloga6{
def main(args: Array[String]){
val start = args(0)
val pathMode = args.length == 2
val end = if(pathMode) args(1) else start.sorted
val graph = new Graph()
@edofic
edofic / naloga6.ugly.scala
Last active December 11, 2015 08:39
if this was js i would say i minified the code.
import java.util.Scanner;import collection.mutable._;object A{type S=String;def main(a:Array[S]){val s=a(0);val p=a.size==2;val e=if(p)a(1)else(s.sorted);val c=new Scanner(System.in);while(c.hasNextLine){val w=c.nextLine;i(new N(w,if(p)(w==e)else(w.sorted==e&&w!=s)))};val q=Queue[N]();val k=y(s);k.c=0;def x(z:N){if(z.t)return;if(!z.v){z.e.map{e=>;if(e.c>z.c+1)e.p.clear();if(e.c>z.c){e.c=z.c+1;e.p.append(z)};if(!e.v)q.enqueue(e)}};z.v=true;if(!q.isEmpty)x(q.dequeue)};x(k);for{n<-y.values if(!n.p.isEmpty&&n.t)}n.P("")};val y=Map[S,N]();def i(n:N){for(m<-y.values;if(d(m.k,n.k)==1)){m.e.append(n);n.e.append(m)}};def d(s1:S,s2:S)=s1.zip(s2).filter{t=>t._1!=t._2}.size;class N(val k:S,val t:Boolean){val e,p=ListBuffer[N]();var c=Int.MaxValue;var v=false;def P(a:S){if(p.isEmpty)println(k+a)else(p.map(_.P("->"+k+a)))}}}
@edofic
edofic / trees.scala
Created January 24, 2013 10:18
having fun with subtrees
case class Node(left: Option[Node] = None, right: Option[Node] = None) {
lazy val size: Int = 1 + left.map(_.size).getOrElse(0) + right.map(_.size).getOrElse(0)
lazy val sum:Int = size +left.map(_.sum).getOrElse(0) + right.map(_.sum).getOrElse(0)
}
def tree(n: Int): Node = {
assert(n>0)
n match {
case 1 => Node()
case 2 => Node(Some(Node()), None)
@edofic
edofic / DemoBuild.scala
Created February 24, 2013 20:44
whoa you can depend on git projects from sbt just put this in project/ and `sbt console`
import sbt._
import Keys._
object DemoBuild extends Build {
val macros = RootProject(uri("git://github.com/edofic/reactive-macros"))
val main = Project("main", file(".")).settings(
scalaVersion := "2.10.0"
) dependsOn macros
}
@edofic
edofic / typeclasses.scala
Created May 27, 2013 14:24
typeclasses and syntax in scala. monad example. this is approximately how scalaz works
trait Monad[M[_]] {
def apply[A](a: => A): M[A]
def flatMap[A,B](value: M[A], f: A => M[B]): M[B]
def map[A,B](value: M[A], f: A=>B): M[B] = flatMap(value, (v: A) => apply(f(v)))
}
object Monad {
def apply[A[_]](implicit f: Monad[A]) = f
}