Skip to content

Instantly share code, notes, and snippets.

View PsychedelicShayna's full-sized avatar
🐇
Writing Code & Contemplating Existence

Shayna PsychedelicShayna

🐇
Writing Code & Contemplating Existence
View GitHub Profile
@PsychedelicShayna
PsychedelicShayna / async_type.hxx
Created May 5, 2020 14:16
A wrapper around std::mutex to convert any generic type into a thread-safe one.
template<typename T>
class AsyncType {
protected:
std::mutex typeMutex;
T typeValue;
public:
const std::mutex& TypeMutex = typeMutex;
T Get() {
@PsychedelicShayna
PsychedelicShayna / eeprom_slice.hpp
Created May 26, 2020 12:27
An indexable slice type to read/write to an Arduino EEPROM based on an address range, e.g. (0, 5) = 6 bytes accessible by the slice from address 0 to 5.
class EepromSlice {
protected:
EERef* eepromReferences;
size_t referenceCount;
public:
const size_t& Size = referenceCount;
EERef At(const size_t& index) {
if(index < Size) {
@PsychedelicShayna
PsychedelicShayna / LambdaObject.hpp
Created May 31, 2020 01:26
A small container for storing and executing lambda functions, meant to emulate the basics of std::function - made for use with Arduino, since it does not include the C++ standard library.
template<typename>
class LambdaObject;
template<typename LambdaReturnType, typename... LambdaArguments>
class LambdaObject<LambdaReturnType(LambdaArguments...)> {
protected:
struct AbstractLambdaContainer {
virtual LambdaReturnType Call(LambdaArguments...) = 0;
virtual AbstractLambdaContainer* ReturnContainerCopy() = 0;
virtual ~AbstractLambdaContainer() {}
@PsychedelicShayna
PsychedelicShayna / simple_caesar_cipher.cpp
Last active July 15, 2020 01:47
A simple caesar cipher implementation using std::transform
std::string CaesarCipher(std::string string, int shift) {
std::transform(string.begin(), string.end(), string.begin(), [&shift](char character) -> char {
char head_character = (character >= 'A' && character <= 'Z') ? 'A' : ((character >= 'a' && character <= 'z') ? 'a' : '\0');
return head_character ? (head_character + (((character - head_character) + shift) % 26)) : character;
});
return string;
}
@PsychedelicShayna
PsychedelicShayna / caesar-cipher.lisp
Created July 16, 2020 06:33
A basic caesar cipher implementation in common Lisp, badly programmed probably. My Lisp "hello world".
(defun get-char-case (input-char)
(cond ((and (>= (char-code input-char) 65) (<= (char-code input-char) 90)) 'uppercase)
((and (>= (char-code input-char) 97) (<= (char-code input-char) 122)) 'lowercase)))
(defun alphabet-start (input-char) (let ((casing (get-char-case input-char)))
(if input-char (cond ((eq casing 'lowercase) 97 ) ((eq casing 'uppercase) 65)) nil)))
(defun caesar-shift-character (input-char shift-amount)
(if (alphabet-start input-char)
(code-char (+ (alphabet-start input-char) (mod (+ (- (char-code input-char) (alphabet-start input-char)) shift-amount) 26)))
@PsychedelicShayna
PsychedelicShayna / expression2.el
Created August 27, 2020 16:24
Emacs Expression2 Simple Derived Mode
(setq expression2-font-lock-keywords
(let* (
;; define several category of keywords
(e2-directives '("#include" "@name" "@inputs" "@outputs" "@persist" "@trigger" "@model" "@autoupdate"))
(e2-directives-regexp (regexp-opt e2-directives))
(e2-keywords '("if" "else" "elseif" "switch" "while" "for" "foreach" "continue" "break" "local"))
(e2-keywords-regexp (regexp-opt e2-keywords 'words))
(e2-types '("string" "number" "vector" "entity" "angle" "array" "table"))
@PsychedelicShayna
PsychedelicShayna / background.vbs
Created February 3, 2021 06:15
VBS Script that launches any given console program in the background without creating a console or displaying output.
' I hate VBS, but it's suitable for this.
' Can be tested by opening notepad then invoking: background taskkill /im notepad.exe
Set oShell = CreateObject ("Wscript.Shell")
Set args = Wscript.Arguments
Dim strArgs
strArgs = "cmd /c "
For Each arg in args
@PsychedelicShayna
PsychedelicShayna / twitch_oauth_autorefresh.rb
Created February 3, 2021 07:45
A class that auto-renews expired Twitch OAuth tokens. Calling get_token() always returns an up to date token.
class AutoRefreshingOAuthToken
def request_new_token
endpoint_uri = URI.parse('https://id.twitch.tv/oauth2/token')
endpoint = Net::HTTP.new(endpoint_uri.host, endpoint_uri.port)
endpoint.use_ssl = true
request = Net::HTTP::Post.new(endpoint_uri.path)
post_form_data = {
@PsychedelicShayna
PsychedelicShayna / cpp_streams_practice.cxx
Created February 4, 2021 18:13
Practice file for dealing with I/O streams in C++
#include <functional>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <thread>
#include <atomic>
#include <mutex>
@PsychedelicShayna
PsychedelicShayna / openssh_notes.ps1
Created November 5, 2021 02:33
Just Some Setup Notes On OpenSSH-Win64
# Default SSH Server Config Dir: C:\ProgramData\ssh
# Default SSH Client Config Dir: C:\Users\USERNAME\.ssh\
# sshd Binaries should be stored in C:\Program Files\
# And the folder permissions must be free from inherited permissions
# authorized users should have read/exec access, and admin/system should have full,
# otherwise the daemon might break.
# Bypass execution policy and run sshd installation script.
powershell.exe -ExecutionPolicy Bypass -File install-sshd.ps1