Skip to content

Instantly share code, notes, and snippets.

View narrowtux's full-sized avatar
:shipit:
Shipping it

Moritz Schmale narrowtux

:shipit:
Shipping it
View GitHub Profile
@narrowtux
narrowtux / LJVehicleListener.java
Created October 22, 2011 13:04
Preload chunks
package com.narrowtux.longjourney;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.event.vehicle.VehicleListener;
import org.bukkit.event.vehicle.VehicleMoveEvent;
import org.bukkit.util.Vector;
public class LJVehicleListener extends VehicleListener {
@narrowtux
narrowtux / Code where I create it.java
Created November 21, 2011 20:17
GenericPolygon.java
p.addPoint(0, 0, new Color(0xffffffff));
p.addPoint(0, 10, new Color(0xffffffff));
p.addPoint(10, 10, new Color(0xffffffff));
p.addPoint(10, 0, new Color(0xffffffff));
Contianer c = new GenericContainer();
c.setLayout(new VerticalLayout());
c.setGeometry(5,5,width - 10, height - 10);
c.attachWidget(addon, new GenericLabel("Title")); //Same as c.getLayout().addItem(new WidgetItem(widget));
c.getLayout().addItem(new SpacerItem(0, 25, 0, Integer.INFINITY)); //minWidth, minHeight, maxWidth, maxHeight
Button b = new GenericButton("Done");
b.setMaxWidth(200);
c.attachWidget(addon, b);
c.getLayout().setAlign(WidgetAnchor.TOP_CENTER);
screen.attachWidget(addon, c);
@narrowtux
narrowtux / ComponentHolder.java
Created September 24, 2012 21:09
Endless event-style methods for Components
public class ComponentHolder {
// ...
public void onEvent(String methodName) {
for (Component c:getComponents()) {
if (c.getClass().hasMethod(methodName)) {
c.getClass().getMethod(methodName).execute(c);
}
}
}
// ...
package de.hs.settlers.util;
import java.lang.reflect.Field;
import javafx.beans.property.Property;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.ObservableSet;
import javafx.collections.SetChangeListener;
defmodule Range
def range(num, min_value, max_value) do
num
|> min(max_value)
|> max(min_value)
end
end
@narrowtux
narrowtux / collection.ex
Last active November 15, 2016 08:04
remove and difference functions for Enum
defmodule Coll do
@doc """
Removes all values from the subject
iex> Coll.remove([1, 2, 3], [2, 3])
[1]
iex> Coll.remove([1, 2], [2, 3, 4])
[1]
"""
def descendants(organization_id, truncation, filter \\ from o in __MODULE__) do
sub = from os in filter, where: os.organization_id == ^organization_id and os.truncation == ^truncation, select: [os.organization_id, os.parent_organization_id, os.id, ^1, os.datetime, os.truncation]
query = from outer in __MODULE__,
join: t in fragment("""
WITH RECURSIVE search_orgs(organization_id, parent_organization_id, id, depth, datetime, truncation) AS (
?
UNION ALL
SELECT
o.organization_id,
def descendants(organization_id, truncation, filter \\ from o in __MODULE__) do
sub = from os in filter, where: os.organization_id == ^organization_id and os.truncation == ^truncation, select: [os.organization_id, os.parent_organization_id, os.id, ^1, os.datetime, os.truncation]
query = from outer in __MODULE__,
join: t in fragment("""
WITH RECURSIVE search_orgs(organization_id, parent_organization_id, id, depth, datetime, truncation) AS (
?
UNION ALL
SELECT
o.organization_id,
def descendants(organization_id, truncation, filter \\ from o in __MODULE__) do
sub = from os in filter, where: os.organization_id == ^organization_id and os.truncation == ^truncation, select: [os.organization_id, os.parent_organization_id, os.id, ^1, os.datetime, os.truncation]
query = from outer in __MODULE__,
join: t in fragment("""
WITH RECURSIVE search_orgs(organization_id, parent_organization_id, id, depth, datetime, truncation) AS (
?
UNION ALL
SELECT
o.organization_id,