Skip to content

Instantly share code, notes, and snippets.

View outsider69's full-sized avatar
🥷

Matthew Malone outsider69

🥷
  • Eau Claire Wisconsin 54703
View GitHub Profile
@mittens13
mittens13 / LocalDateTime.java
Last active December 3, 2024 16:40
[LocalDateTime] #Java
* Return millis since epoch in UTC
* */
static long getUTCtimestamp(int day, int month, int year,int hour){
LocalDateTime ldt = LocalDateTime.of(year,month,day,hour,0);
return ldt.atOffset(ZoneOffset.UTC).toInstant().toEpochMilli();
}
/**
* Get current zone as
* */
@mittens13
mittens13 / SubscribeToBVector.java
Created February 21, 2022 07:36
[Subscribe Niagara] Example implementation of subscribing to an BComponent to receive the changed callback #Niagara #BVector #Subscribe
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Example on how to subscribe to a BVector and handle its events.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Example of a BVector containing some setpoints/properies
*
* Add 3 BInteger properties to BVector
* prio_1
* prio_2
@mittens13
mittens13 / EnumStateMachine.java
Created February 4, 2022 21:03
[StateMachine]
public enum State {
S1 {
@Override
State doSomething() {
// Do something useful
return S2;
}
},
S2 {
@mittens13
mittens13 / Demo.java
Created February 4, 2022 21:02
[MultiThreading] #Java #MultiThreading
public class Main {
public static final int MAX_PW=9999;
public static void main(String[] args) throws InterruptedException {
/**Set a random pw for vault*/
Random rn = new Random();
Vault vault = new Vault(rn.nextInt(9999));
/**Start all threads*/
@mittens13
mittens13 / HttpGet.java
Created February 1, 2022 15:15
[HttpClient] #Java #HttpGet #HttpPost
////////////////////////////////////////////////////////////////////////////////////////////////////
// Using default java.net package
////////////////////////////////////////////////////////////////////////////////////////////////////
public class HttpGetSnippet {
/**
* Performs HTTP GET request.
*
* @param uri the URI of the connection
* @return response object
@mittens13
mittens13 / FindMax.java
Created February 1, 2022 15:10
[Array] #Java #Array
/**
* Returns the maximum integer from the array using reduction.
* @param arr the array of integers (not null)
* @return the maximum element from the array
*/
public static int findMax(int[] arr) {
return Arrays.stream(arr).reduce(Integer.MIN_VALUE, Integer::max);
}
public static double findMax(double[] arr) {
@mittens13
mittens13 / 1_TdLinkMessage.java
Last active December 3, 2024 16:40
[BDriver] Implementation of an NDriver using niagara. Auo generate a new driver template through the workbench -> tools -> new driver module #Niagara #Driver
/**
* 1. workbench -> tools -> new driver -> Ndriver
* 2. After creating the driver, add a dependency if needed to "trafficDriver-rt.gradlle" (see page 394)
*/
/**
* TdLinkMessage streams data to and from a byte array representation.
*/
@mittens13
mittens13 / Q1.java
Created February 1, 2022 14:28
[BQL] Niagara query example implementation #Niagara #Bql
/**
example 1:
The result of a "select" query is always a BITable. The items returned depend on the query.
If the projection is omitted for a local query, the result is a collection of objects in the extent that matched the predicate requirements:
*/
BOrd ord = BOrd.make("slot:/foo/bar|bql:select * from control:NumericPoint");
BITable result = (BITable)ord.resolve(base).get();
TableCursor c = result.cursor();
@mittens13
mittens13 / Widget.java
Created February 1, 2022 14:26
[BWidget] TODO - uitbreiden par 8.1
//if you want to create a widget you create a java wrapper class to comminucate with the javascript and css script
//this wrapper class will be an agent on the controller to add its functionality
@NiagaraSingleton
@NiagaraType (
agent = @AgentOn(
types = {"devTrafficLights:TrafficLightController"}
)
)
@mittens13
mittens13 / BSimpleJob.java
Created February 1, 2022 14:24
[BSimpleJob] Jobs are used to manage tasks which run asynchronously in the background, but require user visibillity. For example: Long running upload/download commands, device/point discovery or batch commands. Jobs can be monitored and canceled via standard workbench tools. #Niagara #Async
/**
* BSimpleJob provides base implementation for async operations
* that require user visibillity.
* For example: long running upload/download commands.
**/
@NiagaraType
public class BExampleJob extends BSimpleJob {