Skip to content

Instantly share code, notes, and snippets.

from collections import defaultdict
class ObservableAttr:
class _unset: pass
def __init__(self, default=_unset):
self.default = default
self.name = "unnamed"
def __set_name__(self, cls, name):
@fre-sch
fre-sch / dnd.jsx
Created July 8, 2019 05:20
Dnd reorderable list in Preactjs
const lorem = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua."
class DndListItem extends Component {
render({onDragStart, children}) {
return (
<div class="dnd-list-item"
draggable="true"
onDragStart={onDragStart}>
{children}
</div>
@fre-sch
fre-sch / first.lua
Last active March 28, 2020 11:53
luabindingsexplore
-- scripts/first.lua
myvars = {}
Hooks.Init = function ()
print("first.lua Hooks.Init")
myvars.foo = "first foo"
end
Hooks.MonsterHit = function (e)
print("first.lua MonsterHit", e.monster.health)
garglebla()
@fre-sch
fre-sch / showmodal.reds
Created February 5, 2021 14:22
Cyberpunk 2077 - Showing some (debug) information in redscripts
let evt = new NotifyShardRead();
evt.title = "Title for modal";
evt.text = "Text for modal;
/* NotifyShardRead has other properties that can be left unset */
let gi: GameInstance = player.GetGame(); /* any GameObject provides GetGame() -> GameInstance */
GameInstance.GetUISystem(gi).QueueEvent(evt);
@fre-sch
fre-sch / maybe.py
Created February 24, 2021 08:30
Chainable None-Aware Wrapper
from dataclasses import dataclass
class Maybe:
def __init__(self, value):
self.value = value
def bind(self, f):
if self.value is None:
return self
@fre-sch
fre-sch / Inventory-Mover.ahk
Last active January 2, 2022 19:05
Autohotkey script to make moving inventory items in Star Citizen (3.16) easier
#NoEnv
#Warn
SetWorkingDir %A_ScriptDir%
SendMode, Input
SetMousedelay, 20
SetMousedelay, 20, Play
;MoveXOffset := 43
@fre-sch
fre-sch / Program.cs
Created April 23, 2022 15:07
Space Engineers Toggle Block on amounts
class Program {
// item name that has to be taken into account for level check
// string itemNameToCheck = "MyObjectBuilder_Ore/Ice";
string itemNameToCheck = "Ice";
// tag for blocks that will be switched off and on
string tag = "[TOGGLE_LEVEL]";
// do not change below
@fre-sch
fre-sch / h.js
Created August 27, 2022 09:13
trying syntax simplifications for using preact h without jsx
function (type, props, children) {
// placeholder for preact h
return {type, props, children}
}
var ElementPropSetter = {
get: function(target, name, proxy) {
return function(...values) {
if (name == "class")
target.props.class = values.join(" ")
@fre-sch
fre-sch / h.js
Last active August 27, 2022 09:21
parser for alternative syntax to use preact h
@{%
// Moo lexer documention is here:
// https://github.com/no-context/moo
const moo = require("moo")
const lexer = moo.compile({
ws: {match: /\s+/, lineBreaks: true},
literal_id: {
match: /#[a-zA-Z_-][a-zA-Z_0-9_-]*/,
value: s => s.slice(1)
@fre-sch
fre-sch / preact-hooks-utils.js
Last active November 21, 2022 09:31
Some utils for dealing with preact/hooks
/*
Add some structure to the `[state, dispatch]` pattern of `useReducer`.
`useActionReducer` provides `dispatch(action: str, data: any)`, and wraps
it to call `handler[action](state, data)`
Example object based handler:
const todoListHandler = {
text: (state, {text}) => {