I first got CoffeeScript working with Phoenix per this guide. Then, using this blog post and this post & comment, I got unit testing with Mocha working:
# install mocha
$ npm install --save-dev mocha| # first off, Virtus basically lets you make this... | |
| class Foo | |
| def initialize(**args) | |
| @bar = bar | |
| end | |
| end | |
| # or this... | |
| class Foo | |
| def initialize(bar:) | |
| @bar = bar |
I first got CoffeeScript working with Phoenix per this guide. Then, using this blog post and this post & comment, I got unit testing with Mocha working:
# install mocha
$ npm install --save-dev mocha| #!/usr/bin/env ruby | |
| # create Jekyll drafts and publish them (to `_posts/`) | |
| ############# | |
| ### USAGE ### | |
| ############# | |
| # | |
| # ### 1 - start a new draft ### | |
| # $ ./draft.rb name of new post # -> opens `_drafts/name-of-new-post.md` in vim |
Hey polyglotarians! Brad here.
One of my Twitter followers asked the other day:
How do you use particles like "ni" or "ga" [in Japanese]?
This is both 1) a great question, and 2) a huge, sprawling question.
I don't think I've ever seen anyone try to give a short answer to this before though, so I tried to condense what I know into a few simple examples. Here's what I came up with:
| #!/usr/bin/env elixir | |
| File.stream!("JMdict_e") | |
| |> Stream.map(& Regex.run(~r{^\<(\w+?)\>\&}, &1)) | |
| |> Stream.uniq | |
| |> Enum.to_list | |
| |> Enum.reject(& is_nil &1) | |
| |> Enum.map(& List.last &1) | |
| |> IO.inspect |
| class App | |
| def self.call(env) | |
| new(env).response | |
| end | |
| attr_reader :env, :request, :response | |
| def initialize(env) | |
| @env, @request = env, Rack::Request.new(env) | |
| end |
| #!/usr/bin/env ruby | |
| require 'nokogiri' | |
| require 'pry' | |
| html_str = <<-HTML | |
| <html> | |
| <body> | |
| <p> | |
| <a href="example.com"><span>click here</span></a> |
こみ上げてくる涙を 何回拭いたら
こみあげてくるなみだを なんかいふいたら
komiagete kuru namida wo nankai fuitara
伝えたい言葉は 届くだろう?
つたえたいことばは とどくだろう?
tsutaetai kotoba wa todoku darou?
So I ended up wanting to do MatchData#to_hash again (to pass named captures from a match into a Virtus constructor in a script), and went searching for my old implementation of it on Gist. I didnt find it, but I did wind up finding a handful of interesting things from other people.
First, to clarify the goal, I have a MatchData instance with named captures:
| #!/usr/bin/env ruby | |
| # require 'virtus' | |
| # require 'uri' | |
| # require 'net/http' | |
| # require 'json' | |
| # require 'ostruct' | |
| # # require 'active_support/core_ext/klass' | |
| require 'pathname' | |
| require 'pry' |