Skip to content

Instantly share code, notes, and snippets.

class Mailer < ApplicationMailer
def self.my_class_method
build_the_mail.deliver_now # this invokes (B)
end
def build_the_mail # (A) this is the instance method you write
mail(
# ...
)
end
// a.c

size_t Chunk_copy(Chunk *src, size_t src_start, Chunk *dst, size_t dst_start, size_t n)
{
    if (!Chunk_bounds_check(src, src_start, n)) return 0;
    if (!Chunk_bounds_check(dst, dst_start, n)) return 0;

    memcpy(dst->data + dst_start, src->data + src_start, n);
require "./diff"
class MyersLinear
Window = Struct.new(:left, :top, :right, :bottom) do
def width
right - left
end
def height
bottom - top
module Lambda where
import Control.Monad (when)
import Data.List (nub, sort)
data LTerm = Var String
| Lambda String LTerm
| Apply LTerm LTerm
deriving (Eq)
require_relative './pattern'
Pattern.define :TmIf,
:TmTrue,
:TmFalse,
:TmZero,
:TmSucc,
:TmPred,
:TmIsZero
require_relative "../myers/linear"
class Diff3
def self.merge(o, a, b, differ: MyersLinear)
o = o.lines if o.is_a?(String)
a = a.lines if a.is_a?(String)
b = b.lines if b.is_a?(String)
new(o, a, b, differ).tap(&:run)
end

The Myers diff algorithm

The following based on Myers' original paper.

The edit graph

To use the example from the paper, say you want to calculate the difference between two strings:

@jcoglan
jcoglan / buffer.c
Last active November 28, 2016 14:48
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef char * BLOB;
typedef struct BufferChunk {
int length;
int cursor;
BLOB data;
@jcoglan
jcoglan / ex17.c
Last active November 22, 2016 18:21
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
struct Address {
int id;
int set;
char *name;
var crypto = require('crypto');
var key = crypto.randomBytes(32),
iv = crypto.randomBytes(12),
mode = 'aes-256-gcm';
var message = new Buffer('Hello, world!', 'utf8');