monads are an abstraction
objects are an abstraction
They're two very different abstractions :-)
In my opinion, monads are much simpler than objects.
Because monads are only abstractions of structure, where you get to change the meaning yourself. >
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# fyi: I have no idea what I'm doing :) | |
Log = Struct.new :buffer do | |
def call method | |
buffer << "Log: before #{method.name}\n" | |
method.call buffer | |
buffer << "Log: after #{method.name}\n\n" | |
self | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# make this script run, update your gist with the running script, and it's | |
# output in a separate gist. the entire quzi should take 1-3 minutes, but you | |
# get 5. | |
# | |
# the meat - take < 5 minutes to do this | |
# | |
assert :hash do | |
x = x.to_h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_rstring(addr): | |
s = addr.cast(string_t.pointer()) | |
if s['basic']['flags'] & (1 << 13): | |
return s['as']['heap']['ptr'].string() | |
else: | |
return s['as']['ary'].string() | |
def get_lineno(iseq, pos): | |
if pos != 0: | |
pos -= 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# MODEL | |
class Case < ActiveRecord::Base | |
include Eventable | |
has_many :tasks | |
concerning :Assignment do | |
def assign_to(new_owner:, details:) | |
transaction do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AssignCaseCommand < Command | |
attribute :case, Case | |
attribute :owner, User | |
attribute :created_by, User | |
attribute :comments, String | |
attribute :distribute_at, DateTime | |
attribute :distribute_rule_name, String | |
attribute :require_initial, Boolean |
I tried a few different techniques to make a GIF via command-line and the following gives me the best control of quality and size. Once you're all setup, you'll be pumping out GIFs in no time!
Install FFmpeg
- $ brew install ffmpeg [all your options]
- Example: $ brew install ffmpeg --with-fdk-aac --with-ffplay --with-freetype --with-frei0r --with-libass --with-libvo-aacenc --with-libvorbis --with-libvpx --with-opencore-amr --with-openjpeg --with-opus --with-rtmpdump --with-schroedinger --with-speex --with-theora --with-tools
Install ImageMagick
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Convenient way to fetch URLs. It follows redirections and handles SSL. Usage: | |
# Net::HTTP.fetch_url('http://google.com') | |
# Net::HTTP.fetch_url('https://www.google.fr/?q=ruby') | |
module Net | |
class HTTP | |
def self.fetch_url(url, limit = 10) | |
raise ArgumentError, 'HTTP redirect too deep' if limit == 0 | |
url = URI.parse(url) | |
options = {use_ssl: url.scheme.downcase == 'https'} | |
request = Net::HTTP::Get.new(url.path.to_s + '?' + url.query.to_s) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Link: [1]RSS (alternate) | |
NOTE:This blog had a good run, but is now in retirement. | |
If you enjoy the content here, please support Gregory's ongoing work on | |
the [2]Practicing Ruby journal. | |
[3]Gregory Brown [4]James Britt [5]Robert Klemme [6]Magnus Holm | |
[7]Ruby Best Practices |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# use from pry or whatever. must have bundler loaded. | |
# `gem install bcat` beforehand. it doesn't have to be in your gemfile. | |
# example: "hello from ruby".bcat #=> opens in default web browser | |
class String | |
def bcat | |
pull, push = IO.pipe | |
Bundler.with_original_env do | |
fork do | |
push.close |