Skip to content

Instantly share code, notes, and snippets.

View swarley's full-sized avatar

Matt Carey swarley

View GitHub Profile
#include <ruby.h>
#include <ctype.h>
#define MAX_LENGTH 2000
VALUE rb_mBigBrain = Qnil;
int bigbrain_find_ideal(char *str) {
int len = strlen(str);
char* loc;
@swarley
swarley / q_to_lhd.py
Created October 3, 2019 07:10
QWERTY input to Left handed DVORAK
#! /usr/bin/python3
"""
Usage: ./qwerty_to_dvorak.py input.txt
OR cat input.txt | ./qwerty_to_dvorak.py
NOTE: This converts to LEFT HANDED DVORAK, not standard or right handed
"""
import sys
@swarley
swarley / youtube.rb
Last active March 19, 2019 15:25
A YouTube example container for discordrb
# frozen_string_literal: true
# Use `bot.include! YouTubeContainer` to use this in your CommandBot
# This requires you to have youtube-dl installed as well as other voice prerequisites.
#
# This example is extremely slow, but could potentially be sped up if the youtube-dl
# `-o -` option actually worked. If you can get it to work, hit me up because other people's
# older examples always fail when I run them locally.
require 'discordrb'
if file.respond_to?(:read)
if spoiler
filename ||= File.basename(file.path)
filename = 'SPOILER_' + filename unless filename.start_with? 'SPOILER_'
end
# https://github.com/rest-client/rest-client/blob/v2.0.2/lib/restclient/payload.rb#L160
file.define_singleton_method(:original_filename) { filename } if filename
end
@swarley
swarley / worst_s_exp_parser_literally_ever_conceived.rb
Created February 6, 2019 03:00
worst_s_exp_parser_literally_ever_conceived.rb
def lex(str, tokens=[])
str.is_a?(String) ?
lex(StringScanner.new(str))
:
(str.scan(/\(/) ?
lex(str, tokens << :l_paren)
:
(str.scan(/\)/) ?
lex(str, tokens << :r_paren)
:
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.5") && ENV['OS'] =~ /Windows/i
module RestClient
module Utils
def self.cgi_parse_header(line)
parts = _cgi_parseparam(';' + line).to_a
key = parts[0]
pdict = {}
while (p = parts.shift)
i = p.index('=')
module RestClient
module Utils
def self.cgi_parse_header(line)
parts = _cgi_parseparam(';' + line).to_a
key = parts[0]
pdict = {}
while (p = parts.shift)
i = p.index('=')
if i
# from int helper
struct Int
def bit_set?(num : Int) : Bool
return (bit num) == 1
end
end
struct UInt8
def bit_set?(num : Int) : Bool
return (bit num) == 1
@swarley
swarley / TMX Loader Assets
Last active December 16, 2015 10:08
A TMX loader library for Lua LOVE. A proper drawing and event framework needs to be implemented, but tiles are loaded into memory correctly already.
https://dl.dropboxusercontent.com/u/36785145/tilemap2.png
require "trie"
trie = Trie.new
dict = {}
File.open("/usr/share/dict/american-english") do |f|
lines = f.read.split("\n")
lines.map(&:chomp).each {|word| (dict[word.size]||=Trie.new).add word, 1 }
end
letters = "psylyrcytyrglhltyprpsyyssysty"