Skip to content

Instantly share code, notes, and snippets.

View samuelmaddock's full-sized avatar

Sam Maddock samuelmaddock

View GitHub Profile
@samuelmaddock
samuelmaddock / preload-custom-element.ts
Last active September 7, 2023 03:00
Define a custom element in an Electron preload script.
contextBridge.exposeInMainWorld('api', {
click() {
console.log('clicked');
},
});
function mainWorldScript() {
const api: any = (window as any).api;
window.customElements.define(
@samuelmaddock
samuelmaddock / bind-all-keys.cpp
Created November 18, 2016 01:33
Unreal Engine 4 UE4 Hack to bind a delegate to all key presses. This allows for multiple keys to be pressed down at once without blocking events.
// example.h
DECLARE_DYNAMIC_DELEGATE_TwoParams(FBindAllKeysDelegate, const FKey&, Key, bool, bKeyPressed);
// example.cpp
void UExampleStatics::BindAllKeyInputActions(AActor *Actor, const FBindAllKeysDelegate& Delegate)
{
// Get input component from actor
UInputComponent *InputComponent = Actor->InputComponent;
if (InputComponent == nullptr) return;
@samuelmaddock
samuelmaddock / .editorconfig
Created January 13, 2016 03:55
UE4 EditorConfig file
# EditorConfig is awesome: http://EditorConfig.org
# top-most EditorConfig file
root = true
# Windows newlines with a newline ending every file
[*]
end_of_line = crlf
insert_final_newline = true
@samuelmaddock
samuelmaddock / srcds_fastdl.bat
Last active March 7, 2021 23:58
Simple FastDL script written using Python 2.7.3 with the bz2 library.
start srcds_fastdl.py "/source" "/target"
@samuelmaddock
samuelmaddock / js-runtime-json-interface.js
Last active February 29, 2020 16:07
Dumps a TypeScript-like JSON interface of runtime JavaScript objects.
; (function (targetObj) {
const STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/gm
const ARGUMENT_NAMES = /([^\s,]+)/g
const getParamNames = func => {
var fnStr = func.toString().replace(STRIP_COMMENTS, '')
var result = fnStr.slice(fnStr.indexOf('(') + 1, fnStr.indexOf(')')).match(ARGUMENT_NAMES)
if (result === null) result = []
return result
}
@samuelmaddock
samuelmaddock / extension-background-apis-enumerated.json
Last active February 29, 2020 16:06
Enumeration of available Chrome APIs in extension background pages using Electron v9.0.0-beta.1
// generated using
// https://gist.github.com/samuelmaddock/fb54ddc47b7a958ded1f799861239a87
{
"alarms": {
"onAlarm": {
"addListener": "() => any",
"removeListener": "() => any",
"hasListener": "() => any",
"hasListeners": "() => any",
"dispatch": "() => any"
@samuelmaddock
samuelmaddock / electron-extension-projects.md
Last active December 10, 2019 02:44
Electron Chrome extension implementations

Metastream Extension Installation

With Google Chrome installed

  1. Find and install extension on the Chrome Webstore. Remember the ID at the end of the URL (e.g. https://chrome.google.com/webstore/detail/ublock-origin/cjpalhdlnbpafiamejdnhcphjbkeiagm).
  2. Navigate to Chrome's extensions directory.
  3. Copy the extension directory with the same name as the ID from step 1.
  4. Paste extension into Metastream's extension directory.

Without Google Chrome installed

  1. Find Chrome extension on the Chrome Webstore and copy the URL.
@samuelmaddock
samuelmaddock / compile-loader.js
Created April 19, 2018 23:38
webpack code to string loader with child compiler
import loaderUtils from 'loader-utils';
import SingleEntryPlugin from 'webpack/lib/SingleEntryPlugin';
/** StringLoader */
export default function loader() {}
export function pitch(request) {
const options = loaderUtils.getOptions(this) || {};
if (!this.webpack) {
@samuelmaddock
samuelmaddock / archive-exports.sh
Last active January 14, 2018 03:33
Swarm remote connection test
export ARCHIVE_KEY='deadbeafdeadbeafdeadbeafdeadbeafdeadbeafdeadbeafdeadbeafdeadbeaf'