Skip to content

Instantly share code, notes, and snippets.

@lucasluitjes
lucasluitjes / sse.rb
Created March 16, 2023 10:54
sinatra app that streams openai chat responses
require 'bundler/setup'
require 'dotenv'
require 'sinatra'
require 'sinatra/streaming'
require 'json'
require 'typhoeus'
set :server, 'thin' # not sure if puma also has streaming nowadays?
Dotenv.load
@lucasluitjes
lucasluitjes / auto_pop.py
Last active September 3, 2021 05:00
automatically generate a click for the talon zoom mouse every n seconds
# This script automatically generates a pop for the talon zoom mouse every n seconds,
# then another one 2 seconds later. For when you want to do a ton of clicking actions
# without getting jaw cramp. If you don't want to click, just look away within 2 seconds.
from talon import Context, Module, actions, app, cron, ctrl, imgui, noise, settings, ui
from talon_plugins import eye_mouse, eye_zoom_mouse, speech
from talon_plugins.eye_mouse import config, toggle_camera_overlay, toggle_control
# Put the following at the bottom of talon/resources/talon_plugins/eye_zoom_mouse.py
# (you will need to reapply this after every talon update)
# demo: https://www.youtube.com/watch?v=MZ3M0ePA5U4&feature=youtu.be
# this depends on the imitone software to convert whistling into midi
require "rtmidi"
midiin = RtMidi::In.new
MATCHERS = {
[0..2, 3..5] => "Page_Up",
[3..5, 0..2] => "Page_Down",
require 'parser/current'
require 'rexml/document'
class XMLAST
include REXML
attr_reader :doc
def initialize sexp
@doc = Document.new "<root></root>"
@sexp = sexp
irb> xml.xpath('*/send/hash/pair[sym[symbol-val/@value="placeholder"]]/str')
=> [s(:str, "placeholder text")]
irb> require 'parser/current'
irb> require 'rexml/document'
irb> snippet = 'f.text_field :attr, placeholder: "placeholder text"'
irb> exp = Parser::CurrentRuby.parse(snippet)
irb> xml = XMLAST.new(exp)
irb> xml.doc.write(STDOUT, 2)
<root>
<send>
<send>
<nilclass-val />
class Controller
BANKS = %w{wmii chromium thunderbird misc vim}
DIRECTIONS = [nil, 'left', 'down', 'right', nil, nil, 'up']
def process bank_index, value
bank = BANKS[bank_index]
puts "bank #{bank || bank_index}, value #{value}"
begin
puts send(:"#{bank}_bank", value) || 'command not found'