Skip to content

Instantly share code, notes, and snippets.

@dometto
dometto / example.sms
Last active July 8, 2025 08:11
Linbox: compiling a simple matrix operation example
4 4 M
1 1 1
1 2 2
3 2 4
3 4 5
0 0 0
@dometto
dometto / benchmark.rb
Created January 24, 2023 18:49
Benchmark for gollum-lib performance related to https://github.com/gollum/gollum-lib/pull/437
require 'gollum-lib'
require 'benchmark'
def do_benchmark(*args)
Benchmark.bm(10) do |x|
x.report { 5.times do
send(*args)
end }
end
end
@dometto
dometto / capture_r.rb
Last active February 15, 2021 22:37
Dockerized calling R from Ruby reading from stdin
require 'open3'
require 'docker'
require 'stringio'
content = <<EOF
```{r first_r_chunk}
vec <- c(1, 2, 3)
cat(readLines("/etc/passwd"), sep="\n")
print(vec)
#!/usr/bin/env ruby
#coding:utf-8
require 'optparse'
require 'pathname'
require 'rubygems'
REPO = ARGV[0] || Dir.pwd
wiki_options = {}
@dometto
dometto / scan_test.rb
Created September 20, 2019 12:14
Parse user query string into regex
query = '+"XYZ" foo -"bar" "hobbit fan"'
search_terms = []
absent = []
present = []
query.scan(/([-+])?"([^"]+)"|(\S+)/) do
term = Regexp.last_match[2] || Regexp.last_match[3]
term = Regexp.escape(term)
@dometto
dometto / page.rb
Created May 16, 2019 23:24
Alternate find_sub_pages method for gollum
# Loads sub pages. Sub page names (footers, headers, sidebars) are prefixed with
# an underscore to distinguish them from other Pages. If there is not one within
# the current directory, starts walking up the directory tree to try and find one
# within parent directories.
def find_sub_pages(subpagenames = SUBPAGENAMES, map = nil)
puts "FINDING SUB PAGES"
subpagenames.each{|subpagename| instance_variable_set("@#{subpagename}", nil)}
return nil if self.filename =~ /^_/ || ! self.version
valid_names = %r{^_#{subpagenames.map(&:capitalize).join("|")}}
@dometto
dometto / gist:aa030e38c9405ca55483602495787af6
Last active April 27, 2017 22:09
Gollum 5.x route proposal
get '/'
get '/*'
get %r{/(.+?)/([0-9a-f]{40})} # Specific version of a page or file
namespace '/gollum' do
get '/last-commit-info'
get '/emoji/:name'
get '/data/*' # Maybe rename to 'raw'?
get '/edit/*'
get '/history/*'
@dometto
dometto / example.sh
Last active April 20, 2017 18:35
Parsing elements and attributes from MathML Elements and Attributes Reference List
# Parse elements from the Elements Reference into a ruby array (to construct a `Sanitize` gem hash for `gollum`):
# https://developer.mozilla.org/en-US/docs/Web/MathML/Element
# See https://github.com/gollum/gollum-lib/pull/266
# Step 1: copy the *source* of https://developer.mozilla.org/en-US/docs/Web/MathML/Element (hit the 'Edit' button), at least of the part of the page containing the alphabetical element list.
# Step 2: save this as `mathml_elements.txt`
# Step 3:
grep MathMLElement mathml_elements.txt | awk -F'"' '{print $2}' > mathml_elements
# Step 4:
for line in `cat mathml_elements`; do echo "'$line',"; done
# Step 5 copy/paste result into ruby array (be sure to remove the comma after the last element):
@dometto
dometto / config.ru
Last active November 10, 2015 23:42
# This file is used by Rack-based servers to start the application.
require 'sinatra'
require ::File.expand_path('../config/environment', __FILE__)
JAVA_FIRST_RUN = java.lang.System.getProperty('setup_db')
map '/' do
if JAVA_FIRST_RUN
run RepotagConfig
else
<p><a href="Home">&raquo; JRuby Project Wiki Home Page</a>
<h1>Embedding JRuby</h1>
Using Java from Ruby is JRuby's best-known feature---but you can also go in the other direction, and use Ruby from Java. There are several different ways to do this. You can execute entire Ruby scripts, call individual Ruby methods, or even implement a Java interface in Ruby (thus allowing you to treat Ruby objects like Java ones). We refer to all these techniques generically as "embedding." This section will explain how to embed JRuby in your Java project.
</p>
<p><table id="toc" class="toc" summary="Contents"><tr><td><div id="toctitle"><h2>Table of Contents</h2></div><ul></li><li><a href="<a class="tweet-url hashtag" href="https://twitter.com/#!/search?q=%23Red_Bridge_JRuby_Embed" rel="nofollow" title="#Red_Bridge_JRuby_Embed">#Red_Bridge_JRuby_Embed</a>">Red Bridge (JRuby Embed)</a><ul><li><a href="<a class="tweet-url hashtag" href="https://twitter.com/#!/search?q=%23Features_of_Red_Bridge" rel="nofollow" title="#Feature