Skip to content

Instantly share code, notes, and snippets.

@mabako
mabako / PrintExample.java
Created May 29, 2012 18:45
Simple way to print Java GUI elements
// beliebige Komponente
final Component component = ...;
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintable(new Printable()
{
@Override
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException
{
@mabako
mabako / Dashboard.java
Created May 29, 2012 19:51
TableView thing for databases
package net.mabako.zwickau.autohaendler;
import javax.swing.JButton;
public class Dashboard extends JPanel
{
/**
* Serial
*/
private static final long serialVersionUID = -2754350246072768836L;
@mabako
mabako / UserTable.java
Created June 15, 2012 12:48
User management in SQL Server 2008 R2
package net.mabako.zwickau.db;
import static net.mabako.zwickau.autohaendler.G.db;
import java.util.Vector;
public class UserTable extends TableHandler
{
/**
* {@inheritDoc}
@mabako
mabako / decode.lua
Created June 28, 2012 18:37
lua € thing, unicode(like utf16)->utf8
:gsub("&#%d%d%d%d;", decode)
function decode(str)
local num = tonumber(str:sub(3,6))
local first = math.floor(num/4096)
num = num - 4096 * first
return string.char(first+224, math.floor(num/64)+128, num%64+128)
end
@mabako
mabako / gist:4037837
Created November 8, 2012 09:46
java: read string into file
/**
* Read complete file into a String
*/
try(InputStream is = ...) {
try(Scanner s = new Scanner(is).useDelimiter("\\A")) {
return s.hasNext() ? s.next() : "";
}
}
(define (primHelp num count)
(cond
((zero? (modulo num count)) #f)
((< count (sqrt num)) (primHelp num (+ count 1)))
(else #t)
)
)
@mabako
mabako / max-square-sum.scm
Created October 11, 2013 16:58
Calculates the sum of the squares of the two largest numbers in the list
(define (a8 a . r)
(let
(
(m (apply max r))
)
(if (>= a m)
(+ (quadrat a) (quadrat m))
(apply a8 (append r (list a)))
)
)
@mabako
mabako / euklid.scm
Created October 11, 2013 17:15
euclidian algorithm
(define (euklid a b)
(if (= b 0) a (euklid b (modulo a b)))
)
(print (euklid 1071 1029))
(print (euklid 1029 1071))
@mabako
mabako / erweiterter_euklid.scm
Created October 11, 2013 17:42
erweiterter euklid
(define (erweiterter_euklid a b)
(if (= b 0)
(list a 1 0)
(begin
(let*
(
(tmp (erweiterter_euklid b (modulo a b)))
(d (car tmp))
(s (cadr tmp))
(t (caddr tmp))
(define (a8 a . r)
(let
(
(m (apply max r))
)
(if (>= a m)
(+ (quadrat a) (quadrat m))
(apply a8 (append r (list a)))
)
)