Skip to content

Instantly share code, notes, and snippets.

require 'rbnacl'
# Libsodium provides "raw" ChaCha20, but it’s not in RbNaCl. We can work round that with
# this little class.
class ChaCha20Stream
extend RbNaCl::Sodium
sodium_function :get_stream,
:crypto_stream_chacha20,
%i[pointer ulong_long pointer pointer]
# The relative letter frequencies in English. This is taken from Wikipedia
# (https://en.wikipedia.org/wiki/Letter_frequency) and is based on the Concise
# Oxford dictionary.
ENGLISH_FREQ = [8.167, 1.492, 2.782, 4.253, 12.702, 2.228, 2.015, 6.094, 6.966, 0.153, 0.772, 4.025, 2.406, 6.749, 7.507, 1.929, 0.095, 5.987, 6.327, 9.056, 2.758, 0.978, 2.361, 0.150, 1.974, 0.074]
# Reverse a shift of a single letter by another letter.
# 65 is the ASCII value of `A`, so subtracting 65 from the letter's ord
# value gives a number between 0-25, which we can then do arithmetic
# modulo 26 on.
def unshift(letter, shift_letter)

Calling mark at end of scalar of interest produces something like:

{"line1"=>{"value"=>"line2", "line"=>4},
  "line4"=>{"value"=>"line5\nline6\n", "line"=>7}}

Calling mark at end of previous scalar produces something like:

{"line1"=>{"value"=>"line2", "line"=>1},

"line4"=>{"value"=>"line5\nline6\n", "line"=>4}}

<!doctype html>
<title> </title>
<p class="0">
@mattwildig
mattwildig / gist:5305812
Last active December 15, 2015 18:39
Rendered new haml autoclose/self-closing/empty tags docs

Empty (void) Tags: /

The forward slash character, when placed at the end of a tag definition, causes Haml to treat it as being an empty (or void) element. Depending on the format, the tag will be rendered either without a closing tag (:html4 or :html5), or as a self-closing tag (:xhtml).

Taking the following as an example:

%br/

@mattwildig
mattwildig / bin-foo
Last active December 14, 2015 02:29
Gem with dependencies
#!/usr/bin/env ruby
#this should be in bin/ dir - gist doesn't allow directories anymore
require 'haml'
puts Haml::VERSION
@mattwildig
mattwildig / example.haml
Created December 14, 2012 17:01
A Haml :ruby filter that doesn't use locking and doesn't redirect $stdout.
:ruby_no_lock
puts 'This will go to wherever stdout is pointing'
haml_concat 'This will go into the Haml output'
@mattwildig
mattwildig / m_app.rb
Created July 17, 2012 00:05
Using Rack::Builder without eval-ing block in another context.
require 'rack'
require 'forwardable'
class MyApp
extend Forwardable
def_delegators :@builder, :use, :map, :run, :call
def initialize
@builder = Rack::Builder.new
@mattwildig
mattwildig / gist:2921460
Created June 13, 2012 02:31
Two test runs?
$ rake test
/Users/matt/.rvm/rubies/ruby-1.8.7-p358/bin/ruby -I"lib:lib:test" -I"/Users/matt/.rvm/gems/ruby-1.8.7-p358/gems/rake-0.9.2.2/lib" "/Users/matt/.rvm/gems/ruby-1.8.7-p358/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb" "test/engine_test.rb" "test/filters_test.rb" "test/haml-spec/ruby_haml_test.rb" "test/helper_test.rb" "test/template_test.rb" "test/util_test.rb"
Run options: --seed 21449
# Running tests:
......................................................................................................................................................................................................................................................................................................................................................................
Finished tests in 0.879086s, 407.2412 tests/s, 1887.1874 assertions/s.
@mattwildig
mattwildig / gist:2598534
Created May 4, 2012 23:54
gem contents sass
/Users/matt/.rvm/gems/ruby-1.9.3-p194/gems/sass-3.1.16/CONTRIBUTING
/Users/matt/.rvm/gems/ruby-1.9.3-p194/gems/sass-3.1.16/MIT-LICENSE
/Users/matt/.rvm/gems/ruby-1.9.3-p194/gems/sass-3.1.16/README.md
/Users/matt/.rvm/gems/ruby-1.9.3-p194/gems/sass-3.1.16/REVISION
/Users/matt/.rvm/gems/ruby-1.9.3-p194/gems/sass-3.1.16/Rakefile
/Users/matt/.rvm/gems/ruby-1.9.3-p194/gems/sass-3.1.16/VERSION
/Users/matt/.rvm/gems/ruby-1.9.3-p194/gems/sass-3.1.16/VERSION_NAME
/Users/matt/.rvm/gems/ruby-1.9.3-p194/gems/sass-3.1.16/bin/sass
/Users/matt/.rvm/gems/ruby-1.9.3-p194/gems/sass-3.1.16/bin/sass-convert
/Users/matt/.rvm/gems/ruby-1.9.3-p194/gems/sass-3.1.16/bin/scss