Skip to content

Instantly share code, notes, and snippets.

View andrew-wilkes's full-sized avatar

Andrew Wilkes andrew-wilkes

View GitHub Profile
@andrew-wilkes
andrew-wilkes / array-to-string.gd
Last active May 21, 2021 07:18
Convert string array to string
func array_to_string(a: Array) -> String:
return PoolStringArray(a).join("\n")
@andrew-wilkes
andrew-wilkes / center-scene.gd
Last active May 20, 2021 05:24
Center the scene on the screen when not main scene in Godot
# Add to main autoload file
func _ready():
# Check the last child node of the root
var scene_node = get_node("/root").get_children()[-1]
if scene_node.filename != ProjectSettings.get_setting("application/run/main_scene"):
var property = "position"
if scene_node is Control:
property = "rect_" + property
set(property, get_viewport().size / 2)
@andrew-wilkes
andrew-wilkes / quit.gd
Created May 18, 2021 09:03
Global code to quit Godot game
func _input(_event):
if Input.is_action_just_pressed("ui_cancel"):
get_tree().quit()
@andrew-wilkes
andrew-wilkes / ViewPortImage.gd
Last active May 12, 2021 11:03
Capture viewport to image in Godot
extends Node2D
func _ready():
yield(VisualServer, "frame_post_draw")
var img = $ViewportContainer/Viewport.get_texture().get_data()
img.flip_y()
img.save_png("vp_image.png")
img = $VP3D/Viewport.get_texture().get_data()
@andrew-wilkes
andrew-wilkes / tunnel.php
Created March 20, 2021 11:18
PHP Script to Start and Stop a Reverse SSH Tunnel from a Remote Server
<?php
/*
This script is placed on a server or computer that remains powered up and is run via a
crontab job at regular intervals to ensure that the reverse SSH tunnel that it creates
remains active or gets killed according to the text value contained in a file on a remote
server that tells it whether to start or kill the process.
That file contains "on" or "off" text that is accessible via a URL.
On that server, the user should be able to SSH to it and change the command value in the file.
@andrew-wilkes
andrew-wilkes / decryptor.go
Created March 7, 2021 12:00
File decryption using go
package main
# This decrypts a file that was encrypted with encryptor where the file name was appended with .enc
import (
"crypto/aes"
"crypto/cipher"
"fmt"
"io/ioutil"
"os"
@andrew-wilkes
andrew-wilkes / encryptor.go
Created March 7, 2021 11:56
File encryption using go
package main
import (
"crypto/aes"
"crypto/cipher"
"crypto/rand"
"fmt"
"io"
"io/ioutil"
"os"
@andrew-wilkes
andrew-wilkes / winsize.gd
Last active December 19, 2020 10:47
Godot in Windows set window size and position
func _ready():
if OS.get_name() == "Windows":
var screen_size = OS.get_screen_size()
var window_size = OS.get_window_size()
OS.set_window_position(Vector2((screen_size.x - window_size.x) * 0.5, 0))
OS.set_window_size(Vector2(window_size.x, screen_size.y - 75)) # Allow for the tray bar
@andrew-wilkes
andrew-wilkes / computer.c
Created December 13, 2020 10:25
Arduino Cycling Computer
/*
* Bicyle computer Arduino Uno code
* Author: Andrew M Wilkes
* 2016-08-12
*/
/*
* Notes
* Switch/sensor debounce is implemented by assigning an INT value to the switch variable that is set on the initial falling edge of the switch.
* The switch action is then ignored until the value has been counted down to zero.
@andrew-wilkes
andrew-wilkes / text-overlay.gd
Created November 30, 2020 10:02
Add a Line2D above tagged ranges of text in a Label in Godot
extends Control
# Scene structure:
# Main (Control Node)
# - HBox
# -- Multi-line Text label of 400px min width containing a bunch of text
# -- Control node that expands horizontally
# c (canvas node)
export var token = "#" # Marks start and end points of text to draw a line over