Skip to content

Instantly share code, notes, and snippets.

View byteit101's full-sized avatar

Patrick Plenefisch byteit101

  • Eastern Time Zone (GMT-5 Winter/GMT-4 Summer)
View GitHub Profile
@byteit101
byteit101 / descriptor_builder.hpp
Created January 10, 2023 06:10
TinyUSB C++20 compile-time USB descriptor builder (Pico/RP2040 edition)
#include "tusb.h"
//#include <vector>
#include <initializer_list>
#include <algorithm>
#include <array>
//#include <tuple>
#include <cstddef>
#include <type_traits>
@byteit101
byteit101 / ResourceChat.java
Last active September 19, 2022 14:55
Simple atmosphere returning errors
/*
* Copyright 2008-2022 Async-IO.org
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@byteit101
byteit101 / jrubyclassloader.rb
Last active February 1, 2022 01:54
JRuby Class loader proxy
# FXML requires loading both ruby and java classes.
# JRuby has no such single classloader builtin, so we proxy them all
# This is a minimal classloader only for classes, resources not supported
class PolyglotClassLoader < java.lang.ClassLoader
def initialize()
super(JRuby.runtime.jruby_class_loader)
end
java_signature "java.lang.Class findClass(java.lang.String name)"
def findClass(a)
# TODO: full Ruby modules?
@byteit101
byteit101 / Gen.rb
Created February 8, 2021 19:55
Concrete Java classes result
module Umm
module Paintbrush
#TODO: test self.to_java on non-super'd non-become_java'd things
class Balloons < com.test.SecondaryClass
def initialize(*args)
puts "yay, helo(i), with #{args.inspect}"
#raise "ack" #java.lang.NullPointerException.new
egads = args.length + 5
@byteit101
byteit101 / c_source.patch
Created August 29, 2020 04:40
FFI crasher sample & debug info
diff --git a/Rakefile b/Rakefile
index ce27f29..2ac712a 100644
--- a/Rakefile
+++ b/Rakefile
@@ -42,6 +42,7 @@ task :distclean => :clobber
desc "Test the extension"
task :test => [ :spec ]
+puts "hi"
let template = `<?xml version="1.0" encoding="UTF-8"?>
<?OFX OFXHEADER="200" VERSION="203" SECURITY="NONE" OLDFILEUID="NONE" NEWFILEUID="NONE"?>
<OFX>
</OFX>`;
let ofx = new DOMParser().parseFromString(template, "text/xml");
let ofxs = slop(ofx.firstElementChild);
// Note: awful. I just don't want to drag in any other libraries for one format
@byteit101
byteit101 / config.ru
Created July 6, 2019 22:26
Minimal rack server serving a cookie-protected resource. `gem install rack` followed by `rackup config.ru` to launch. Try to download the resource
run (Proc.new do |cfg|
hc = cfg["HTTP_COOKIE"] || ""
logged = hc.include? "yup"
case cfg["PATH_INFO"]
when "/"
unless logged
['200', {'Content-Type' => 'text/html'}, ['<a href="/login">Login</a><br><br><a href="/res">Resource</a>']]
else
['200', {'Content-Type' => 'text/html'}, ['<a href="/logout">Logout</a><br><br><a href="/res">Resource</a>']]
@byteit101
byteit101 / demo.rb
Created April 3, 2019 19:37
JRubyFX with interactive terminal
# usage instructions
# $ gem install pry
# $ gem install jrubyfx
# Then download and unpack lib/ in . from https://github.com/byteit101/rb-readline/tree/pty-fixes
# gather the 5 jars listed below in .
# then you can launch this with jruby demo.rb
# Note you need a javafx-enabled java build.
# Tested with jdk1.8.0_144 on Linux
# You may need to ctrl-z, kill %1 to exit.
@byteit101
byteit101 / irb_pty_mri_vs_jruby.rb
Created January 23, 2018 06:05
JRuby IRB readline issue on linux under a non-forked PTY
require 'irb'
require 'pty'
require 'ffi'
require 'rspec'
require 'rspec/core'
RSpec::Core::Runner.autorun
# patching PTY::open to comment out fnctl bug in JRuby
if defined? JRUBY_VERSION
@byteit101
byteit101 / safe.cpp
Created March 10, 2015 01:23
null pointer this
#include <iostream>
using namespace std;
class A {
public: void isNull() {
if (this == nullptr)
std::cout << "We are null" <<std::endl;
else
std::cout << "We are not null" <<std::endl;
}
};