Skip to content

Instantly share code, notes, and snippets.

# 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

Unit Testing CoffeeScript with Mocha in Phoenix

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
@bchase
bchase / draft.rb
Last active June 20, 2016 04:41
A Ruby script for creating and publishing Jekyll drafts
#!/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>

何度でも - DREAMS COME TRUE

こみ上げてくる涙を 何回拭いたら
こみあげてくるなみだを なんかいふいたら
komiagete kuru namida wo nankai fuitara

伝えたい言葉は 届くだろう?
つたえたいことばは とどくだろう?
tsutaetai kotoba wa todoku darou?
@bchase
bchase / 00_matchdata_to_hash.md
Last active April 6, 2016 20:37
Ruby MatchData to Hash

Ruby MatchData to Hash

blog post

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.

What we're doing

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'