Skip to content

Instantly share code, notes, and snippets.

@replaid
replaid / wiki-unislug.md
Last active October 29, 2022 13:36
Federated Wiki i18n proposal

OldSlug vs. Unislug comparison

Input OldSlug Unislug Unislug HTML link Unislug appearance in location bar
[[Peña]] pea peña /pe%C3%B1a.html /peña.html
[[Pea]] pea pea /pea.html /pea.html
[[RAMN]] ramn ramn /ramn.html /ramn.html
[[Ramén]] ramn ramén /ram%C3%A9n.html /ramén.html
[[Ramón]] ramn ramón /ram%C3%B3n.html /ramón.html
[[Гильдии]] (empty string) гильдии /%D0%B3%D0%B8%D0%BB%D1%8C%D0%B4%D0%B8%D0%B8.html /гильдии.html
@replaid
replaid / Zenity-mac.bash
Created July 8, 2020 09:23
Give Zenity foreground on macOS
#!/usr/bin/env bash
zenity --password &
zenity_pid=$!
osascript<<EOF
tell application "System Events"
set processList to every process whose unix id is $zenity_pid
repeat with proc in processList
set the frontmost of proc to true
end repeat
@replaid
replaid / mixin_ancestors.rb
Last active December 17, 2016 03:42
Included Ruby modules go into the inheritance chain
irb(main):001:0> module Mixin; end
=> nil
irb(main):002:0> class A
irb(main):003:1> include Mixin
irb(main):004:1> end
=> A
irb(main):005:0> a = A.new
=> #<A:0x007fbaea8a89a8>
irb(main):006:0> a.is_a? Mixin
=> true
@replaid
replaid / flatten_enum.rb
Created October 22, 2016 21:09
Flatten arbitrarily nested collections.
class FlattenEnum
class << self
# Returns an enumerator that yields the non-enumerable items from within a
# nested enumerable, in depth-first order.
#
# Example:
#
# FlattenEnum.create([[1, 2, [3]], 4]).to_a
# #=> [1, 2, 3, 4]
@replaid
replaid / restaurant_recommendation.adoc
Created March 31, 2016 20:00 — forked from jexp/restaurant_recommendation.adoc
Restaurant Recommendation GraphGist

Restaurant Recommendations

We want to demonstrate how easy it is to model a domain as a graph and answer questions in almost natural language.

Graph Based Search and Discovery is prominent a use-case for graph databases like Neo4j.

@replaid
replaid / keybase.md
Created February 5, 2016 18:19
keybase.md

Keybase proof

I hereby claim:

  • I am replaid on github.
  • I am rep (https://keybase.io/rep) on keybase.
  • I have a public key ASCQqLi-yHok4PIouZjkILaJ5jUFRMrj__Ebwe-uaqpKJwo

To claim this, I am signing this object:

@replaid
replaid / inject.rb
Last active August 26, 2015 22:26
ROM Relation setup difficulty
require 'domain'
require 'persist/rom'
require 'persist/users_relation'
rom = ROM.env
p rom
Domain::Repository::User.delegate = rom.relation(:users).as(:user)
@replaid
replaid / ddd-rails-tree.txt
Last active March 23, 2023 02:19
A Rails directory tree that expresses DDD layers and bounded contexts.
components/
my_bounded_context/
app/
presentation/ # This is called the "UI" layer in DDD literature, but it is also
# where things like JSON interfaces live -- any kind of presentation
# or handshake to anything outside. So "presentation" rather than "ui".
assets/
helpers/
mailers/
views/
@replaid
replaid / dump.rb
Created September 22, 2014 18:21
Save test data into tab-separated files.
ActiveRecord::Base.connection.tables.each do |table_name|
ActiveRecord::Base.connection.execute("select * from #{table_name} into outfile '/tmp/datadump-#{table_name}.outfile'")
end
@replaid
replaid / fixture_validation_test.rb
Created August 5, 2014 21:22
Validating your Fixtures in Rails 4
# Adapted for Rails 4 from http://trevorturk.com/2008/09/20/validating-your-fixtures/
# I put this in test/models/. Trevor put his in test/integration/.
require 'test_helper'
class FixtureValidationTest < ActiveSupport::TestCase
test "fixtures should be valid" do
models = ActiveRecord::FixtureSet.all_loaded_fixtures.keys
models.each do |model|