Skip to content

Instantly share code, notes, and snippets.

View Tiim's full-sized avatar

Tiim

View GitHub Profile
final JCommandPopupMenu menu = new JCommandPopupMenu();
menu.addMenuButton(new JCommandMenuButton("Hallo",null));
button.setCommandButtonKind(JCommandButton.CommandButtonKind.POPUP_ONLY);
button.setPopupCallback(new PopupPanelCallback() {
@Override
public JPopupPanel getPopupPanel(final JCommandButton commandButton) {
return menu;
}
@Tiim
Tiim / gist:3958945
Created October 26, 2012 13:52
Zooming
g.translate(getTranslateX(), getTranslateY());
g.translate(-viewport.width / 2, -viewport.height / 2);
g.scale(getZoom(), getZoom());
g.translate((viewport.width / 2) * getZoom(), (viewport.height / 2) * getZoom());
// As soon as getZoom() is not 1.00, it breaks!
@Tiim
Tiim / PlaySound.java
Created November 16, 2012 17:53
Java Play Sound
package org.wikijava.sound.playWave;
import java.io.IOException;
import java.io.InputStream;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.SourceDataLine;
local monitor = peripheral.wrap("right");
rednet.open("top");
maxX, maxY = monitor.getSize();
curX, curY = 1,1;
print("Max X: " .. maxX .. " Max Y: " .. maxY);
names = {};
@Tiim
Tiim / Exception
Last active September 2, 2015 18:45
Exception in thread "main" org.springframework.jdbc.BadSqlGrammarException: StatementCallback; bad SQL grammar [CREATE TABLE test (id INTEGER PRIMARY KEY)]; nested exception is org.h2.jdbc.JdbcSQLException: Tabelle "TEST" besteht bereits
Table "TEST" already exists; SQL statement:
CREATE TABLE test (id INTEGER PRIMARY KEY) [42101-188]
at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:231)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:415)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:439)
at TestMain.main(TestMain.java:19)
Caused by: org.h2.jdbc.JdbcSQLException: Tabelle "TEST" besteht bereits
Table "TEST" already exists; SQL statement:
@Tiim
Tiim / alex2.py
Last active February 13, 2018 20:00
import csv
import datetime
import math
##TODO: Ändere die zeiten an denen du die mittelwerte berechnene willst
# Liste von allen zeiden von denen du das mittel willst
mittelZeiten = [{'hour': 13, 'min': 10},
{'hour': 16, 'min': 30}]
@Tiim
Tiim / Makefile
Created April 4, 2019 06:51
Makefile that compiles every source file to a executable in the bin dir. Conserves data structure.
CC = gcc
OBJDIR = bin
exec = udp/server udp/client tcp/server tcp/client
.PHONY: all clean
all: $(OBJDIR) $(exec)
clean:
rm -r $(OBJDIR)
@Tiim
Tiim / query.js
Created March 7, 2020 11:04
Query Inside JS object like lodash _.get but handles arrays as well
function queryObject(object, path) {
const parts = path.split('.');
let objects = wrapArray(object);
while (parts.length > 0 && objects.length > 0) {
const prop = parts.shift();
objects = objects
.flatMap((o) => wrapArray(o[prop]))
.filter((o) => o != null);
}
return objects;
<!DOCTYPE html>
<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
<title>Stopwatch</title>
<link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@600&display=swap" rel="stylesheet">
</head>
#!/usr/bin/env bash
# This script should be called inside a docker container
# to backup the database.
# $ ./backup.sh [hourly|daily|weekly|monthly|yearly]
# The environment variables for pg_dumpall need to be set.
set -e
# First command line arg.