Skip to content

Instantly share code, notes, and snippets.

@tehbeard
tehbeard / complex-reflection.php
Created January 19, 2023 21:07
Testing classes against complex types
<?php
/*
Function to test a class type against a potentially complex type
Should handle Disjunctive Normal Form Types as well (A&B)|C|null
*/
function matchesType(string $class, ReflectionNamedType|ReflectionIntersectionType|ReflectionUnionType $type): bool
{
if ($type instanceof ReflectionNamedType) {
return is_a($class, $type->getName(), true);
} else if ($type instanceof ReflectionIntersectionType) {
@tehbeard
tehbeard / fullTextDB.ts
Created March 27, 2021 16:29
Mucking around with Full text search and IndexedDB.
import { openDB, IDBPDatabase, DBSchema, IDBPTransaction,IDBCursorDirection } from "idb/with-async-ittr";
import { stemmer } from "./stemmer";
const TBL_ENTRY = "FTSEntry";
const IDX_BY_SCORE = "byScore";
const IDX_BY_DOC_ID = "byDocId";
type FTSEntry = { id: any, word: string , count: number };
interface FullTextSchema extends DBSchema {
@tehbeard
tehbeard / gist:d91c0cbfcc438ad7af4c310462f6f961
Created October 21, 2016 20:58
Minecraft PE 0.16 - Addon Component name list
minecraft:identifier
minecraft:collision_box
minecraft:projectile
minecraft:type_family
minecraft:fall_damage
minecraft:movement
minecraft:health
minecraft:nameable
minecraft:loot
minecraft:attack
@tehbeard
tehbeard / minecraft-head-canvas.html
Created March 7, 2016 22:00
Old minecraft canvas head script.
<!DOCTYPE html>
<html>
<head>
<title>Minecraft heads using Canvas 2D</title>
<script src='http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js'></script>
<style>
canvas{
width: 320px;
height: 320px;
/*border: 2px solid black;*/
@tehbeard
tehbeard / refs.js
Created January 15, 2016 23:44
Experiments with js-git
Trying to understand generators and yield, and create a listRefs() implementation for file backed repos.
@tehbeard
tehbeard / example.js
Created October 6, 2015 12:59
node ws->express passthrough
var httpServer = http.createServer(app);
var ServerResponse = http.ServerResponse;
var wsServer = new WebSocketServer({ server: httpServer });
wsServer.on('connection', function(ws) {
var response = new ServerResponse(ws.upgradeReq);
response.writeHead = function (statusCode) {
if (statusCode > 200) ws.close();
@tehbeard
tehbeard / parseVideoId.js
Created September 10, 2014 15:44
improved youtube/vimeo video id parser.
// Improved variant of http://stackoverflow.com/questions/5612602/improving-regex-for-parsing-youtube-vimeo-urls/22763925#22763925
function parseVideoId(url){
var res = url.match(/(?:http:|https:|)\/\/(?:player.|www.)?(vimeo\.com|youtu(?:be\.com|\.be|be\.googleapis\.com))\/(?:video\/|embed\/|watch\?v=|v\/)?([A-Za-z0-9._%-]*)(\&\S+)?/);
var type = null;
if(res[1].indexOf('youtu') > -1){
type = 'youtube';
} else if(res[1].indexOf('vimeo') > -1){
type = 'vimeo';
}
return {
@tehbeard
tehbeard / gist:c8adc5be97311d13e78f
Created June 8, 2014 00:56
Promise w/o being stuck inside it.
function getDeferred(){var _r,_e;var _p = new Promise(function(r,e){_r=r;_e=e;});_p.resolve = _r;_p.reject = _e;return _p;}
2013-11-27 16:21:34 [INFO] [BeardAch] Loading Data Adapters
2013-11-27 16:21:35 [INFO] [BeardAch] Installing default triggers and rewards
2013-11-27 16:21:35 [WARNING] [BeardAch] [counter] Increment counter depends on BeardStat which is not found, this reward has been disabled. This may cause errors if an achievement is built using this.
2013-11-27 16:21:35 [WARNING] [BeardAch] [subgroup] (DroxPerms) add subgroup depends on DroxPerms which is not found, this reward has been disabled. This may cause errors if an achievement is built using this.
2013-11-27 16:21:35 [WARNING] [BeardAch] [promote] (DroxPerms) Promote along track depends on DroxPerms which is not found, this reward has been disabled. This may cause errors if an achievement is built using this.
2013-11-27 16:21:35 [WARNING] [BeardAch] [money] (vault) Give money depends on Vault which is not found, this reward has been disabled. This may cause errors if an achievement is built using this.
2013-11-27 16:21:35 [WARNING] [BeardAch] [vaultaddgroup] (Vau
public class PasteCommand extends CommandBase {
private final SchematicFile schFile;
public PasteCommand(SchematicFile schFile) {
this.schFile = schFile;
}
@Override
public String getCommandName() {