Skip to content

Instantly share code, notes, and snippets.

View benjjo's full-sized avatar
💣

Ben McGUffog benjjo

💣
View GitHub Profile
@benjjo
benjjo / lxterm-autostart.desktop
Created June 10, 2021 09:24
A small script to display the IP address of your Raspberry Pi, on start up. Requires figlet, lxterm
[Desktop Entry]
Encoding=UTF-8
Name=Terminal autostart
Comment=Start a terminal and list directory
Exec=/usr/bin/lxterm -e 'sleep 60 ; figlet `hostname -I` ; sleep 600'
@benjjo
benjjo / northwind.ddf
Last active April 19, 2021 12:43
Postgres database for the northwind customers SQL example used in W3Scools SQL tutorial
DROP TABLE IF EXISTS customers;
CREATE TABLE customers (
CustomerID varchar(5) NOT NULL,
CustomerName varchar(40) NOT NULL,
ContactName varchar(30) NOT NULL,
Address varchar(60) NOT NULL,
City varchar(15) NOT NULL,
PostalCode varchar(10) NOT NULL,
Country varchar(15) NOT NULL );
@benjjo
benjjo / makeEmptyCSV.py
Created February 8, 2021 10:32
creates an empty df with the date range specified, indexed by date and incrementing in seconds. Writes to a csv file.
def main():
def makeEmptyDFWithDateRange(start_date='14:45:24 2021-02-02', end_date='17:05:24 2021-02-05', set_point=22):
index = pd.date_range(start_date, end=end_date, freq='S')
columns = ['Set Point']
df = pd.DataFrame(index=index, columns=columns)
df['Set Point'] = df['Set Point'].fillna(set_point)
df.index.name = 'Time date'
df.to_csv('emptyDateRange.csv')
if __name__ == "__main__":
@benjjo
benjjo / runTest.py
Last active December 19, 2020 20:16
Simple test fnction
failed = 0
ran = 0
def test(name, actual, expected):
"""Report if test passed or failed."""
global ran, failed
if actual == expected:
print(name, 'OK')
else:
print(name, 'FAILED: got', actual, 'instead of', expected)
package org.kodejava.example.swing;
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;
public class FrameIconExample extends JFrame {
@benjjo
benjjo / bufferedFileWirter.java
Last active April 21, 2020 21:48
Example of a buffered file writer
/**
* Writes the Object data from the Objects ArrayList into a CSV file.
* Data is written to the file in the following format:
*
* String,int,String,int
* String,int,String,int
*/
public void writeObjectData()
{
String pathName = FileChooser.getFilename(); // pick a file chooser and change this.
@benjjo
benjjo / bufferedScanner.java
Last active April 21, 2020 21:50
Example of a buffered file reader using a buffered scanner.
/**
* Extracts comma separated values from an external file. The method readObjectData()
* expects to find employee data on each line separated by a comma. The pattern example outlined here:
*
* String,int,String,int
* String,int,String,int
*
* The above csv inputs are returned by Scanner as:
* - Name of employee (String)
* - Years employed (int)
import javax.swing.JCheckBox;
import javax.swing.JOptionPane;
public class ConfirmDialog1b {
public static void main(String[] args) {
JCheckBox check = new JCheckBox("Tick me");
Object[] options = {'e', 2, 3.14, 4, 5, "TURTLES!", check};
int x = JOptionPane.showOptionDialog(null, "So many options using Object[]",
@benjjo
benjjo / Main.java
Last active March 8, 2020 09:46
Dwarf Quoter - Java edition
import javax.swing.*;
import java.util.ArrayList;
import java.util.Random;
/**
* The all amasing Dwarf Quoter is back! JAVA STYLE!!
* Hooray for everything.
*
* @author Benjo
* @version 1.6
@benjjo
benjjo / Sorter.java
Last active February 26, 2020 13:16
Sorts an mapped array
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;
public class Sorter {
SortedMap<Integer, String> sm = new TreeMap<>();
Set s = sm.entrySet();
/**