Skip to content

Instantly share code, notes, and snippets.

View f-mer's full-sized avatar

Fabian Mersch f-mer

View GitHub Profile
@tkareine
tkareine / pfork.rb
Created May 31, 2011 22:35
Capture input and output and get the exit status of arbitrary Ruby code, variant of Open4::popen4
# coding: utf-8
module PFork
extend self
# Call function +fun+ in a child process, giving access to the child process
# id and capturing STDIN, STDOUT, and STDERR of the function call.
#
# Adapted from stdlib's Open3::popen3 and
# {Open4::popen4}[https://github.com/ahoward/open4] by Ara T. Howard, but
@jcasimir
jcasimir / better_rails_through_better_ruby.markdown
Created September 13, 2011 18:32
Better Rails Through Better Ruby

The Problem is Your Ruby

(Intro)

Stop Trying

Stop trying to be an expert at Rails.

Is it Hard?

@dcernst
dcernst / HWTemplate.tex
Last active April 23, 2024 05:19
LaTeX homework template for Weekly Homework assignments for Dana Ernst's courses.
% --------------------------------------------------------------
% This is all preamble stuff that you don't have to worry about.
% Head down to where it says "Start here"
% --------------------------------------------------------------
\documentclass[12pt]{article}
\usepackage[margin=1in]{geometry}
\usepackage{amsmath,amsthm,amssymb}
@madtrick
madtrick / remote_authenticatable.rb
Created October 19, 2012 08:43
Example module to perform remote authentication with Devise
module Devise
module Models
module RemoteAuthenticatable
extend ActiveSupport::Concern
#
# Here you do the request to the external webservice
#
# If the authentication is successful you should return
# a resource instance
@madtrick
madtrick / gist:3917079
Created October 19, 2012 09:06
Warden strategy for Devise
module Devise
module Strategies
class RemoteAuthenticatable < Authenticatable
#
# For an example check : https://github.com/plataformatec/devise/blob/master/lib/devise/strategies/database_authenticatable.rb
#
# Method called by warden to authenticate a resource.
#
def authenticate!
#
@Integralist
Integralist / rules for good testing.md
Last active May 13, 2024 18:25
Sandi Metz advice for writing tests

Rules for good testing

Look at the following image...

...it shows an object being tested.

You can't see inside the object. All you can do is send it messages. This is an important point to make because we should be "testing the interface, and NOT the implementation" - doing so will allow us to change the implementation without causing our tests to break.

@j1n6
j1n6 / multiple_io.rb
Created January 3, 2014 12:55
Ruby Multiple IO
class MultipleIO
def initialize(*targets)
@targets = targets
end
def write(*args)
@targets.each { |t| t.write(*args) }
end
def close
# MODEL
class Case < ActiveRecord::Base
include Eventable
has_many :tasks
concerning :Assignment do
def assign_to(new_owner:, details:)
transaction do
# config/routes.rb
resources :documents do
scope module: 'documents' do
resources :versions do
post :restore, on: :member
end
resource :lock
end
end
@joyrexus
joyrexus / README.md
Last active August 21, 2023 16:59
Node.js streams demystified

A quick overview of the node.js streams interface with basic examples.

This is based on @brycebaril's presentation, Node.js Streams2 Demystified

Overview

Streams are a first-class construct in Node.js for handling data.

Think of them as as lazy evaluation applied to data.